
이 전략은 상대 강도 지수(RSI), 지수 이동 평균(EMA), 평균 진폭 범위(ATR)를 기반으로 한 포괄적인 양적 거래 시스템입니다. 이 전략은 EMA를 사용하여 RSI를 매끄럽게 하고, 주요 수준에서 RSI 돌파 신호를 통해 거래를 촉발하며, ATR을 사용하여 손절매 및 이익실현 수준을 동적으로 설정하여 효과적인 위험 관리를 달성합니다. 동시에 이 전략에는 거래 신호를 계산하고 기록하는 기능도 포함되어 있어, 거래자가 전략을 백테스트하고 최적화하는 데 도움이 됩니다.
전략의 핵심 논리는 다음과 같은 핵심 부분으로 구성됩니다.
이 전략은 RSI, EMA, ATR이라는 세 가지 고전적 기술 지표를 결합하여 완전한 정량적 거래 시스템을 구축합니다. 이 전략은 신호 생성, 위험 관리 및 거래 실행 측면에서 매우 실용적입니다. 지속적인 최적화와 개선을 통해 이 전략은 실제 거래에서 안정적인 성과를 달성할 것으로 기대됩니다. 그러나 사용자는 시장 환경이 전략 성과에 미치는 영향에 주의를 기울여야 하며, 매개변수를 합리적으로 설정하고 위험 관리를 잘 해야 합니다.
/*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=6
strategy("RSI Trading Strategy with EMA and ATR Stop Loss/Take Profit", overlay=true)
length = input.int(14, minval=1, title="RSI Length")
src = input(close, title="Source")
rsi = ta.rsi(src, length)
smoothingLength = input.int(14, minval=1, title="Smoothing Length")
smoothedRsi = ta.ema(rsi, smoothingLength) // استفاده از EMA برای صاف کردن RSI
atrLength = input.int(14, title="ATR Length")
atrMultiplier = input.float(1, title="ATR Multiplier")
atrValue = ta.atr(atrLength) // محاسبه ATR
level1 = 30
level2 = 70
// تنظیمات استراتژی
var table crossingTable = table.new(position.top_right, 2, 5, border_width=1)
var int crossCount = 0
var float crossPrice = na
// شرط ورود به معامله خرید زمانی که RSI از سطح 70 به بالا عبور میکند
if (ta.crossover(smoothedRsi, level2))
strategy.entry("Long", strategy.long)
// تنظیم حد سود و حد ضرر
strategy.exit("Take Profit/Stop Loss", "Long", stop=close - atrMultiplier * atrValue, limit=close + atrMultiplier * atrValue, comment="")
crossCount := crossCount + 1
crossPrice := close
// شرط ورود به معامله فروش زمانی که RSI از سطح 70 به پایین عبور میکند
if (ta.crossunder(smoothedRsi, level2))
strategy.entry("Short", strategy.short)
// تنظیم حد سود و حد ضرر
strategy.exit("Take Profit/Stop Loss", "Short", stop=close + atrMultiplier * atrValue, limit=close - atrMultiplier * atrValue, comment="")
crossCount := crossCount + 1
crossPrice := close
// شرط ورود به معامله خرید زمانی که RSI از سطح 30 به بالا عبور میکند
if (ta.crossover(smoothedRsi, level1))
strategy.entry("Long", strategy.long)
// تنظیم حد سود و حد ضرر
strategy.exit("Take Profit/Stop Loss", "Long", stop=close - atrMultiplier * atrValue, limit=close + atrMultiplier * atrValue, comment="")
crossCount := crossCount + 1
crossPrice := close
// شرط ورود به معامله فروش زمانی که RSI از سطح 30 به پایین عبور میکند
if (ta.crossunder(smoothedRsi, level1))
strategy.entry("Short", strategy.short)
// تنظیم حد سود و حد ضرر
strategy.exit("Take Profit/Stop Loss", "Short", stop=close + atrMultiplier * atrValue, limit=close - atrMultiplier * atrValue, comment="")
crossCount := crossCount + 1
crossPrice := close
if (not na(crossPrice))
table.cell(crossingTable, 0, crossCount % 5, text=str.tostring(crossCount), bgcolor=color.green)
table.cell(crossingTable, 1, crossCount % 5, text=str.tostring(crossPrice), bgcolor=color.green)
// ترسیم خطوط و مقادیر RSI
plot(smoothedRsi, title="Smoothed RSI", color=color.blue)
hline(level1, "Level 30", color=color.red)
hline(level2, "Level 70", color=color.green)