複数の移動平均トレンド追跡と動的ボラティリティフィルタリング戦略

EMA TR ATR
作成日: 2025-01-17 15:00:37 最終変更日: 2025-01-17 15:00:37
コピー: 3 クリック数: 303
1
フォロー
1617
フォロワー

複数の移動平均トレンド追跡と動的ボラティリティフィルタリング戦略

概要

この戦略は、トレンドフォローとボラティリティフィルタリングを組み合わせたインテリジェントな取引システムです。指数移動平均 (EMA) を通じて市場のトレンドを特定し、トゥルー レンジ (TR) と動的ボラティリティ フィルターを使用してエントリー タイミングを決定し、ボラティリティに基づいた動的なストップ プロフィットおよびストップ ロス メカニズムでリスクを管理します。この戦略は、スキャルプとスイングの 2 つの取引モードをサポートしており、さまざまな市場環境や取引スタイルに応じて柔軟に切り替えることができます。

戦略原則

戦略の中核となるロジックには、次の主要なコンポーネントが含まれます。

  1. トレンドの識別: 50 期間の EMA をトレンド フィルターとして使用し、価格が EMA を上回っている場合にのみロングし、価格が EMA を下回っている場合にのみショートします。
  2. ボラティリティ フィルタリング: 真の範囲 (TR) の EMA を計算し、調整可能なフィルター係数 (デフォルトは 1.5) を使用して市場のノイズを除去します。
  3. エントリー条件: 3 つの連続する K ラインの形態学的分析と組み合わせて、価格変動が継続的かつ加速的である必要があります。
  4. 利益確定と損失確定: 短期モードでは現在の TR に基づいて設定され、バンドモードでは過去の高値と安値に基づいて設定され、動的なリスク管理を実現します。

戦略的優位性

  1. 強力な適応性: 動的なボラティリティ フィルタリングとトレンド追跡を組み合わせることで、さまざまな市場環境に適応できます。
  2. 完璧なリスク管理: 2 つの取引モードに動的なストッププロフィットとストップロスのメカニズムを提供し、市場特性に応じて柔軟に選択できます。
  3. 優れたパラメータ調整機能: フィルタ係数、トレンドサイクルなどの主要なパラメータは、取引商品の特性に応じて最適化できます。
  4. 優れた視覚化効果: 明確な売買シグナル マークとストップ プロフィットおよびストップ ロスのポジション表示を提供し、取引の監視を容易にします。

戦略リスク

  1. トレンド反転リスク: トレンドの転換点で連続ストップが発生する可能性があります。
  2. 誤ったブレイクアウトのリスク: ボラティリティが突然増加すると、誤ったシグナルがトリガーされる可能性があります。
  3. パラメータの感度: フィルタ係数を不適切に設定すると、信号が多すぎたり少なすぎたりする可能性があります。
  4. スリッページの影響: 市場の動きが速い場合、大きなスリッページが発生し、戦略のパフォーマンスに影響する可能性があります。

戦略最適化の方向性

  1. トレンド強度フィルタリングの追加: ADX などのインジケーターを導入して、トレンドの強度を評価し、トレンド追跡効果を向上させることができます。
  2. 利益確定とストップロスを最適化します。より多くの利益を保護するために、移動ストップロスを導入することを検討します。
  3. スイングトレードモデルの改善:スイングトレード特有の判断条件をさらに追加して、中長期保有能力を向上させることができます。
  4. ボリューム分析を追加: ボリュームの変化を組み合わせて、ブレークスルーの有効性を確認します。

要約する

この戦略は、トレンド追跡、ボラティリティフィルタリング、動的リスク管理を有機的に組み合わせることで、完全な取引システムを構築します。この戦略の利点は、適応性が高くリスク管理が行き届いている一方で、最適化の余地が広いことです。パラメータを適切に設定し、適切な取引モードを選択することで、この戦略はさまざまな市場環境で安定したパフォーマンスを維持できます。トレーダーは実際の使用前に十分なバックテストとパラメータの最適化を実施し、特定の取引商品の特性に基づいて対応する調整を行うことをお勧めします。

ストラテジーソースコード
/*backtest
start: 2024-12-17 00:00:00
end: 2025-01-15 08:00:00
period: 2h
basePeriod: 2h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT","balance":49999}]
*/

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Creativ3mindz

//@version=5
strategy("Scalp Slayer (I)", overlay=true)

// Input Parameters
filterNumber = input.float(1.5, "Filter Number", minval=1.0, maxval=10.0, tooltip="Higher = More aggressive Filter, Lower = Less aggressive")
emaTrendPeriod = input.int(50, "EMA Trend Period", minval=1, tooltip="Period for the EMA used for trend filtering")
lookbackPeriod = input.int(20, "Lookback Period for Highs/Lows", minval=1, tooltip="Period for determining recent highs/lows")
colorTP = input.color(title='Take Profit Color', defval=color.orange)
colorSL = input.color(title='Stop Loss Color', defval=color.red)

// Inputs for visibility
showBuyLabels = input.bool(true, title="Show Buy Labels")
showSellLabels = input.bool(true, title="Show Sell Labels")

// Alert Options
alertOnCondition = input.bool(true, title="Alert on Condition Met", tooltip="Enable to alert when condition is met")

// Trade Mode Toggle
tradeMode = input.bool(false, title="Trade Mode (ON = Swing, OFF = Scalp)", tooltip="Swing-mode you can use your own TP/SL.")

