ダブル移動平均チャネルトレンドフォロー戦略

SMA EMA RSI MACD
作成日: 2024-09-26 16:28:19 最終変更日: 2024-09-26 16:28:19
コピー: 2 クリック数: 748
1
フォロー
1617
フォロワー

ダブル移動平均チャネルトレンドフォロー戦略

概要

この戦略は,二重均線とチャネルに基づくトレンド追跡システムである.これは,インデックス移動平均 ((EMA)) の形成されたチャネルと組み合わせた,短期および長期の移動平均の交差信号を利用して,市場のトレンドを捕捉し,取引を行う.この戦略は,多頭と空頭市場の両方に適用され,ストップとストップを設定することによってリスクと利益を管理する.

戦略原則

戦略の中核となるロジックには、次の主要な部分が含まれます。

  1. 主なトレンド指標として,55周期および300周期SMAの2つのシンプル移動平均 ((SMA)) を使用する.
  2. 2つの指数移動平均 ((EMA) を使って,それぞれ576周期と676周期のEMA) で取引チャネルを形成する.
  3. 短期SMA上では長期SMAまたはEMAを履くと,多信号を触発する.短期SMA下では長期SMAまたはEMAを履くと,空白信号を触発する.
  4. 固定ポイントのストップとストップの戦略を使用し,ストップは入場価格の1/70で,ストップは入場価格の1/140で設定します.
  5. 利潤が300点に達すると,既得利潤を保護するために移動停止メカニズムを起動します.
  6. 戦略には,価格がストップ・ロースまたはストップ・ストップ・ポイントに達したときに自動的に平仓するなど,平仓条件も含まれています.

戦略的優位性

  1. 多指標結合:複数の移動平均とEMAチャネルを組み合わせることで,トレンド判断の精度を高めます.
  2. 双方向取引:戦略は,多頭と空頭の両方で利益を得ることができ,資金の利用効率を向上させる.
  3. リスク管理: 固定ポイントのストップとストップを適用し,各取引のリスクを効果的に制御します.
  4. 利潤保護: 移動式ストップメカニズムを使用して,トレンドが継続するときに利潤の一部をロックします.
  5. 柔軟性: 戦略のパラメータは,異なる市場条件に適応して調整できます.

戦略リスク

  1. 振動市場リスク:横盤振動市場では,誤信号が頻繁に発生し,連続的な損失を引き起こす可能性があります.
  2. スリップポイントリスク:高波動性のある市場では,実際の取引価格は理想価格から大きく偏っている可能性があります.
  3. 過剰取引: 頻繁に取引するシグナルにより,取引コストが高くなる可能性があります.
  4. パラメータの感受性:戦略のパフォーマンスは,パラメータの設定に非常に敏感であり,異なる市場環境によって頻繁に調整する必要があるかもしれません.

