
この戦略は,総合的なトレンド追跡と動量協同取引システムであり,主に均線的なトレンド判断と比較的強い指数 ((RSI)) の動量確認に基づいて高確率の取引機会を識別する.戦略の核心は”,順位を保つ”という取引哲学に従っており,市場の主なトレンドの方向を確認した後で,リコーディングを待って,動量指標と組み合わせて最適なエントリーポイントを探します.同時に,戦略は,実際の波動幅 ((ATR)) に基づくリスク管理システムを採用し,取引毎のリスクの一致性を確保し,段差で利益を得ることと追随損失の仕組みによって資金管理の効率を最適化します.
戦略の運営原理は,トレンド認識,入場条件判断,リスク管理,利益最適化という4つの重要なモジュールに基づいています.
トレンド認識:
入学条件の判断:
リスク管理:
利益の最適化:
戦略の実施では,正確な数学的な計算を使用して最適なポジションの大きさを決定し,各取引のリスクが既定のレベルで制御され,パラメータで異なる市場条件に適応することを許可します.
この戦略は,以下のような大きな利点があります.
高品質の取引信号: トレンドとモーションの協同確認により,高い確率の方向のみでポジションを開き,勝利率を大幅に高めます.long_trend_okそしてlong_rsi_recovery取引信号の質を保証する条件の組み合わせ
リスク管理に適応するATR ベースのストップデザインは,市場波動性に応じて戦略が自動的にリスクパラメータを調整できるようにする. 波動的な市場環境ではより緩やかなストップを使用し,静かな市場ではより緊密なストップを使用し,最適のリスク制御を実現する.
資金管理の最適化区切り利益の仕組み (50%のポジションは2.1Rで利益を得,残りの部分は尾行ストップを使用) は,利益を確保し,トレンドを最大限に捉えるバランスを実現します.long_tp1_hitそしてlong_trail_stopこのプロセスは等変数によって精密に制御されます.
ルールが客観的に明確です: 戦略は完全に量化され,取引における感情的干渉は排除され,実行は厳格である. すべての取引決定は,明確な数学的な計算と論理的条件に基づいて,主観的な判断を避けている.
ビジュアル化による意思決定支援戦略は,トレンドの背景の色,入場信号の標識,およびストップ/利益目標の可視化を含む完全な視覚的フィードバックシステムを提供し,トレーダーが戦略の動作を理解し,監視することを容易にします.
パラメータの可変性: EMA周期,RSI値,ATR倍数などのコアパラメータは,戦略が異なる市場環境と個人のリスク好みに適応できるように調整できます.
この戦略は複数の利点があるものの,以下の潜在的なリスクがあります.
トレンド認識の遅れ: EMAをトレンド判断ツールとして使用するには固有の遅滞があり,トレンドの初期にいくつかの機会を逃したり,トレンドの終わりに元の方向のポジションを維持したりする可能性があります. 解決策は,短期トレンド確認指標を追加するか,EMAパラメータを調整して感度を増やすことを検討することです.
偽の突破の危険性:RSI反転シグナルは,偽の突破が発生し,誤った取引を引き起こす可能性があります. このリスクに対して,取引量の変化または他の動向指標の協同確認などの確認条件を追加することができます.
横盤市場には適していない: 戦略は明らかにトレンド市場で最適で,横横整理段階では頻繁に誤信号と損失取引が生じることがあります. 市場が明らかに区間振動しているときに戦略を一時停止することをお勧めし,トレンド強度フィルターを追加することでこのような状況を認識することができます.
パラメータ感度: 戦略性能はパラメータ選択に敏感であり,特にEMA周期とRSIの値の設定である. 異なる市場条件でパラメータを最適化して,過度にフィットすることを避けるために,歴史を遡ることを推奨する.
資金管理のリスク: 固定パーセントリスク管理は,極端な市場条件下でも,連続損失の累積につながる可能性があります. 連続損失の後にポジションのサイズを徐々に小さくするダイナミックリスク調整メカニズムの実施を検討することをお勧めします.
戦略のコード分析により,以下の方向に最適化が可能である.
複数の時間周期の同定: 複数の時間周期のトレンドと動力の信号を統合し,取引決定の正確性を向上させる.例えば,日経トレンドが4時間動力の一致かどうかをチェックし,方向が一致するときにのみ取引することができる.
トレンド強度フィルター: ADX (平均方向指数) などのトレンド強度指標を導入し,トレンドが十分に強いときにのみポジションを開き,弱いトレンドまたは横軸市場の誤った信号を避ける.コードはuptrendそしてdowntrend条件の判断の強化について
動的にリスク参数調整: 市場変動,口座利権曲線,または戦略のパフォーマンス指標に基づいて,各取引のリスク比率を動的に調整し,戦略が良好なパフォーマンスを示す場合,リスクを適度に増加させ,不良なパフォーマンスを示す場合,リスクを減少させる.
市場環境分析を統合する: 変動率指数や市場構造分析などのマクロ市場環境認識モジュールを導入し,異なる市場段階に応じて戦略パラメータを自動的に調整するか,選択的に起動する.
止装置の最適化:現在の戦略は,最初のストップポイントとして固定2.1Rを使用し,サポートレジスタンスまたは波動率に基づいてストップポジションを動的に調整することを考慮し,重要な価格レベル近くで利益を得る.
取引時間フィルターを追加します.: タイムフィルターまたは交差量条件を考慮し,低流動性の時間または異常な交差量状態を回避し,信号品質を向上させる.
機械学習の最適化: 最適なパラメータの組み合わせや取引重量を動的に予測する機械学習アルゴリズムを使用し,リアルタイム市場の状況に応じて自律的に調整する.
トレンド・ダイナミクス・協同・重量化リスク管理 量化取引戦略は,トレンド・識別・ダイナミクス・確認・精密リスク・コントロール・インテリジェント・マネジメントを統合した完全な取引システムである.EMA均線によって市場の方向を決定し,RSIダイナミクス・インディケータは,最適の入場タイミングを決定し,ATRベースのダイナミック・ストップ・ロズ・アンド・セグメント・リターン・メカニズムを採用し,リスクと利益の最適なバランスを実現する.
この戦略の最大の優点は,その体系性と規律性であり,明瞭な量化ルールによって取引過程における感情的な干渉を排除し,安定した取引スタイルを追求する量化トレーダーに適しています.同時に,戦略のリスク管理モジュールは,単一の損失が制限され,利益の可能性は制限されないことを保証し,成功取引の核心原則に適合しています.
トレンド判断の遅れや横軸市場の適応性の不足などの固有の限界があるにもかかわらず,前述の最適化方向,例えば多周期分析,トレンド強度フィルタリング,ダイナミックリスク調整などの方向によって,戦略の頑丈性と適応性をさらに向上させることができます.将来の発展方向は,異なる市場環境下で安定したパフォーマンスを維持できるように戦略の自己適応性を強化することに重点を置くべきです.
この戦略は,体系的な取引方法を求める投資家にとって,個人リスクの好みや市場の理解に基づいてさらにカスタマイズ・最適化できる,堅固な基礎の枠組みを提供します.
/*backtest
start: 2024-06-17 00:00:00
end: 2025-06-15 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"DOGE_USDT"}]
*/
//@version=5
strategy("Crypto Swing Trading Strategy (1-5 Day)", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, pyramiding=0, calc_on_every_tick=false, calc_on_order_fills=false)
// ============================================================================
// STRATEGY INPUTS
// ============================================================================
// Trend Filter Settings
ema_fast_length = input.int(50, title="Fast EMA Length", minval=1, group="Trend Filter")
ema_slow_length = input.int(200, title="Slow EMA Length", minval=1, group="Trend Filter")
// RSI Settings
rsi_length = input.int(14, title="RSI Length", minval=1, group="Momentum")
rsi_oversold = input.int(45, title="RSI Oversold Level", minval=1, maxval=50, group="Momentum")
rsi_overbought = input.int(70, title="RSI Overbought Level", minval=50, maxval=99, group="Momentum")
// ATR Settings
atr_length = input.int(14, title="ATR Length", minval=1, group="Risk Management")
atr_stop_mult = input.float(1.5, title="ATR Stop Loss Multiplier", minval=0.1, step=0.1, group="Risk Management")
atr_trail_mult = input.float(1.0, title="ATR Trailing Stop Multiplier", minval=0.1, step=0.1, group="Risk Management")
// Risk Management
risk_per_trade = input.float(1.0, title="Risk Per Trade (%)", minval=0.1, maxval=5.0, step=0.1, group="Risk Management")
reward_ratio = input.float(2.1, title="Initial Take Profit Ratio (R:R)", minval=1.0, step=0.1, group="Risk Management")
// Strategy Settings
pullback_distance = input.float(1.0, title="Max Distance from 50 EMA for Pullback (ATR)", minval=0.1, step=0.1, group="Entry Conditions")
enable_shorts = input.bool(true, title="Enable Short Trades", group="Strategy Settings")
enable_longs = input.bool(true, title="Enable Long Trades", group="Strategy Settings")
// ============================================================================
// INDICATOR CALCULATIONS
// ============================================================================
// Moving Averages
ema_fast = ta.ema(close, ema_fast_length)
ema_slow = ta.ema(close, ema_slow_length)
// RSI
rsi = ta.rsi(close, rsi_length)
// ATR
atr = ta.atr(atr_length)
// ============================================================================
// TREND IDENTIFICATION
// ============================================================================
// Primary trend based on EMA relationship
uptrend = ema_fast > ema_slow
downtrend = ema_fast < ema_slow
// ============================================================================
// ENTRY CONDITIONS
// ============================================================================
// Long Entry Conditions
long_trend_ok = uptrend and enable_longs
long_pullback = math.abs(close - ema_fast) <= (pullback_distance * atr) and close < ema_fast[1]
long_rsi_oversold = rsi[1] < rsi_oversold
long_rsi_recovery = rsi > rsi_oversold and rsi[1] <= rsi_oversold
long_entry_condition = long_trend_ok and long_pullback and long_rsi_oversold and long_rsi_recovery
// Short Entry Conditions
short_trend_ok = downtrend and enable_shorts
short_pullback = math.abs(close - ema_fast) <= (pullback_distance * atr) and close > ema_fast[1]
short_rsi_overbought = rsi[1] > rsi_overbought
short_rsi_decline = rsi < rsi_overbought and rsi[1] >= rsi_overbought
short_entry_condition = short_trend_ok and short_pullback and short_rsi_overbought and short_rsi_decline
// ============================================================================
// POSITION SIZING
// ============================================================================
// Calculate position size based on risk per trade and ATR stop distance
calculate_position_size(entry_price, stop_price, risk_percent) =>
risk_amount = strategy.equity * (risk_percent / 100)
stop_distance = math.abs(entry_price - stop_price)
position_size = stop_distance > 0 ? risk_amount / stop_distance : 0
position_size
// ============================================================================
// STRATEGY VARIABLES
// ============================================================================
var float long_entry_price = na
var float long_stop_price = na
var float long_tp1_price = na
var float long_trail_stop = na
var bool long_tp1_hit = false
var float short_entry_price = na
var float short_stop_price = na
var float short_tp1_price = na
var float short_trail_stop = na
var bool short_tp1_hit = false
// ============================================================================
// LONG TRADE MANAGEMENT
// ============================================================================
// Long Entry
if long_entry_condition and strategy.position_size == 0
long_entry_price := close
long_stop_price := close - (atr_stop_mult * atr)
long_tp1_price := close + (reward_ratio * (close - long_stop_price))
long_trail_stop := long_stop_price
long_tp1_hit := false
// Calculate position size
pos_size = calculate_position_size(long_entry_price, long_stop_price, risk_per_trade)
strategy.entry("Long", strategy.long, qty=pos_size)
strategy.exit("Long Stop", "Long", stop=long_stop_price)
// Long TP1 Management (Take 50% profit at 2:1 R:R)
if strategy.position_size > 0 and not long_tp1_hit and high >= long_tp1_price
long_tp1_hit := true
strategy.close("Long", qty_percent=50, comment="TP1 - 50%")
// Move stop to breakeven
long_trail_stop := long_entry_price
strategy.cancel("Long Stop")
// Long Trailing Stop (for remaining 50% position)
if strategy.position_size > 0 and long_tp1_hit
// Calculate new trailing stop
highest_since_tp1 = ta.highest(high, 1)
new_trail_stop = highest_since_tp1 - (atr_trail_mult * atr)
// Only move stop up, never down
if new_trail_stop > long_trail_stop
long_trail_stop := new_trail_stop
// Exit on trailing stop or trend reversal
if close <= long_trail_stop or not uptrend
strategy.close("Long", comment=not uptrend ? "Trend Reversal" : "Trailing Stop")
// ============================================================================
// SHORT TRADE MANAGEMENT
// ============================================================================
// Short Entry
if short_entry_condition and strategy.position_size == 0
short_entry_price := close
short_stop_price := close + (atr_stop_mult * atr)
short_tp1_price := close - (reward_ratio * (short_stop_price - close))
short_trail_stop := short_stop_price
short_tp1_hit := false
// Calculate position size
pos_size = calculate_position_size(short_entry_price, short_stop_price, risk_per_trade)
strategy.entry("Short", strategy.short, qty=pos_size)
strategy.exit("Short Stop", "Short", stop=short_stop_price)
// Short TP1 Management (Take 50% profit at 2:1 R:R)
if strategy.position_size < 0 and not short_tp1_hit and low <= short_tp1_price
short_tp1_hit := true
strategy.close("Short", qty_percent=50, comment="TP1 - 50%")
// Move stop to breakeven
short_trail_stop := short_entry_price
strategy.cancel("Short Stop")
// Short Trailing Stop (for remaining 50% position)
if strategy.position_size < 0 and short_tp1_hit
// Calculate new trailing stop
lowest_since_tp1 = ta.lowest(low, 1)
new_trail_stop = lowest_since_tp1 + (atr_trail_mult * atr)
// Only move stop down, never up
if new_trail_stop < short_trail_stop
short_trail_stop := new_trail_stop
// Exit on trailing stop or trend reversal
if close >= short_trail_stop or not downtrend
strategy.close("Short", comment=not downtrend ? "Trend Reversal" : "Trailing Stop")
// ============================================================================
// PLOTTING
// ============================================================================
// Plot EMAs
plot(ema_fast, title="EMA 50", color=color.blue, linewidth=2)
plot(ema_slow, title="EMA 200", color=color.red, linewidth=2)
// Color background based on trend
bgcolor(uptrend ? color.new(color.green, 95) : downtrend ? color.new(color.red, 95) : na, title="Trend Background")
// Plot RSI levels (scaled to price for visualization)
hline(rsi_overbought, title="RSI Overbought", color=color.red, linestyle=hline.style_dashed)
hline(rsi_oversold, title="RSI Oversold", color=color.green, linestyle=hline.style_dashed)
// Plot entry signals
plotshape(long_entry_condition, title="Long Entry", style=shape.triangleup, location=location.belowbar, color=color.green, size=size.normal)
plotshape(short_entry_condition, title="Short Entry", style=shape.triangledown, location=location.abovebar, color=color.red, size=size.normal)
// Plot stop losses and targets for current position
plot(strategy.position_size > 0 ? long_trail_stop : na, title="Long Trailing Stop", color=color.red, style=plot.style_stepline, linewidth=2)
plot(strategy.position_size < 0 ? short_trail_stop : na, title="Short Trailing Stop", color=color.red, style=plot.style_stepline, linewidth=2)
plot(strategy.position_size > 0 and not long_tp1_hit ? long_tp1_price : na, title="Long TP1", color=color.green, style=plot.style_cross, linewidth=2)
plot(strategy.position_size < 0 and not short_tp1_hit ? short_tp1_price : na, title="Short TP1", color=color.green, style=plot.style_cross, linewidth=2)
// ============================================================================
// INFORMATION DISPLAY (Using Labels instead of Table)
// ============================================================================
// Display key information using labels on the last bar
if barstate.islast
// Create info label with key metrics
trend_text = uptrend ? "UP" : downtrend ? "DOWN" : "SIDE"
position_text = strategy.position_size > 0 ? "LONG" : strategy.position_size < 0 ? "SHORT" : "NONE"
info_text = "Trend: " + trend_text + "\nRSI: " + str.tostring(math.round(rsi, 1)) + "\nATR: " + str.tostring(math.round(atr, 2)) + "\nPosition: " + position_text
label.new(bar_index, high + atr, info_text,
color=uptrend ? color.new(color.green, 80) : downtrend ? color.new(color.red, 80) : color.new(color.gray, 80),
textcolor=color.white, style=label.style_label_down, size=size.normal)
// ============================================================================
// ALERTS
// ============================================================================
// Alert conditions
alertcondition(long_entry_condition, title="Long Entry Signal", message="LONG: Swing trading signal for {{ticker}} at {{close}}")
alertcondition(short_entry_condition, title="Short Entry Signal", message="SHORT: Swing trading signal for {{ticker}} at {{close}}")
alertcondition(strategy.position_size > 0 and long_tp1_hit, title="Long TP1 Hit", message="LONG TP1: First target hit for {{ticker}} at {{close}}")
alertcondition(strategy.position_size < 0 and short_tp1_hit, title="Short TP1 Hit", message="SHORT TP1: First target hit for {{ticker}} at {{close}}")
// ============================================================================
// STRATEGY SUMMARY
// ============================================================================
// This strategy implements the full swing trading approach described in the document:
// 1. Trend filtering using 50/200 EMA (only trade with the trend)
// 2. RSI momentum for entry timing (buy oversold in uptrend, sell overbought in downtrend)
// 3. ATR-based position sizing and stop losses (volatility-adjusted risk management)
// 4. Partial profit taking at 2:1 R:R (50% of position)
// 5. Trailing stops for remaining position using ATR
// 6. Trend reversal exits (close all when trend changes)
//
// Key Features:
// - Configurable parameters for different market conditions
// - Risk management with consistent 1% risk per trade
// - Visual indicators for trend, signals, and trade management
// - Information table showing key metrics
// - Alert system for automated notifications
//
// Recommended for: BTC, ETH, XRP on daily timeframes
// Holding period: 1-5 days typical