这是一个结合了指数移动平均线(EMA)交叉和平均真实波幅(ATR)过滤器的量化交易策略。该策略通过识别强势趋势并在波动率较高的市场环境下进行交易,有效地提高了策略的夏普比率和整体表现。策略采用50周期和200周期的EMA来捕捉中长期趋势,同时使用ATR指标来评估市场波动性,只有在波动率超过特定阈值时才进行交易。
策略的核心逻辑包含两个主要部分:趋势判断和波动率过滤。在趋势判断方面,策略使用50周期EMA作为快线,200周期EMA作为慢线,当快线上穿慢线时产生做多信号,下穿时产生做空信号。在波动率过滤方面,策略计算14周期的ATR值并将其转换为价格的百分比,只有当ATR百分比超过预设阈值(默认为2%)时才允许开仓。这种设计确保了策略只在具有足够波动性的市场环境下交易,有效降低了在震荡市场中的虚假信号。
这是一个将经典技术指标与现代风险管理理念相结合的策略。通过EMA交叉捕捉趋势,同时使用ATR过滤器来控制交易时机,策略在保持简单性的同时也具备了较强的实用性。虽然存在一些固有的风险,但通过合理的优化和风险管理措施,该策略仍然具有较好的应用价值。建议交易者在实际应用中根据具体市场特点和自身风险偏好进行适当的参数调整。
/*backtest
start: 2019-12-23 08:00:00
end: 2024-11-27 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("EMA Crossover with ATR Filter", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10)
// Inputs for Moving Averages
fastLength = input.int(50, title="Fast EMA Length")
slowLength = input.int(200, title="Slow EMA Length")
// Inputs for ATR Filter
atrLength = input.int(14, title="ATR Length")
atrMultiplier = input.float(1.5, title="ATR Multiplier")
atrThreshold = input.float(0.02, title="ATR Threshold (%)")
// Calculate EMAs
fastEMA = ta.ema(close, fastLength)
slowEMA = ta.ema(close, slowLength)
// Calculate ATR
atr = ta.atr(atrLength)
// Convert ATR to a percentage of price
atrPct = atr / close
// Define Long Condition (Cross and ATR filter)
longCondition = ta.crossover(fastEMA, slowEMA) and atrPct > atrThreshold / 100
// Define Short Condition
shortCondition = ta.crossunder(fastEMA, slowEMA) and atrPct > atrThreshold / 100
// Define Exit Conditions
exitConditionLong = ta.crossunder(fastEMA, slowEMA)
exitConditionShort = ta.crossover(fastEMA, slowEMA)
// Long Entry
if (longCondition)
strategy.entry("Long", strategy.long)
// Short Entry
if (shortCondition)
strategy.entry("Short", strategy.short)
// Long Exit
if (exitConditionLong)
strategy.close("Long")
// Short Exit
if (exitConditionShort)
strategy.close("Short")
// Plot EMAs for visual reference
plot(fastEMA, title="50 EMA", color=color.blue)
plot(slowEMA, title="200 EMA", color=color.red)
// Plot ATR for reference
plot(atrPct, title="ATR Percentage", color=color.orange, style=plot.style_line)
hline(atrThreshold / 100, "ATR Threshold", color=color.green)