
이 전략은 기술 지표에 기반한 변동 거래 전략으로, 평행선 교차, RSI 오버 바이 오버 셀, ATR 스톱 스톱 등과 같은 여러 신호를 결합한다. 이 전략의 핵심은 단기 EMA와 장기 SMA의 교차를 통해 시장 추세를 포착하는 것이며, RSI 지표를 사용하여 신호 확인을 하고, ATR을 통해 스톱 스톱 스톱 위치를 설정한다. 이 전략은 다공간 양방향 거래를 지원하며, 사용자의 선호에 따라 한 방향으로 유연하게 켜거나 닫을 수 있다.
전략은 다층적인 기술 지표 조합을 사용하여 거래 시스템을 구성합니다.
이 전략은 여러 기술적 지표의 조합을 사용하여 비교적 완전한 거래 시스템을 구축한다. 전략의 장점은 신호 확인의 신뢰성과 위험 관리의 완전성에 있다. 그러나 또한 시장 환경이 전략의 성능에 미치는 영향을 주의해야 한다. 제안된 최적화 방향을 통해 전략에는 큰 개선 공간이 있다. 실내 적용 시에는 충분한 매개 변수 테스트와 재검증이 권장된다.
/*backtest
start: 2019-12-23 08:00:00
end: 2024-12-10 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © CryptoRonin84
//@version=5
strategy("Swing Trading Strategy with On/Off Long and Short", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100)
// Input for turning Long and Short trades ON/OFF
enable_long = input.bool(true, title="Enable Long Trades")
enable_short = input.bool(true, title="Enable Short Trades")
// Input parameters for strategy
sma_short_length = input.int(20, title="Short EMA Length", minval=1)
sma_long_length = input.int(50, title="Long SMA Length", minval=1)
sl_percentage = input.float(1.5, title="Stop Loss (%)", step=0.1, minval=0.1)
tp_percentage = input.float(3, title="Take Profit (%)", step=0.1, minval=0.1)
risk_per_trade = input.float(1, title="Risk Per Trade (%)", step=0.1, minval=0.1)
capital = input.float(10000, title="Initial Capital", step=100)
// Input for date range for backtesting
start_date = input(timestamp("2020-01-01 00:00"), title="Backtest Start Date")
end_date = input(timestamp("2024-12-31 23:59"), title="Backtest End Date")
inDateRange = true
// Moving averages
sma_short = ta.ema(close, sma_short_length)
sma_long = ta.sma(close, sma_long_length)
// RSI setup
rsi = ta.rsi(close, 14)
rsi_overbought = 70
rsi_oversold = 30
// ATR for volatility-based stop-loss calculation
atr = ta.atr(14)
stop_loss_level_long = strategy.position_avg_price - (1.5 * atr)
stop_loss_level_short = strategy.position_avg_price + (1.5 * atr)
take_profit_level_long = strategy.position_avg_price + (3 * atr)
take_profit_level_short = strategy.position_avg_price - (3 * atr)
// Position sizing based on risk per trade
risk_amount = capital * (risk_per_trade / 100)
position_size = risk_amount / (close * sl_percentage / 100)
// Long and Short conditions
long_condition = ta.crossover(sma_short, sma_long) and rsi < rsi_overbought
short_condition = ta.crossunder(sma_short, sma_long) and rsi > rsi_oversold
// Execute long trades
if (long_condition and inDateRange and enable_long)
strategy.entry("Long", strategy.long, qty=position_size)
strategy.exit("Take Profit/Stop Loss", "Long", stop=stop_loss_level_long, limit=take_profit_level_long)
// Execute short trades
if (short_condition and inDateRange and enable_short)
strategy.entry("Short", strategy.short, qty=position_size)
strategy.exit("Take Profit/Stop Loss", "Short", stop=stop_loss_level_short, limit=take_profit_level_short)
// Plot moving averages
plot(sma_short, title="Short EMA", color=color.blue)
plot(sma_long, title="Long SMA", color=color.red)
// Plot RSI on separate chart
hline(rsi_overbought, "Overbought", color=color.red)
hline(rsi_oversold, "Oversold", color=color.green)
plot(rsi, title="RSI", color=color.purple)
// Plot signals on chart
plotshape(series=long_condition and enable_long, title="Long Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(series=short_condition and enable_short, title="Short Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")
// Background color for backtest range
bgcolor(inDateRange ? na : color.red, transp=90)