動的移動平均クロスオーバートレンド追跡組み合わせ戦略

EMA SMA Moving Average CROSSOVER TREND FOLLOWING STOP LOSS TAKE PROFIT
作成日: 2025-02-24 09:46:10 最終変更日: 2025-02-24 09:46:10
コピー: 1 クリック数: 315
2
フォロー
319
フォロワー

動的移動平均クロスオーバートレンド追跡組み合わせ戦略 動的移動平均クロスオーバートレンド追跡組み合わせ戦略

概要

この戦略は,多重平均線交差に基づくトレンド追跡システムで,SMAとEMAの指標を組み合わせて市場トレンドを捉えます.この戦略は,カスタマイズされた周期のシンプル移動平均 ((SMA) と2つの指数移動平均 ((EMA) の組み合わせを使用して,完全なトレンド追跡取引システムを構築します.同時に,ダイナミックな止損と利益目標管理機構を統合し,リスクを効果的に制御し,利益をロックします.

戦略原則

戦略は,主に3つの均線の動的関係に基づいて取引決定を行う.システムは,価格とSMAの相対的な位置,および高速EMAと遅いEMAの交差を監視することによって,トレンドの方向を決定する.入場信号は,2つのトリガー方法に分かれています.

戦略的優位性

  1. 多重平均線配合を使用することで,トレンド判断の正確性が向上し,偽突破による損失が軽減されます.
  2. デュアルエントリー条件の設計は,トレンドの初期の機会を捉え,既定のトレンドの継続性を追跡します.
  3. ダイナミック・ストップ・メカニズムは,既にお得なトレンドを保護し,トレンドの完全な発展を可能にする.
  4. ストップ・ストップ・ロスの割合は合理的に設定され,リスクコントロールと利益の間のバランスが良好です.
  5. 平均線交差は,トレンドの逆転のリスクを回避するために,追加の平仓条件として役立ちます.

戦略リスク

  1. 波動的な市場では,頻繁に取引することで損失を招く可能性があります.
  2. 多重平均線システムは,急速な変動の市場で遅れをとる可能性があります.
  3. 固定のストップ・ロスの倍数は,すべての市場環境には適さない可能性があります.
  4. 移動ストップは,波動性の高い市場では,利益を早めに固定する可能性があります.
  5. パラメータを過度に最適化すると,戦略がリアルディスクでのフィードバック結果に追いつかない可能性があります.

戦略最適化の方向性

  1. 波動性指標の導入により,ストップとストップの倍数を動的に調整し,異なる市場状況に戦略を適当に適応させる
  2. 入場信号の信頼性を高めるために,補足確認として,出場量指標を増やす.
  3. 市場波動の特徴に合わせて均線周期を動的に調整し,戦略の適応性を向上させる
  4. トレンド強さのフィルターで,弱気な状況で頻繁に取引を避ける
  5. 市場変動の動向に応じてストップ距離を調整する自主的な移動ストップメカニズムを開発

要約する

この戦略は,多重均等線の配合による使用により,完全なトレンド追跡システムを構築し,入場,出場,リスク管理などの面で詳細なルール設計がある.戦略の優点は,トレンドを効果的に識別し,追跡し,ダイナミックな止損機構によって利益を保護することにある.いくつかの固有のリスクがあるものの,提唱された最適化方向によって,戦略の安定性と適応性をさらに向上させることができる.戦略は全体的に合理的に設計され,優れた実用価値と最適化スペースを有している.

ストラテジーソースコード
/*backtest
start: 2025-02-17 17:00:00
end: 2025-02-20 00:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Binance","currency":"SOL_USDT"}]
*/

//@version=5
strategy("交易策略(自定义EMA/SMA参数)", overlay=true, initial_capital=100000, currency=currency.EUR, default_qty_type=strategy.percent_of_equity, default_qty_value=10)

// 输入参数:可调的 SMA 和 EMA 周期
smaLength     = input.int(120, "SMA Length", minval=1, step=1)
emaFastPeriod = input.int(13, "EMA Fast Period", minval=1, step=1)
emaSlowPeriod = input.int(21, "EMA Slow Period", minval=1, step=1)

// 计算均线
smaVal   = ta.sma(close, smaLength)
emaFast  = ta.ema(close, emaFastPeriod)
emaSlow  = ta.ema(close, emaSlowPeriod)

// 绘制均线
plot(smaVal, color=color.orange, title="SMA")
plot(emaFast, color=color.blue, title="EMA Fast")
plot(emaSlow, color=color.red, title="EMA Slow")

// 入场条件 - 做多
// 条件1:收盘价高于SMA 且 EMA Fast 向上穿越 EMA Slow
longTrigger1 = (close > smaVal) and ta.crossover(emaFast, emaSlow)
// 条件2:收盘价上穿SMA 且前5根K线的最低价均高于各自的SMA
longTrigger2 = ta.crossover(close, smaVal) and (low[1] > smaVal[1] and low[2] > smaVal[2] and low[3] > smaVal[3] and low[4] > smaVal[4] and low[5] > smaVal[5])
longCondition = longTrigger1 or longTrigger2

// 入场条件 - 做空
// 条件1:收盘价低于SMA 且 EMA Fast 向下穿越 EMA Slow
shortTrigger1 = (close < smaVal) and ta.crossunder(emaFast, emaSlow)
// 条件2:收盘价下穿SMA 且前5根K线的最高价均低于各自的SMA
shortTrigger2 = ta.crossunder(close, smaVal) and (high[1] < smaVal[1] and high[2] < smaVal[2] and high[3] < smaVal[3] and high[4] < smaVal[4] and high[5] < smaVal[5])
shortCondition = shortTrigger1 or shortTrigger2

// 定义变量记录入场时的价格与EMA Fast值,用于计算止损
var float entryPriceLong      = na
var float entryEMA_Fast_Long   = na
var float entryPriceShort     = na
var float entryEMA_Fast_Short = na

// 入场与初始止盈止损设置 - 做多
// 止损取“开仓时的EMA Fast价格”与“0.2%止损”中较大者;止盈为止损的5倍
if (longCondition and strategy.position_size == 0)
    entryPriceLong      := close
    entryEMA_Fast_Long  := emaFast
    strategy.entry("Long", strategy.long)
    stopPercLong = math.max(0.002, (entryPriceLong - entryEMA_Fast_Long) / entryPriceLong)
    stopLong     = entryPriceLong * (1 - stopPercLong)
    tpLong       = entryPriceLong * (1 + 5 * stopPercLong)
    strategy.exit("LongExit", "Long", stop=stopLong, limit=tpLong)

// 入场与初始止盈止损设置 - 做空
// 止损取“开仓时的EMA Fast价格”与“0.2%止损”中较大者;止盈为止损的5倍
if (shortCondition and strategy.position_size == 0)
    entryPriceShort      := close
    entryEMA_Fast_Short  := emaFast
    strategy.entry("Short", strategy.short)
    stopPercShort = math.max(0.002, (entryEMA_Fast_Short - entryPriceShort) / entryPriceShort)
    stopShort     = entryPriceShort * (1 + stopPercShort)
    tpShort       = entryPriceShort * (1 - 5 * stopPercShort)
    strategy.exit("ShortExit", "Short", stop=stopShort, limit=tpShort)

// 移动止损逻辑
// 当持仓盈利达到0.8%时更新止损和止盈,保持止盈为止损的5倍
var float longHighest = na
if (strategy.position_size > 0)
    longHighest := na(longHighest) ? high : math.max(longHighest, high)
    if (high >= entryPriceLong * 1.008)
        newLongStop = longHighest * (1 - 0.003)
        newPerc     = (entryPriceLong - newLongStop) / entryPriceLong
        newLongTP   = entryPriceLong * (1 + 5 * newPerc)
        strategy.exit("LongExit", "Long", stop=newLongStop, limit=newLongTP)
else
    longHighest := na

var float shortLowest = na
if (strategy.position_size < 0)
    shortLowest := na(shortLowest) ? low : math.min(shortLowest, low)
    if (low <= entryPriceShort * 0.992)
        newShortStop  = shortLowest * (1 + 0.003)
        newPercShort  = (newShortStop - entryPriceShort) / entryPriceShort
        newShortTP    = entryPriceShort * (1 - 5 * newPercShort)
        strategy.exit("ShortExit", "Short", stop=newShortStop, limit=newShortTP)
else
    shortLowest := na

// 额外平仓条件
// 如果持多仓时EMA Fast下穿EMA Slow,则立即平多
if (strategy.position_size > 0 and ta.crossunder(emaFast, emaSlow))
    strategy.close("Long", comment="EMA下穿平多")
// 如果持空仓时EMA Fast上穿EMA Slow,则立即平空
if (strategy.position_size < 0 and ta.crossover(emaFast, emaSlow))
    strategy.close("Short", comment="EMA上穿平空")