双動平均クロスオーバー戦略によるモメンタム・トレーディング

作者: リン・ハーンチャオチャン,日付: 2024-04-01 11:53:14
タグ:

img

概要

この戦略は,市場動向の変化を特定するために8期および21期指数関数移動平均値 (EMA) を採用する.短期EMAが長期EMAを下から越えるときに購入信号が生成され,短期EMAが長期EMAを下から越えるときに販売信号が生成される.この戦略には,トレンド逆転のさらなる確認として,3つの連続的なHigh Lows (HLs) と3つの連続的なLower Highs (LHs) も含まれている.さらに,リスクを管理し,利益をロックするためにストップ・ロストとテイク・プロフィートレベルが設定されている.

戦略の原則

  1. 8 期間の EMA と 21 期間の EMA を計算し,主要な傾向の方向性を特定します.
  2. 3つの連続した高低値 (HLs) と3つの連続した低低値 (LHs) を,潜在的なトレンド逆転の初期信号として特定する.
  3. 8 期間の EMA が 21 期間の EMA を越えて HL ブレイクが発生した場合に購入信号を生成し, 8 期間の EMA が 21 期間の EMA を越えて LH ブレイクが発生した場合に販売信号を生成する.
  4. ストップ・ロスのレベルをエントリー価格の5%と,収益のレベルをエントリー価格の16%に設定し,リスクを管理し利益を固定します.
  5. ポジションを閉じ,逆の信号が表示されたときに逆のポジションを開きます.

戦略 の 利点

  1. EMAと価格行動パターン (HLsとLHs) を組み合わせ,傾向を確認し,信号の信頼性を向上させます.
  2. リスクの管理と利益の確保に役立ちます リスクの管理と利益の確保に役立ちます
  3. 複数のタイムフレームと異なる市場に適用可能で,ある程度の多様性があります.
  4. 論理が明確で 分かりやすく実行できます

戦略リスク

  1. 不安定な市場では 頻繁にクロスオーバーが起きると 複数の誤った信号が発信され 損失が生じます
  2. 固定ストップ・ロースとテイク・プロフィートのレベルは,異なる市場状況にうまく適応できない可能性があり,潜在的なチャンスコストや大きな損失につながる.
  3. 戦略は歴史的なデータに基づいているため 突然の出来事や根本的な変化にうまく適応できない可能性があります

戦略の最適化方向

  1. 適応性のあるストップ・ロスト・メカニズムと,変動性 (例えばATR) に基づいたレベル調整など,利益を引き出すメカニズムを導入し,異なる市場状況により良く適応させる.
  2. ボリューム,相対強度指数 (RSI) など,他の指標や要因を組み込むことで,信号をさらにフィルターし,信頼性を向上させる.
  3. パラメータを最適化する (EMA期間,ストップ・ロスト,テイク・プロフィートの割合など) 特定の市場やインstrumentに最適な組み合わせを見つける.
  4. リスク管理対策を導入することを検討する.例えば,ポジションのサイズを調整する.

概要

この戦略は,トレンド逆転を特定し,取引信号を生成するために,HLとLHの価格パターンと組み合わせた8期と21期EMAsのクロスオーバーを利用する.明確なストップ・ロストとテイク・プロフィートルールはリスクを管理し,利益をロックするのに役立ちます.しかし,この戦略は不安定な市場で誤った信号を生成し,固定ストップ・ロストとテイク・プロフィートのレベルは異なる市場状況にうまく適応しない可能性があります.さらに改善するために,適応型ストップ・ロストとテイク・プロフィートを導入し,他の指標を組み込み,パラメータを最適化し,リスク管理措置を導入することを検討してください.全体として,この戦略はモメンタムとトレンドフォローティングのフレームワークを提供しますが,特定の市場と個人の好みに基づいて調整と最適化が必要です.


