デュアルトレンドフィルターチェーン移動平均比率戦略


作成日: 2023-12-28 17:37:14 最終変更日: 2023-12-28 17:37:14
コピー: 1 クリック数: 623
1
フォロー
1623
フォロワー

デュアルトレンドフィルターチェーン移動平均比率戦略

概要

この戦略は,ブリン付きフィルターと二重トレンドフィルタリング指標を組み合わせた二重移動平均比率指標に基づいて,鎖型退出機構を使用するトレンドフォロー戦略である. この戦略は,中長線トレンドの方向を識別するために,トレンドの方向が明確であるときに,より良い入場場場を選択し,利益をロックし,損失を減らすために,止まり,止損退出機構を設定することを目的としている.

戦略原則

  1. 速動平均 ((10日線) と遅動平均 ((50日線) を計算し,それらの比率を計算し,価格移動平均比率と呼ばれる.この比率は,価格の中間の長線傾向の変化を効果的に識別できる.
  2. 価格移動平均比率を過去比率の比率に変換する. この比率は振動器として定義される.
  3. 振動器上は設定した買入値 ((10) を突破すると買入シグナルを生じ,下は売り値 ((90) を突破すると売り出シグナルを生じ,トレンドフォローを行う.
  4. ブリン帯域幅の指標と組み合わせて取引信号をフィルタリングし,ブリン帯域が狭くなると操作する.
  5. 二重トレンドフィルタリング指標を用いて,価格が上昇トレンドチャネルにある場合にのみ買い信号が発生し,価格が下降チャネルにある場合にのみ売り信号が発生し,逆行操作を回避する.
  6. チェーン式退出の仕組みを設定し,停止,止損,組合せ退出を含む.複数の退出条件を予め設定し,最も利益のある退出条件を優先する.

戦略的優位性

  1. 二重トレンドフィルタリング機構,主動トレンドの方向を確実に判断し,逆転操作を避ける.
  2. 移動平均比率指標は,単一の移動平均よりもトレンドの変化を判断するのにより効果的です.
  3. ブリン帯域幅指数は,取引信号がより信頼される低波動期を効率的に特定します.
  4. チェイン・アウト・メカニズムは,収益を安定させ,全利益の最大化につながります.

リスクと解決策

  1. 震動の状況で明らかな傾向がない場合,誤信号と反転が多く発生する. 解決方法は,ブリン帯域度過を組み合わせて,収縮時に操作することである.
  2. 明らかなトレンド反転が発生すると,移動平均は遅滞が生じ,反転信号を最初に判断することはできません. 解決策は,移動平均周期パラメータを適切に短縮することです.
  3. 空飛ぶ隙間が発生した場合,止損点は瞬時に打たれ,大きな損失を招く可能性があります. 解決策は,適切な緩解止損点のパラメータです.

戦略最適化の方向性

  1. パラメータ最適化: 移動平均周期,振動器の買賣点,ブリン帯のパラメータ,トレンドフィルターパラメータの散策テストを行い,最適なパラメータの組み合わせを探します.
  2. 他の指標を組み込む.戦略の正確性を向上させるために,KD指標,MACD指標などの他の傾向転換の指標を組み込むことを検討することができます.
  3. 機械学習。 歴史的データを収集し,機械学習アルゴリズムの訓練モデルを利用し,動的に各パラメータを最適化し,パラメータの自生調整を実現する。

要約する

この戦略は,双重移動平均比率指標とブリン帯指標を総合的に使用して,中長線トレンドの方向を判断し,トレンドが確認された後に最適な入場ポイントを検索し,連鎖退出機構を設定して,利益をロックし,信頼性が高く,効果が顕著である.この戦略は,パラメータ最適化,その他の補助判断指標の追加,機械学習によりさらに改善され,収益率を向上させることができる.

ストラテジーソースコード
/*backtest
start: 2023-12-20 00:00:00
end: 2023-12-27 00:00:00
period: 3m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
strategy("Premium MA Ratio Strategy", overlay = true)

// Input: Adjustable parameters for Premium MA Ratio
fast_length = input(10, title = "Fast MA Length")
slow_length = input(50, title = "Slow MA Length")
oscillator_threshold_buy = input(10, title = "Oscillator Buy Threshold")
oscillator_threshold_sell = input(90, title = "Oscillator Sell Threshold")

// Input: Adjustable parameters for Bollinger Bands
bb_length = input(20, title = "Bollinger Bands Length")
bb_source = input(close, title = "Bollinger Bands Source")
bb_deviation = input(2.0, title = "Bollinger Bands Deviation")
bb_width_threshold = input(30, title = "BB Width Threshold")
use_bb_filter = input(true, title = "Use BB Width Filter?")

// Input: Adjustable parameters for Trend Filter
use_trend_filter = input(true, title = "Use Trend Filter?")
trend_filter_period_1 = input(50, title = "Trend Filter Period 1")
trend_filter_period_2 = input(200, title = "Trend Filter Period 2")
use_second_trend_filter = input(true, title = "Use Second Trend Filter?")

// Input: Adjustable parameters for Exit Strategies
use_exit_strategies = input(true, title = "Use Exit Strategies?")
use_take_profit = input(true, title = "Use Take Profit?")
take_profit_ticks = input(150, title = "Take Profit in Ticks")
use_stop_loss = input(true, title = "Use Stop Loss?")
stop_loss_ticks = input(100, title = "Stop Loss in Ticks")
use_combined_exit = input(true, title = "Use Combined Exit Strategy?")
combined_exit_ticks = input(50, title = "Combined Exit Ticks")

// Input: Adjustable parameters for Time Filter
use_time_filter = input(false, title = "Use Time Filter?")
start_hour = input(8, title = "Start Hour")
end_hour = input(16, title = "End Hour")

// Calculate moving averages
fast_ma = sma(close, fast_length)
slow_ma = sma(close, slow_length)

// Calculate the premium price moving average ratio
premium_ratio = fast_ma / slow_ma * 100

// Calculate the percentile rank of the premium ratio
percentile_rank(src, length) =>
    rank = 0.0
    for i = 1 to length
        if src > src[i]
            rank := rank + 1.0
    percentile = rank / length * 100

// Calculate the percentile rank for the premium ratio using slow_length periods
premium_ratio_percentile = percentile_rank(premium_ratio, slow_length)

// Calculate the oscillator based on the percentile rank
oscillator = premium_ratio_percentile

// Dynamic coloring for the oscillator line
oscillator_color = oscillator > 50 ? color.green : color.red

// Plot the oscillator on a separate subplot as a line
hline(50, "Midline", color = color.gray)
plot(oscillator, title = "Oscillator", color = oscillator_color, linewidth = 2)

// Highlight the overbought and oversold areas
bgcolor(oscillator > oscillator_threshold_sell ? color.red : na, transp = 80)
bgcolor(oscillator < oscillator_threshold_buy ? color.green : na, transp = 80)

// Plot horizontal lines for threshold levels
hline(oscillator_threshold_buy, "Buy Threshold", color = color.green)
hline(oscillator_threshold_sell, "Sell Threshold", color = color.red)

// Calculate Bollinger Bands width
bb_upper = sma(bb_source, bb_length) + bb_deviation * stdev(bb_source, bb_length)
bb_lower = sma(bb_source, bb_length) - bb_deviation * stdev(bb_source, bb_length)
bb_width = bb_upper - bb_lower

// Calculate the percentile rank of Bollinger Bands width
bb_width_percentile = percentile_rank(bb_width, bb_length)

// Plot the Bollinger Bands width percentile line
plot(bb_width_percentile, title = "BB Width Percentile", color = color.blue, linewidth = 2)

// Calculate the trend filters
trend_filter_1 = sma(close, trend_filter_period_1)
trend_filter_2 = sma(close, trend_filter_period_2)

// Strategy logic
longCondition = crossover(premium_ratio_percentile, oscillator_threshold_buy)
shortCondition = crossunder(premium_ratio_percentile, oscillator_threshold_sell)

// Apply Bollinger Bands width filter if enabled
if (use_bb_filter)
    longCondition := longCondition and bb_width_percentile < bb_width_threshold
    shortCondition := shortCondition and bb_width_percentile < bb_width_threshold

// Apply trend filters if enabled
if (use_trend_filter)
    longCondition := longCondition and (close > trend_filter_1)
    shortCondition := shortCondition and (close < trend_filter_1)

// Apply second trend filter if enabled
if (use_trend_filter and use_second_trend_filter)
    longCondition := longCondition and (close > trend_filter_2)
    shortCondition := shortCondition and (close < trend_filter_2)

// Apply time filter if enabled
if (use_time_filter)
    longCondition := longCondition and (hour >= start_hour and hour <= end_hour)
    shortCondition := shortCondition and (hour >= start_hour and hour <= end_hour)

// Generate trading signals with exit strategies
if (use_exit_strategies)
    strategy.entry("Buy", strategy.long, when = longCondition)
    strategy.entry("Sell", strategy.short, when = shortCondition)
    
    // Define unique exit names for each order
    buy_take_profit_exit = "Buy Take Profit"
    buy_stop_loss_exit = "Buy Stop Loss"
    sell_take_profit_exit = "Sell Take Profit"
    sell_stop_loss_exit = "Sell Stop Loss"
    combined_exit = "Combined Exit"
    
    // Exit conditions for take profit
    if (use_take_profit)
        strategy.exit(buy_take_profit_exit, from_entry = "Buy", profit = take_profit_ticks)
        strategy.exit(sell_take_profit_exit, from_entry = "Sell", profit = take_profit_ticks)
    
    // Exit conditions for stop loss
    if (use_stop_loss)
        strategy.exit(buy_stop_loss_exit, from_entry = "Buy", loss = stop_loss_ticks)
        strategy.exit(sell_stop_loss_exit, from_entry = "Sell", loss = stop_loss_ticks)
    
    // Combined exit strategy
    if (use_combined_exit)
        strategy.exit(combined_exit, from_entry = "Buy", loss = combined_exit_ticks, profit = combined_exit_ticks)