
この戦略は、方向性指数 (DMI) と平均真の範囲 (ATR) を組み合わせたトレンド追跡システムです。この戦略の核心は、DI+ および DI- 指標を通じて市場トレンドの方向と強さを特定し、ATR を使用して利益確定ポジションと損切りポジションを動的に調整することです。トレンドフィルタリングされた移動平均を補助的な確認として導入することで、取引シグナルの信頼性がさらに向上します。戦略設計は市場のボラティリティを十分に考慮しており、適応性に優れています。
この戦略は、次のコアメカニズムに基づいて機能します。
不安定な市場のリスク - レンジ相場では連続ストップが発生する可能性があります。 提案: オシレーター フィルターを追加するか、パラメーターのしきい値を調整します。
スリッページリスク - ボラティリティが高い期間には大きなスリッページが発生する可能性があります。 提案: ストップロスポジションを適切に緩和し、スリッページの余地を残します。
誤ったブレイクアウトのリスク - トレンドの転換点を誤って判断する可能性があります。 推奨事項: 取引量などの指標を組み合わせてシグナルを確認します。
パラメータの感度 - パラメータの組み合わせによってパフォーマンスが大きく異なる場合があります。 推奨事項: バックテストを通じて安定性の高いパラメータ範囲を見つけます。
シグナルの最適化 - トレンドの強さを評価するために ADX インジケーターを導入したり、ボリューム確認メカニズムを追加したりできます。
ポジション管理 - トレンドの強さに基づいてポジション サイズを動的に調整し、より洗練されたリスク管理を実現します。
時間枠 - 信号の信頼性を高めるために、複数の期間の分析を検討できます。
市場適応性 - さまざまな品種の特性に基づいて、適応パラメータ調整メカニズムを開発できます。
この戦略は、トレンド指標とボラティリティ指標を組み合わせることで、動的なトレンド追跡とリスク管理を実現します。実用性と操作性を重視した戦略設計で、市場適応性に優れています。パラメータの最適化と信号の改善を通じて、戦略をさらに改善する余地がまだあります。投資家は実際の適用において十分なテストを実施し、特定の市場特性に基づいて的を絞った調整を行うことをお勧めします。
/*backtest
start: 2019-12-23 08:00:00
end: 2025-01-04 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("使用 DI+ 和 DI- 的策略 (最終完整修正且含圖表止損止盈線)", overlay=true)
// 輸入參數
diLength = input.int(title="DI 長度", defval=14)
adxSmoothing = input.int(title="ADX Smoothing", defval=14)
trendFilterLength = input.int(title="趨勢過濾均線長度", defval=20)
strengthThreshold = input.int(title="趨勢強度門檻值", defval=20)
atrLength = input.int(title="ATR 長度", defval=14)
atrMultiplierStop = input.float(title="ATR 停損倍數", defval=1.5)
atrMultiplierTakeProfit = input.float(title="ATR 止盈倍數", defval=2.5)
// 計算 DI+ 和 DI-
[diPlus, diMinus, _] = ta.dmi(diLength, adxSmoothing)
// 計算趨勢過濾均線
trendFilterMA = ta.sma(close, trendFilterLength)
// 判斷趨勢方向和強度
strongUpTrend = diPlus > diMinus + strengthThreshold and close > trendFilterMA
strongDownTrend = diMinus > diPlus + strengthThreshold and close < trendFilterMA
// 計算 ATR
atr = ta.atr(atrLength)
// 追蹤止損止盈價格 (使用 var 宣告,只在進場時更新)
var float longStopPrice = na
var float longTakeProfitPrice = na
var float shortStopPrice = na
var float shortTakeProfitPrice = na
// 進場邏輯
longCondition = strongUpTrend
shortCondition = strongDownTrend
if (longCondition)
strategy.entry("多單", strategy.long)
longStopPrice := close - atr * atrMultiplierStop // 進場時計算並更新止損價
longTakeProfitPrice := close + atr * atrMultiplierTakeProfit // 進場時計算並更新止盈價
if (shortCondition)
strategy.entry("空單", strategy.short)
shortStopPrice := close + atr * atrMultiplierStop // 進場時計算並更新止損價
shortTakeProfitPrice := close - atr * atrMultiplierTakeProfit // 進場時計算並更新止盈價
// 出場邏輯 (使用 time 限制和 ATR)
inLongPosition = strategy.position_size > 0
inShortPosition = strategy.position_size < 0
lastEntryTime = strategy.opentrades.entry_bar_index(strategy.opentrades - 1)
if (inLongPosition and time > lastEntryTime)
strategy.exit("多單出場", "多單", stop=longStopPrice, limit=longTakeProfitPrice)
if (inShortPosition and time > lastEntryTime)
strategy.exit("空單出場", "空單", stop=shortStopPrice, limit=shortTakeProfitPrice)
// 繪製 DI+、DI- 和趨勢過濾均線
plot(diPlus, color=color.green, title="DI+")
plot(diMinus, color=color.red, title="DI-")
plot(trendFilterMA, color=color.blue, title="趨勢過濾均線")
// 繪製止損止盈線 (使用 plot 函數繪製)
plot(strategy.position_size > 0 ? longStopPrice : na, color=color.red, style=plot.style_linebr, linewidth=2, title="多單停損")
plot(strategy.position_size > 0 ? longTakeProfitPrice : na, color=color.green, style=plot.style_linebr, linewidth=2, title="多單止盈")
plot(strategy.position_size < 0 ? shortStopPrice : na, color=color.red, style=plot.style_linebr, linewidth=2, title="空單停損")
plot(strategy.position_size < 0 ? shortTakeProfitPrice : na, color=color.green, style=plot.style_linebr, linewidth=2, title="空單止盈")