戦略最適化の方向性

  1. 波動率指標の導入:異なる市場の変動状況に対応するために,ストップとストップポイントの位置を動的に調整するためにATR ((平均リアルレンジ) を追加することを検討する.
  2. トレンド強度フィルタリングを増やす:ADX (平均方向指数) を導入して,弱いトレンド信号をフィルタリングし,偽突破による損失を減らすことができる.
  3. 入場タイミングを最適化:RSI ((相対的に強い指標) またはMACD ((移動平均の相似散度) を組み合わせて入場タイミングを最適化して勝率を向上させる.
  4. 資金管理の最適化:ダイナミックなポジション管理を実現し,口座の純額と市場の変動に応じて取引毎の資金比率を調整する.
  5. 回測周期の拡張: 戦略を,異なる市場環境における安定性を検証するために,より長い時間周期で回測する.

要約する

この双線均一チャネルトレンド追跡戦略は,複数の技術指標を組み合わせることで,包括的な取引システムを提供しています.主要トレンドを捕捉するだけでなく,リスク管理と利益保護の仕組みも備えています.いくつかの潜在的リスクがあるものの,継続的な最適化とパラメータ調整により,この戦略は,さまざまな市場条件下で良好なパフォーマンスを発揮する可能性があります.

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

//@version=5
strategy("RC BTC Vegas 5min free ", overlay=true )

// 定义输入参数
short_ma_length = input.int(55, title="Short MA Length")
long_ma_length = input.int(300, title="Long MA Length")

ema1_length = input.int(576, title="EMA 1 Length")
ema2_length = input.int(676, title="EMA 2 Length")
// 计算移动平均线 
short_ma = ta.sma(close, short_ma_length)
long_ma = ta.sma(close, long_ma_length)
ema1 = ta.ema(close, ema1_length)
ema2 = ta.ema(close, ema2_length)
// 确定买入和卖出信号 
enter_long = ta.crossover(short_ma +5 , ema1)
enter_long2 = ta.crossover(short_ma +5 , long_ma)
enter_long3 =ta.crossover(long_ma+5  , ema1)

exit_long = ta.crossunder(short_ma -5, ema1) 
exit_long2 = ta.crossunder(short_ma -5, long_ma) 
exit_long3 = ta.crossunder(long_ma-5 , ema1)

// 记录进场价格
var float long_stop_loss = na
var float long_take_profit = na

if (enter_long or exit_long  )
    long_stop_loss := close

if (enter_long or exit_long)
    long_take_profit := close

// 根据进场价格计算止损和止盈点数 
stop_loss_points = long_stop_loss /70
take_profit_points  = long_take_profit /140
// 设置固定点数的止损和止
Along_stop_loss = close - stop_loss_points
Along_take_profit = close + take_profit_points
short_stop_loss = close + stop_loss_points
short_take_profit = close - take_profit_points

// 检查持仓利润是否达到300点
long_profit_target_reached = (strategy.position_size > 0 and (close - strategy.position_avg_price) >= take_profit_points)
short_profit_target_reached = (strategy.position_size < 0 and (strategy.position_avg_price - close) >= take_profit_points)

// 即时止损和止盈检查
long_stop_loss_hit = (strategy.position_size > 0 and close <= strategy.position_avg_price - stop_loss_points)
long_take_profit_hit = (strategy.position_size > 0 and close >= strategy.position_avg_price + take_profit_points)
short_stop_loss_hit = (strategy.position_size < 0 and close >= strategy.position_avg_price + stop_loss_points)
short_take_profit_hit = (strategy.position_size < 0 and close <= strategy.position_avg_price - take_profit_points)
// 上一根K棒的止盈止损检查
long_stop_loss_hit_prev = (strategy.position_size > 0 and low[1] <= strategy.position_avg_price - stop_loss_points)
long_take_profit_hit_prev = (strategy.position_size > 0 and high[1]>= strategy.position_avg_price + take_profit_points)
short_stop_loss_hit_prev = (strategy.position_size < 0 and high[1] >= strategy.position_avg_price + stop_loss_points)
short_take_profit_hit_prev = (strategy.position_size < 0 and low[1] <= strategy.position_avg_price - take_profit_points)

// 创建警报条件
alertcondition(long_stop_loss_hit, title="Long Stop Loss Hit", message="Long position stop loss hit")
alertcondition(long_take_profit_hit, title="Long Take Profit Hit", message="Long position take profit hit")
alertcondition(short_stop_loss_hit, title="Short Stop Loss Hit", message="Short position stop loss hit")
alertcondition(short_take_profit_hit, title="Short Take Profit Hit", message="Short position take profit hit")
// 移动止损输入
initialProfitLevel = input.float(9, title="Initial Profit Level (points)")
trailingStopIncrement = input.float(3, title="Trailing Stop Increment (points)")
if (close - long_take_profit >= 150)
    strategy.exit("多單移平", from_entry="Buy", trail_price=close+5 , trail_offset=5  )
if (close - long_take_profit <= -150)
    strategy.exit("空單移平", from_entry="Sell", trail_price=close-5 , trail_offset=5)

// 执行多单交易
if (enter_long or enter_long2  )
    strategy.entry("Buy", strategy.long, qty=1 , comment = "做多")

if (long_stop_loss_hit or long_take_profit_hit  ) 
    strategy.close("Buy",comment = "多單平倉")
//死亡交叉才跟著做空就打開
if (exit_long  or exit_long2  )
    strategy.entry("Sell" ,strategy.short, qty=1 , comment = "做空")

// 执行空单交易
if ( short_take_profit_hit or short_stop_loss_hit ) 
    strategy.close("Sell",comment = "空單平倉")

// 绘制移动平均线
plot(short_ma, title="Short MA", color=color.blue)
plot(long_ma, title="Long MA", color=color.red)

// 绘制进场和出场点
plotshape(series=enter_long, location=location.belowbar, color=color.green, style=shape.labelup, text="做多")
plotshape(series=exit_long , location=location.abovebar, color=color.red, style=shape.labeldown, text="做空") 
plotshape(series=long_take_profit_hit , location=location.abovebar, color=color.yellow, style=shape.labeldown, text="多單止盈")  
plotshape(series=short_take_profit_hit , location=location.abovebar, color=color.yellow, style=shape.labeldown, text="空單止盈") 
plotshape(series=short_stop_loss_hit , location=location.abovebar, color=color.black, style=shape.labeldown, text="空單止損") 
plotshape(series=long_stop_loss_hit , location=location.abovebar, color=color.black, style=shape.labeldown, text="多單止損") 
 
// 绘制止盈和止损点
plot(series=enter_long ? Along_take_profit : na, title="Take Profit", color=color.green, linewidth=2, style=plot.style_linebr)
plot(series=enter_long ? Along_stop_loss : na, title="Stop Loss", color=color.red, linewidth=2, style=plot.style_linebr)