/*backtest
start: 2023-03-26 00:00:00
end: 2024-03-31 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy('Trend Following 8&21EMA with strategy tester [ukiuro7]', overlay=true, process_orders_on_close=true, calc_on_every_tick=true, initial_capital = 10000)

//INPUTS
lh3On = true
hl3On = true
emaOn = input(title='105ema / 30min', defval=true) 
assistantOn = input(title='Assistant', defval=true)
textOn = input(title='Text', defval=true)

showRiskReward = input.bool(true, title='Show Risk/Reward Area', group="TP/SL")
stopPerc = input.float(5.0, step=0.1, minval=0.1, title='Stop-Loss %:',group="TP/SL") / 100
tpPerc = input.float(16.0, step=0.1, minval=0.1, title='Take-Profit %:',group="TP/SL") / 100

backtestFilter = input(false, title='Backtest Entries to Date Range',group="Backtest Date Range")
i_startTime = input(defval=timestamp('01 Jan 2022 00:00'), inline="b_1", title='Start',group="Backtest Date Range")
i_endTime = input(defval=timestamp('01 Jan 2029 00:00'), inline="b_1", title='End',group="Backtest Date Range")
inDateRange = true

message_long_entry = input.string(title='Alert Msg: LONG Entry', defval ='', group='Alert Message')
message_short_entry = input.string(title='Alert Msg: SHORT Entry', defval='', group='Alert Message')
message_long_exit = input.string(title='Alert Msg: LONG SL/TP', defval='', group='Alert Message')
message_short_exit = input.string(title='Alert Msg: SHORT SL/TP', defval='', group='Alert Message')  

//CALCS
threeHigherLows() =>
    low[0] >= low[1] and low[1] >= low[2]

threeLowerHighs() =>
    high[2] >= high[1] and high[1] >= high[0]

breakHigher() =>
    padding = timeframe.isintraday ? .02 : .1
    high >= high[1] + padding

breakLower() =>
    padding = timeframe.isintraday ? .02 : .1
    low <= low[1] - padding

lh3 = threeLowerHighs() and lh3On
lh3bh = lh3[1] and breakHigher() and lh3On

hl3 = threeHigherLows() and hl3On
hl3bl = hl3[1] and breakLower() and hl3On

ema8 = ta.ema(close, 8)
ema21 = ta.ema(close, 21)

//VARS
var float longStop = na, var float longTp = na
var float shortStop = na, var float shortTp = na

//CONDS
isUptrend = ema8 >= ema21
isDowntrend = ema8 <= ema21
trendChanging = ta.cross(ema8, ema21)

buySignal = lh3bh and lh3[2] and lh3[3] and isUptrend and timeframe.isintraday
sellSignal = hl3bl and hl3[2] and hl3[3] and isDowntrend and timeframe.isintraday

goingDown = hl3 and isDowntrend and timeframe.isintraday
goingUp = lh3 and isUptrend and timeframe.isintraday

projectXBuy = trendChanging and isUptrend
projectXSell = trendChanging and isDowntrend

longCond = trendChanging and isUptrend and assistantOn
shortCond = trendChanging and isDowntrend and assistantOn

//STRATEGY
if shortCond and strategy.position_size > 0 and barstate.isconfirmed
    strategy.close('Long', comment='CLOSE LONG', alert_message=message_long_exit)

if longCond and strategy.position_size < 0 and barstate.isconfirmed
    strategy.close('Short', comment='CLOSE SHORT', alert_message=message_short_exit) 

if longCond and strategy.position_size <= 0 and barstate.isconfirmed and inDateRange
    longStop := close * (1 - stopPerc)
    longTp := close * (1 + tpPerc)
    strategy.entry('Long', strategy.long, comment='LONG', alert_message=message_long_entry)
    strategy.exit('Long Exit', 'Long', comment_loss="SL LONG", comment_profit = "TP LONG", stop=longStop, limit=longTp, alert_message=message_long_exit)

if shortCond and strategy.position_size >= 0 and barstate.isconfirmed and inDateRange
    shortStop := close * (1 + stopPerc)
    shortTp := close * (1 - tpPerc)
    strategy.entry('Short', strategy.short, comment='SHORT', alert_message=message_short_entry)
    strategy.exit('Short Exit', 'Short', comment_loss="SL SHORT", comment_profit="TP SHORT", stop=shortStop, limit=shortTp, alert_message=message_short_exit)

//PLOTS
plotshape(longCond, style=shape.triangleup, location=location.belowbar, color=color.new(color.green, 0), size=size.small, text='Buy')
plotshape(shortCond, style=shape.triangledown, location=location.abovebar, color=color.new(color.red, 0), size=size.small, text='Sell')
plotchar(trendChanging and isUptrend and close < open and assistantOn, char='!', location=location.abovebar, color=color.new(color.green, 0), size=size.small)

aa = plot(ema8, linewidth=3, color=color.new(color.green, 0), editable=true)
bb = plot(ema21, linewidth=3, color=color.new(color.red, 0), editable=true)
fill(aa, bb, color=isUptrend ? color.new(color.green,90) : color.new(color.red,90))
buyZone = isUptrend and lh3 and high < ema21 and timeframe.isintraday
sellZone = isDowntrend and hl3 and low > ema21 and timeframe.isintraday

L1 = plot(showRiskReward and strategy.position_size > 0 ? strategy.position_avg_price : na, color=color.new(color.green, 0), linewidth=1, style=plot.style_linebr, title='Long Entry Price')
L2 = plot(showRiskReward and strategy.position_size > 0 ? longTp : na, color=color.new(color.green, 0), linewidth=1, style=plot.style_linebr, title='Long TP Price')
L3 = plot(showRiskReward and strategy.position_size > 0 ? longStop : na, color=color.new(color.red, 0), linewidth=1, style=plot.style_linebr, title='Long Stop Price')

S1 = plot(showRiskReward and strategy.position_size < 0 ? strategy.position_avg_price : na, color=color.new(color.teal, 0), linewidth=1, style=plot.style_linebr, title='Short Entry Price')
S2 = plot(showRiskReward and strategy.position_size < 0 ? shortTp : na, color=color.new(color.teal, 0), linewidth=1, style=plot.style_linebr, title='Short TP Price')
S3 = plot(showRiskReward and strategy.position_size < 0 ? shortStop : na, color=color.new(color.maroon, 0), linewidth=1, style=plot.style_linebr, title='Short Stop Price')

fill(L1, L2, color=color.new(color.green, 90))
fill(L1, L3, color=color.new(color.red, 90))
fill(S1, S2, color=color.new(color.teal, 90))
fill(S1, S3, color=color.new(color.maroon, 90))

bgcolor(inDateRange == false ? color.new(color.red,90) : na, title="Backtest Off-Range") 


もっと