ダイナミックATRトレーリングストップロスと移動平均クロスオーバーの組み合わせ戦略

EMA ATR RSI SMA VOLUME
作成日: 2025-02-18 15:48:18 最終変更日: 2025-02-18 15:48:18
コピー: 1 クリック数: 504
1
フォロー
1617
フォロワー

ダイナミックATRトレーリングストップロスと移動平均クロスオーバーの組み合わせ戦略

概要

この戦略は,ATRの動的なストップと均線交差を追跡する複合型取引システムであり,取引フィルタリングとリスク管理のために複数の技術指標を組み合わせている.この戦略は,15分間の時間周期で動作し,EMA均線,ATRの波動率,RSI指標,取引量などの多次元指標を使用して取引信号を決定し,動的なストップを追跡する方法で損失リスクを管理する.

戦略原則

戦略の核心的な論理には以下の重要な要素が含まれています.

  1. 入場条件は複数のフィルタリングメカニズムで設定されています.
    • 価格が100サイクルEMA上下にある
    • 1時間周期100EMAトレンド確認
    • 価格とATRのストップラインの交差点
    • RSIは30から70までの中性領域
    • 現在取引量は20サイクル平均より大きい
  2. リスク管理システム:
    • 3倍ATRに基づく動的追跡ストップ
    • ATRを2倍に設定する
  3. 出場メカニズム:
    • 15と17周期EMAの連続した2つのK線の交差信号
    • ストップ・ロースまたは利益の目標を追跡する

戦略的優位性

  1. 複数の技術指標のクロス検証により,偽信号を低減する
  2. 多周期的なトレンドフィルターを使用して,取引方向の正確性を向上させる
  3. ダイナミックATRストップは,市場の変動に応じて自律的に調整できます.
  4. 利得目標と止損を結びつけ,リスクと利益のバランスを確保する
  5. EMA交差点を出場信号として使用し,早退を避ける
  6. 取引の有効性を高める

戦略リスク

  1. 複数のフィルタリング条件により,一部の取引機会を逃す可能性があります.
  2. ATRのストップは,波動の激しい市場では,過大に拡大する可能性があります.
  3. 連続EMA交差出場が利益の一部を吐き出す可能性がある
  4. 市場動向に強い依存度,振動的な市場では不良な結果が出る可能性
  5. 計算が複雑で実行が遅れるリスクがある

戦略最適化の方向性

  1. 適応パラメータの最適化メカニズムを導入する:
    • ATRの倍数は,市場の状況に応じて動的に調整できます.
    • EMA周期は,市場の変動率に基づいて自動的に最適化されます.
  2. 市場状況を把握する
    • トレンドの強さの指標を追加
    • 波動率周期判断を導入する
  3. リスク管理の改善:
    • 貯蔵庫の建設と削減の実施
    • 最大保有時間制限を増加させる
  4. 試合開始の仕組みを最適化する:
    • トレンドの強さによる収益目標の動的調整
    • タイムストップメカニズムを追加

要約する

この戦略は,複数の技術指標とリスク管理手段を総合的に適用することで,比較的完全な取引システムを構築している.戦略の主要な特徴は,市場の変動に適応するために動的なATRのストップを追跡することであり,同時に取引信号を確認するために複数の指標のフィルターと均一線の交差を利用することです.ある程度の最適化の余地があるものの,全体的な設計理念は,現代の定量取引の要求に適合し,良い実用的な応用価値を持っています.

