本策略是一个基于多重指数移动平均线(EMA)交叉信号的交易系统,结合了不同周期的EMA指标和ATR动态止损机制。策略使用了10周期、39周期、73周期的EMA作为主要信号指标,同时引入了143周期的高时间周期EMA作为趋势过滤器,并通过ATR指标动态设置止损和获利目标。
策略的核心逻辑基于多重EMA的交叉信号和趋势确认。当短期EMA(10周期)向上穿越中期EMA(39周期),且价格位于长期EMA(73周期)和更高时间周期EMA(143周期)之上时,系统产生做多信号。相反,当短期EMA向下穿越中期EMA,且价格位于长期EMA和更高时间周期EMA之下时,系统产生做空信号。策略通过ATR的1倍作为止损距离,2倍作为获利目标,实现风险收益比为1:2的动态仓位管理。
该策略通过多重EMA交叉结合ATR动态止损,构建了一个兼具趋势跟踪和风险管理的交易系统。策略的主要优势在于多重时间周期的确认机制和动态的仓位管理,但也需要注意横盘市场和滞后性带来的风险。通过引入成交量确认、趋势强度过滤等优化手段,可以进一步提升策略的稳定性和收益能力。在实际应用中,建议根据不同市场环境和交易品种特性,对参数进行适当调整。
/*backtest
start: 2019-12-23 08:00:00
end: 2024-11-28 00:00:00
period: 2d
basePeriod: 2d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Enhanced EMA Crossover Strategy", overlay=true)
// Define the EMA lengths
ema_short_length = 10
ema_long_length = 39
ema_filter_length = 73
ema_higher_tf_length = 143
// Calculate the EMAs
ema_short = ta.ema(close, ema_short_length)
ema_long = ta.ema(close, ema_long_length)
ema_filter = ta.ema(close, ema_filter_length)
ema_higher_tf = request.security(syminfo.tickerid, "D", ta.ema(close, ema_higher_tf_length))
// Calculate ATR for volatility-based stop loss and take profit
atr_length = 14
atr = ta.atr(atr_length)
// Plot the EMAs
plot(ema_short, title="EMA 10", color=color.blue)
plot(ema_long, title="EMA 35", color=color.red)
plot(ema_filter, title="EMA 75", color=color.orange)
plot(ema_higher_tf, title="EMA Higher TF", color=color.purple)
// EMA crossover conditions with EMA 75 and higher timeframe EMA filter
longCondition = ta.crossover(ema_short, ema_long) and close > ema_filter and close > ema_higher_tf
shortCondition = ta.crossunder(ema_short, ema_long) and close < ema_filter and close < ema_higher_tf
// Execute long trade with dynamic stop loss and take profit
if (longCondition)
strategy.entry("Long", strategy.long)
strategy.exit("Take Profit/Stop Loss", "Long", limit=close + 2 * atr, stop=close - 1 * atr)
// Execute short trade with dynamic stop loss and take profit
if (shortCondition)
strategy.entry("Short", strategy.short)
strategy.exit("Take Profit/Stop Loss", "Short", limit=close - 2 * atr, stop=close + 1 * atr)
// Plot signals on the chart
plotshape(series=longCondition, location=location.belowbar, color=color.green, style=shape.labelup, title="Buy Signal", text="BUY")
plotshape(series=shortCondition, location=location.abovebar, color=color.red, style=shape.labeldown, title="Sell Signal", text="SELL")