该策略是一个多指标综合交易系统,结合了指数移动平均线(EMA)、相对强弱指标(RSI)和平均真实波幅(ATR)等技术指标,并引入了平均趋向指数(ADX)来增强趋势判断的准确性。系统通过多重信号确认建仓时机,并利用ATR动态管理止损和止盈,实现风险的有效控制。
策略核心是通过多重技术指标的配合来捕捉市场趋势并进行交易。具体包括: 1. 使用快速(20周期)和慢速(50周期)EMA判断趋势方向 2. 结合ADX(14周期)确认趋势强度,要求ADX>20才确认趋势有效 3. 利用RSI(14周期)寻找超买超卖机会,RSI突破30触发买入,跌破70触发卖出 4. 采用ATR(14周期)计算动态止损和止盈位置,风险收益比设定为2:1
该策略通过多重技术指标的有机结合,构建了一个完整的趋势跟踪交易系统。策略在保证交易准确性的同时,通过严格的风险控制确保交易的安全性。虽然存在一定的优化空间,但整体框架具有良好的实用价值和扩展性。
/*backtest
start: 2025-01-20 00:00:00
end: 2025-01-31 00:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Binance","currency":"DOGE_USDT"}]
*/
//@version=5
strategy("Enhanced GBP/USD Strategy with ADX", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=1)
// === Input Parameters ===
emaFastLength = input.int(20, title="Fast EMA Length")
emaSlowLength = input.int(50, title="Slow EMA Length")
rsiLength = input.int(14, title="RSI Length")
rsiOverbought = input.int(70, title="RSI Overbought")
rsiOversold = input.int(30, title="RSI Oversold")
atrLength = input.int(14, title="ATR Length")
adxLength = input.int(14, title="ADX Length")
riskToReward = input.float(2.0, title="Risk-Reward Ratio (R:R)")
slMultiplier = input.float(1.5, title="SL Multiplier (ATR)")
// === Indicator Calculations ===
emaFast = ta.ema(close, emaFastLength)
emaSlow = ta.ema(close, emaSlowLength)
rsi = ta.rsi(close, rsiLength)
atr = ta.atr(atrLength)
// === ADX Calculation ===
// Components of ADX
tr = ta.rma(ta.tr, adxLength) // True Range smoothed
plusDM = ta.rma(math.max(high - high[1], 0), adxLength) // +DM
minusDM = ta.rma(math.max(low[1] - low, 0), adxLength) // -DM
plusDI = (plusDM / tr) * 100
minusDI = (minusDM / tr) * 100
dx = math.abs(plusDI - minusDI) / (plusDI + minusDI) * 100
adx = ta.rma(dx, adxLength) // Final ADX value
// === Entry Conditions ===
isUptrend = emaFast > emaSlow and adx > 20
isDowntrend = emaFast < emaSlow and adx > 20
buySignal = isUptrend and ta.crossover(rsi, rsiOversold)
sellSignal = isDowntrend and ta.crossunder(rsi, rsiOverbought)
// === Stop-Loss and Take-Profit ===
slDistance = atr * slMultiplier
tpDistance = slDistance * riskToReward
buySL = buySignal ? close - slDistance : na
buyTP = buySignal ? close + tpDistance : na
sellSL = sellSignal ? close + slDistance : na
sellTP = sellSignal ? close - tpDistance : na
// === Execute Trades ===
if buySignal
strategy.entry("Buy", strategy.long)
strategy.exit("Buy TP/SL", from_entry="Buy", stop=buySL, limit=buyTP)
if sellSignal
strategy.entry("Sell", strategy.short)
strategy.exit("Sell TP/SL", from_entry="Sell", stop=sellSL, limit=sellTP)
// === Plotting ===
plot(emaFast, title="Fast EMA", color=color.blue)
plot(emaSlow, title="Slow EMA", color=color.orange)
plotshape(buySignal, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(sellSignal, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")
plot(buySL, title="Buy Stop Loss", color=color.red, linewidth=1)
plot(buyTP, title="Buy Take Profit", color=color.green, linewidth=1)
plot(sellSL, title="Sell Stop Loss", color=color.red, linewidth=1)
plot(sellTP, title="Sell Take Profit", color=color.green, linewidth=1)
// === Alerts ===
alertcondition(buySignal, title="Buy Alert", message="Buy Signal Detected!")
alertcondition(sellSignal, title="Sell Alert", message="Sell Signal Detected!")