ハル移動平均トレンドフォロー戦略


作成日: 2023-09-16 18:41:33 最終変更日: 2023-09-16 18:41:33
コピー: 0 クリック数: 696
1
フォロー
1617
フォロワー

概要

ハル移動平均トレンドトラッキング戦略は,市場トレンドの方向を判断するためにハル移動平均を使用し,買入と売却のシグナルを発信する量化取引戦略である. この戦略は,中長線トレンドを捕捉し,トレンドの開始段階でポジションを確立し,トレンドが逆転する前にポジションを平止する.

原則

この戦略は,ハル移動平均と普通移動平均を同時に使用してトレンドの方向を判断する.短い周期のハルMAが長い周期のハルMAを横断するときに買入シグナルである.短い周期のハルMAが長い周期のハルMAを横断するときに売る信号である.

通常の移動平均は,即時トレンドの方向を判断するために使用される.短周期EMAで長周期EMAを横切るときは看板であり,短周期EMAの下では長周期EMAを横切るときは下落である.ハルMA信号とEMAが同方向の看板または下落である場合にのみ,取引信号が送信されます.

さらに,この戦略は,K線実体チャネルを利用して,市場の波動幅を判断し,波動的な市場で誤った取引を避ける. 価格がチャネルを突破するのみでポジションを考慮する.

利点

  • ハル移動平均は価格の変化に敏感で,トレンドの転換を早期に捉えることができる.

  • Hull MAとEMAの組み合わせにより,偽信号をフィルターできます.

  • K線チャネルを使って振動を判断し,清算時に頻繁に取引を避ける.

  • トレンドトラッキングで,中長線のトレンドを継続的に捉えることができます.

リスク

  • 移動平均は遅滞しており,トレンドの逆転のベストエントリーポイントを逃している可能性がある.

  • 震動の勢いは判断が不正確で,計算で誤った取引が起こりうる.

  • 取引の回数が少なく,単発の損失の影響を受けやすい.

  • ショートラインの振動を有効に利用できない.

どう対処するか

  • 移動平均の周期パラメータを最適化して,タイムレス反応のトレンドを追求する.

  • RSI,BBANDSなどの他の指標を用いて震動を判断する.

  • 積極的な資金管理を導入し,単発損失率を制御する.

  • 短線利潤を捕まえるための他の戦略を活用する.

要約する

ハル移動平均トレンドトラッキング戦略は,ハルMAとEMAの組み合わせを使用して,中長線トレンドを効果的に追跡できます. 利益のトレンドの中で継続的に利益を累積し,トレンドが逆転する前にできるだけ早く停止します. これは,シンプルで実用的な量化取引戦略であり,推奨されます.

ストラテジーソースコード
/*backtest
start: 2023-08-16 00:00:00
end: 2023-09-15 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=2

// strategy(title='HULLMiguel 2019/ Strategy v3', shorttitle='HULLMiguel_2019_Strategy', overlay=true, pyramiding=0, default_qty_value=1000, initial_capital=1000, currency=currency.USD)

//Candle body resistance Channel-----------------------------//
len = 34
src = input(close, title="Candle body resistance Channel")
out = sma(src, len)
last8h = highest(close, 13)
lastl8 = lowest(close, 13)
bearish = cross(close,out) == 1 and falling(close, 1)
bullish = cross(close,out) == 1 and rising(close, 1)
channel2=input(false, title="Bar Channel On/Off")
ul2=plot(channel2?last8h:last8h==nz(last8h[1])?last8h:na, color=black, linewidth=1, style=linebr, title="Candle body resistance level top", offset=0)
ll2=plot(channel2?lastl8:lastl8==nz(lastl8[1])?lastl8:na, color=blue, linewidth=1, style=linebr, title="Candle body resistance level bottom", offset=0)
//fill(ul2, ll2, color=black, transp=95, title="Candle body resistance Channel")

//-----------------Support and Resistance 
RST = input(title='Support / Resistance length:',  defval=15) 
RSTT = valuewhen(high >= highest(high, RST), high, 0)
RSTB = valuewhen(low <= lowest(low, RST), low, 0)
RT2 = plot(RSTT, color=RSTT != RSTT[1] ? na : red, linewidth=1, offset=+0)
RB2 = plot(RSTB, color=RSTB != RSTB[1] ? na : green, linewidth=1, offset=0)

//--------------------Trend colour ema------------------------------------------------// 
src0 = close, len0 = input(13, minval=1, title="EMA 1")
ema0 = ema(src0, len0)
direction = rising(ema0, 2) ? +1 : falling(ema0, 2) ? -1 : 0
plot_color = direction > 0  ? lime: direction < 0 ? red : na
plot(ema0, title="EMA", style=line, linewidth=3, color = plot_color)

//-------------------- ema 2------------------------------------------------//
src02 = close, len02 = input(21, minval=1, title="EMA 2")
ema02 = ema(src02, len02)
direction2 = rising(ema02, 2) ? +1 : falling(ema02, 2) ? -1 : 0
plot_color2 = direction2 > 0  ? green: direction2 < 0 ? red : na
plot(ema02, title="EMA Signal 2", style=line, linewidth=2, color = plot_color2)

//=============Hull MA//
show_hma = input(false, title="Display Hull MA Set:")
hma_src = input(close, title="Hull MA's Source:")
hma_base_length = input(16, minval=1, title="Hull MA's Base Length:")
hma_length_scalar = input(10, minval=0, title="Hull MA's Length Scalar:")
hullma(src, length)=>wma(2*wma(src, length/2)-wma(src, length), round(sqrt(length)))
plot(not show_hma ? na : hullma(hma_src, hma_base_length+hma_length_scalar*6), color=black, linewidth=5, title="Hull MA")
dif_close_hull= (close-hullma(hma_src, hma_base_length+hma_length_scalar*6))/close
Percent_dif = (dif_close_hull/(hullma(hma_src, hma_base_length+hma_length_scalar*6)))
//direction3 = Percent_dif>0 ? +1 : Percent_dif<0 ? -1 : 0
//plot_color3 = direction3 > 0  ? lime: direction3 < 0 ? red : na
//plot(dif_close_hull, title="dif close hull", style=line, linewidth=6, color = plot_color3)

//============ signal Generator ==================================//
Piriod=input('720')
ch1 = security(syminfo.tickerid, Piriod, open)
ch2 = security(syminfo.tickerid, Piriod, close)
plot(ch1, title="EMA Signal 2", style=line, linewidth=1, color = blue)
//longCondition = crossover(security(tickerid, Piriod, close),security(tickerid, Piriod, open))
//plot((close-ema02)/ema02+close)
longCondition = direction > 0 and direction2> 0

if (longCondition)
    strategy.entry("BUY", strategy.long)
//shortCondition = crossunder(security(tickerid, Piriod, close),security(tickerid, Piriod, open))
shortCondition = direction < 0 and direction2 < 0

if (shortCondition)
    strategy.entry("SELL", strategy.short)

///////////////////////////////////////////////////////////////////////////////////////////