
이 전략은 종합적인 트렌드 추적과 동력 연동 거래 시스템으로, 주로 평평한 트렌드 판단과 상대적으로 강한 지수 ((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을 1번의 정지점으로 사용하고, 지지 저항이나 변동률에 따라 동적으로 정지 위치를 조정하여 핵심 가격 수준 근처에서 이익을 얻는 것을 고려할 수 있다.
거래 시간 필터를 추가합니다.: 시간 필터 또는 트랜지먼트 조건을 고려하고, 낮은 유동성 시점이나 비정상적인 트랜지먼트 상태를 피하고, 신호 품질을 향상한다.
기계 학습 최적화: 기계 학습 알고리즘을 사용하여 최적의 변수 조합 또는 거래 중계를 동적으로 예측하고, 실시간 시장 조건에 따라 스스로 조정한다.
트렌드 동력 협동 과중 위험 관리 정량 거래 전략은 트렌드 식별, 동력 확인, 정밀 위험 제어 및 지능형 자금 관리를 하나로 통합한 전체 거래 시스템입니다. 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