トレンドトラッキング 移動平均クロスオーバー戦略

作者: リン・ハーンチャオチャン,日付: 2024-01-29 16:52:46
タグ:

img

概要

これは,異なるコインペアでうまく機能する単純な移動平均ベースの戦略である.移動平均開口価格と閉じる価格をプロットし,両線が交差しているかどうかに基づいてロングポジションに入るか出るか決定する.アイデアは,平均閉じる価格が上昇しているときにポジションに入ることであり,価格の上昇勢いを示す可能性があります.その後,平均閉じる価格が低下するときにポジションから出ます.これは憶測的なことですが,時には価格の動きを非常によく予測することができます.

戦略の論理

この戦略は,まずEMA,SMA,RMA,WMA,VWMAを含む移動平均の種類を選択します.その後,移動平均のバックバック期間,通常は10〜250バーを設定します.移動平均の種類とバックバック期間が異なる組み合わせによって,異なるコインペアで非常に異なる結果が得られます.

具体的な取引論理は:

  1. オープン価格と閉値の移動平均を計算する.
  2. 閉じる価格と開く価格の移動平均値を比較する.
  3. 閉じる価格の移動平均が開いた価格の移動平均を上回る場合は,ロングポジションを入力します.
  4. 閉じる価格移動平均値が開く価格移動平均値を下回る場合は,ロングポジションを閉じる.

ポジションに入ると 上向きの価格動きの兆候と考えられ, ポジションから出ると 下向きの価格動きと考えられます.

利点分析

この戦略の主な利点は以下の通りです.

  1. 柔軟なパラメータ設定により,より優れた特異性のために異なるコインペアに最適化できます.
  2. シンプルな論理で 分かりやすく実行できます
  3. いくつかのコインペアで得られる非常に高い収益性,一般的に良好な安定性
  4. 異なる指標を表示する際の高度なカスタマイズ可能性

リスク分析

この戦略にはいくつかのリスクもあります:

  1. いくつかのコインペアやパラメータでは,収益性と安定性が低い可能性があります.
  2. 短期的な価格変動にうまく対応できない.高変動性コインのパフォーマンスが悪い.
  3. 移動平均回顧期間の選択は 科学的に十分ではなく,ある程度主観的です

解決策と最適化

  1. 12H, 1Dのような長い時間枠を使用し,不必要な取引を削減し,安定性を向上させる.
  2. パラメータ最適化機能を追加して,最適なパラメータを自動的に異なるパラメータ組み合わせでテストする.
  3. 移動平均回顧期の適応選択を追加して,システムが自動的に最適期を決定できるようにします.

結論

概要すると,これは価格トレンドと傾き点を決定するために移動平均指標を使用する単純な戦略である.パラメータを調整することによって非常に良い結果を達成することができ,さらなる改善と適用に値する効果的なトレンド追跡戦略である.しかし,リスク管理は注意すべきであり,その有用性を最大化するために適切なコインペアとパラメータを選択する必要があります.


/*backtest
start: 2023-12-01 00:00:00
end: 2023-12-31 23:59:59
period: 2h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
//Author @divonn1994

initial_balance = 100
strategy(title='Close v Open Moving Averages Strategy', shorttitle = 'Close v Open', overlay=true, pyramiding=0, default_qty_value=100, default_qty_type=strategy.percent_of_equity, precision=7, currency=currency.USD, commission_value=0.1, commission_type=strategy.commission.percent, initial_capital=initial_balance)

//Input for number of bars for moving average, Switch to choose moving average type, Display Options and Time Frame of trading----------------------------------------------------------------

bars = input.int(66, "Moving average length (number of bars)", minval=1, group='Strategy') //66 bars and VWMA for BTCUSD on 12 Hours.. 35 bars and VWMA for BTCUSD on 1 Day
strategy = input.string("VWMA", "Moving Average type", options = ["EMA", "SMA", "RMA", "WMA", "VWMA"], group='Strategy')

redOn = input.string("On", "Red Background Color On/Off", options = ["On", "Off"], group='Display')
greenOn = input.string("On", "Green Background Color On/Off", options = ["On", "Off"], group='Display')
maOn = input.string("On", "Moving Average Plot On/Off", options = ["On", "Off"], group='Display')

startMonth = input.int(title='Start Month 1-12 (set any start time to 0 for furthest date)', defval=1, minval=0, maxval=12, group='Beginning of Strategy')
startDate = input.int(title='Start Date 1-31 (set any start time to 0 for furthest date)', defval=1, minval=0, maxval=31, group='Beginning of Strategy')
startYear = input.int(title='Start Year 2000-2100 (set any start time to 0 for furthest date)', defval=2011, minval=2000, maxval=2100, group='Beginning of Strategy')

endMonth = input.int(title='End Month 1-12 (set any end time to 0 for today\'s date)', defval=0, minval=0, maxval=12, group='End of Strategy')
endDate = input.int(title='End Date 1-31 (set any end time to 0 for today\'s date)', defval=0, minval=0, maxval=31, group='End of Strategy')
endYear = input.int(title='End Year 2000-2100 (set any end time to 0 for today\'s date)', defval=0, minval=0, maxval=2100, group='End of Strategy')

//Strategy Calculations-----------------------------------------------------------------------------------------------------------------------------------------------------------------------

inDateRange = true

maMomentum = switch strategy
    "EMA" => (ta.ema(close, bars) > ta.ema(open, bars)) ? 1 : -1
    "SMA" => (ta.sma(close, bars) > ta.sma(open, bars)) ? 1 : -1
    "RMA" => (ta.rma(close, bars) > ta.rma(open, bars)) ? 1 : -1
    "WMA" => (ta.wma(close, bars) > ta.wma(open, bars)) ? 1 : -1
    "VWMA" => (ta.vwma(close, bars) > ta.vwma(open, bars)) ? 1 : -1
    =>
        runtime.error("No matching MA type found.")
        float(na)

openMA = switch strategy
    "EMA" => ta.ema(open, bars)
    "SMA" => ta.sma(open, bars)
    "RMA" => ta.rma(open, bars)
    "WMA" => ta.wma(open, bars)
    "VWMA" => ta.vwma(open, bars)
    =>
        runtime.error("No matching MA type found.")
        float(na)
        
closeMA = switch strategy
    "EMA" => ta.ema(close, bars)
    "SMA" => ta.sma(close, bars)
    "RMA" => ta.rma(close, bars)
    "WMA" => ta.wma(close, bars)
    "VWMA" => ta.vwma(close, bars)
    =>
        runtime.error("No matching MA type found.")
        float(na)

//Enter or Exit Positions--------------------------------------------------------------------------------------------------------------------------------------------------------------------

if ta.crossover(maMomentum, 0)
    if inDateRange
        strategy.entry('long', strategy.long, comment='long')
if ta.crossunder(maMomentum, 0)
    if inDateRange
        strategy.close('long')

//Plot Strategy Behavior---------------------------------------------------------------------------------------------------------------------------------------------------------------------

plot(series = maOn == "On" ? openMA : na, title = "Open moving Average", color = color.new(color.purple,0), linewidth=3, offset=1)
plot(series = maOn == "On" ? closeMA : na, title = "Close Moving Average", color = color.new(color.white,0), linewidth=2, offset=1)
bgcolor(color = inDateRange and (greenOn == "On") and maMomentum > 0 ? color.new(color.green,75) : inDateRange and (redOn == "On") and maMomentum <= 0 ? color.new(color.red,75) : na, offset=1)

もっと