// Calculations
tr = high - low
ema = filterNumber * ta.ema(tr, 50)
trendEma = ta.ema(close, emaTrendPeriod)  // Calculate the EMA for the trend filter

// Highest and lowest high/low within lookback period for swing logic
swingHigh = ta.highest(high, lookbackPeriod)
swingLow = ta.lowest(low, lookbackPeriod)

// Variables to track the entry prices and SL/TP levels
var float entryPriceLong = na
var float entryPriceShort = na
var float targetPriceLong = na
var float targetPriceShort = na
var float stopLossLong = na
var float stopLossShort = na
var bool tradeActive = false

// Buy and Sell Conditions with Trend Filter
buyCondition = close > trendEma and  // Buy only if above the trend EMA
      close[2] > open[2] and close[1] > open[1] and close > open and 
      (math.abs(close[2] - open[2]) > math.abs(close[1] - open[1])) and 
      (math.abs(close - open) > math.abs(close[1] - open[1])) and 
      close > close[1] and close[1] > close[2] and tr > ema

sellCondition = close < trendEma and  // Sell only if below the trend EMA
       close[2] < open[2] and close[1] < open[1] and close < open and 
       (math.abs(close[2] - open[2]) > math.abs(close[1] - open[1])) and 
       (math.abs(close - open) > math.abs(close[1] - open[1])) and 
       close < close[1] and close[1] < close[2] and tr > ema

// Entry Rules
if (buyCondition and not tradeActive)
    entryPriceLong := close  // Track entry price for long position
    stopLossLong := tradeMode ? ta.lowest(low, lookbackPeriod) : swingLow  // Scalping: recent low, Swing: lowest low of lookback period
    targetPriceLong := tradeMode ? close + tr : swingHigh  // Scalping: close + ATR, Swing: highest high of lookback period
    tradeActive := true

if (sellCondition and not tradeActive)
    entryPriceShort := close  // Track entry price for short position
    stopLossShort := tradeMode ? ta.highest(high, lookbackPeriod) : swingHigh  // Scalping: recent high, Swing: highest high of lookback period
    targetPriceShort := tradeMode ? close - tr : swingLow  // Scalping: close - ATR, Swing: lowest low of lookback period
    tradeActive := true

// Take Profit and Stop Loss Logic
signalBuyTPPrint = (not na(entryPriceLong) and close >= targetPriceLong)
signalSellTPPrint = (not na(entryPriceShort) and close <= targetPriceShort)

signalBuySLPrint = (not na(entryPriceLong) and close <= stopLossLong)
signalSellSLPrint = (not na(entryPriceShort) and close >= stopLossShort)

if (signalBuyTPPrint or signalBuySLPrint)
    entryPriceLong := na  // Reset entry price for long position
    targetPriceLong := na  // Reset target price for long position
    stopLossLong := na  // Reset stop-loss for long position
    tradeActive := false

if (signalSellTPPrint or signalSellSLPrint)
    entryPriceShort := na  // Reset entry price for short position
    targetPriceShort := na  // Reset target price for short position
    stopLossShort := na  // Reset stop-loss for short position
    tradeActive := false

// Plot Buy and Sell Labels with Visibility Conditions
plotshape(showBuyLabels and buyCondition, "Buy", shape.labelup, location=location.belowbar, color=color.green, text="BUY", textcolor=color.white, size=size.tiny)
plotshape(showSellLabels and sellCondition, "Sell", shape.labeldown, location=location.abovebar, color=color.red, text="SELL", textcolor=color.white, size=size.tiny)

// Plot Take Profit Flags
plotshape(showBuyLabels and signalBuyTPPrint, title="Take Profit (buys)", text="TP", style=shape.flag, location=location.abovebar, color=colorTP, textcolor=color.white, size=size.tiny)
plotshape(showSellLabels and signalSellTPPrint, title="Take Profit (sells)", text="TP", style=shape.flag, location=location.belowbar, color=colorTP, textcolor=color.white, size=size.tiny)

// Plot Stop Loss "X" Marker
plotshape(showBuyLabels and signalBuySLPrint, title="Stop Loss (buys)", text="X", style=shape.xcross, location=location.belowbar, color=colorSL, textcolor=color.white, size=size.tiny)
plotshape(showSellLabels and signalSellSLPrint, title="Stop Loss (sells)", text="X", style=shape.xcross, location=location.abovebar, color=colorSL, textcolor=color.white, size=size.tiny)

// Alerts

alertcondition(buyCondition and alertOnCondition, title="Buy Alert", message='{"content": "Buy {{ticker}} at {{close}}"}')
alertcondition(sellCondition and alertOnCondition, title="Sell Alert", message='{"content": "Sell {{ticker}} at {{close}}"}')
alertcondition(signalBuyTPPrint and alertOnCondition, title="Buy TP Alert", message='{"content": "Buy TP {{ticker}} at {{close}}"}')
alertcondition(signalSellTPPrint and alertOnCondition, title="Sell TP Alert", message='{"content": "Sell TP {{ticker}} at {{close}}"}')
alertcondition(signalBuySLPrint and alertOnCondition, title="Buy SL Alert", message='{"content": "Buy SL {{ticker}} at {{close}}"}')
alertcondition(signalSellSLPrint and alertOnCondition, title="Sell SL Alert", message='{"content": "Sell SL {{ticker}} at {{close}}"}')

if buyCondition
    strategy.entry("Enter Long", strategy.long)
else if sellCondition
    strategy.entry("Enter Short", strategy.short)