ストラテジーソースコード
/*backtest
start: 2024-02-19 00:00:00
end: 2025-02-16 08:00:00
period: 2h
basePeriod: 2h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy(title='UT Bot Strategy with 100 EMA Filter, Trailing Stop and EMA Cross Exit', overlay=true)

// Inputs
a = input(1, title='Key Value. \'This changes the sensitivity\'')
c = input(10, title='ATR Period')
h = input(false, title='Signals from Heikin Ashi Candles')

// Higher timeframe trend filter (1-hour)
higherTimeframeEMA = request.security(syminfo.tickerid, "60", ta.ema(close, 100)) // 1-hour EMA

xATR = ta.atr(c)

// Adjusting ATR multiplier for Gold on 15-minute timeframe
atrMultiplier = 3
nLoss = atrMultiplier * xATR  // ATR-based loss calculation

src = h ? request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, close, lookahead=barmerge.lookahead_off) : close

// Trailing Stop Calculation
xATRTrailingStop = 0.0
iff_1 = src > nz(xATRTrailingStop[1], 0) ? src - nLoss : src + nLoss
iff_2 = src < nz(xATRTrailingStop[1], 0) and src[1] < nz(xATRTrailingStop[1], 0) ? math.min(nz(xATRTrailingStop[1]), src + nLoss) : iff_1
xATRTrailingStop := src > nz(xATRTrailingStop[1], 0) and src[1] > nz(xATRTrailingStop[1], 0) ? math.max(nz(xATRTrailingStop[1]), src - nLoss) : iff_2

pos = 0
iff_3 = src[1] > nz(xATRTrailingStop[1], 0) and src < nz(xATRTrailingStop[1], 0) ? -1 : nz(pos[1], 0)
pos := src[1] < nz(xATRTrailingStop[1], 0) and src > nz(xATRTrailingStop[1], 0) ? 1 : iff_3

xcolor = pos == -1 ? color.red : pos == 1 ? color.green : color.blue

// Define 100 EMA
ema100 = ta.ema(src, 100)
plot(ema100, title="100 EMA", color=color.black, linewidth=2)

// Define 15 EMA and 17 EMA for exit conditions
ema15 = ta.ema(src, 15)
ema17 = ta.ema(src, 17)
plot(ema15, title="15 EMA", color=color.blue, linewidth=1)
plot(ema17, title="17 EMA", color=color.purple, linewidth=1)

// Define Entry Conditions
longCondition = src > ema100 and src > xATRTrailingStop and close > higherTimeframeEMA and ta.crossover(ta.ema(src, 1), xATRTrailingStop)
shortCondition = src < ema100 and src < xATRTrailingStop and close < higherTimeframeEMA and ta.crossover(xATRTrailingStop, ta.ema(src, 1))

// RSI Filter
rsi = ta.rsi(close, 14)
longCondition := longCondition and rsi > 30 and rsi < 70  // Ensure RSI is not in extreme conditions
shortCondition := shortCondition and rsi > 30 and rsi < 70

// Volume Filter
volumeMA = ta.sma(volume, 20)
longCondition := longCondition and volume > volumeMA
shortCondition := shortCondition and volume > volumeMA

// ** Trailing Stop Setup **
trailOffset = nLoss  // The trailing stop distance is based on ATR, which is already calculated
trailPriceLong = close - trailOffset  // The trailing stop for long trades is below the entry price
trailPriceShort = close + trailOffset  // The trailing stop for short trades is above the entry price

// Define Take Profit (TP) condition
takeProfitMultiplier = 2  // This sets the take profit at 2x the ATR from the entry
takeProfitLong = close + takeProfitMultiplier * nLoss
takeProfitShort = close - takeProfitMultiplier * nLoss

// Strategy Entries
if (longCondition)
    strategy.entry('long', strategy.long)

if (shortCondition)
    strategy.entry('short', strategy.short)

// Exit conditions for 15 and 17 EMA cross (must be consecutive on two bars)
exitLong = ta.crossover(ema15, ema17) and ta.crossover(ema15[1], ema17[1])  // Exit long if both the current and previous bars have 15 EMA crossing above 17 EMA
exitShort = ta.crossunder(ema15, ema17) and ta.crossunder(ema15[1], ema17[1])  // Exit short if both the current and previous bars have 15 EMA crossing below 17 EMA

// Apply trailing stop and take profit along with EMA cross exit
strategy.exit("Exit Long", "long", trail_price=trailPriceLong, trail_offset=trailOffset, limit=takeProfitLong)  // Long exit with trailing stop and TP
strategy.exit("Exit Short", "short", trail_price=trailPriceShort, trail_offset=trailOffset, limit=takeProfitShort)  // Short exit with trailing stop and TP

// Close positions when 15 and 17 EMAs cross consecutively
strategy.close("long", when=exitLong)
strategy.close("short", when=exitShort)

// Alert condition for trade closure
longExitAlert = exitLong  // Only trigger alert for long if both consecutive bars show crossover
shortExitAlert = exitShort  // Only trigger alert for short if both consecutive bars show crossunder

alertcondition(longExitAlert, title="Close Long Trade", message="Long trade closed. 15 EMA crossed above 17 EMA on two consecutive bars.")
alertcondition(shortExitAlert, title="Close Short Trade", message="Short trade closed. 15 EMA crossed below 17 EMA on two consecutive bars.")