该策略利用快速EMA均线(9周期)和慢速EMA均线(21周期)的交叉作为入场信号,并结合移动止损来锁定利润,避免回撤过大。
当快速EMA线从下方向上突破慢速EMA线时,生成买入信号;当快速EMA线从上方向下跌破慢速EMA线时,生成卖出信号。
一旦入场,策略会实时跟踪最高价,并在当前价格低于最高价2%时触发移动止损,将利润锁定。
风险解决方法:
该策略整合了趋势判断与止损管理的优点,既可以顺势而为,也可以有效控制风险。通过参数调整和优化,可以适用于不同类型的市场和交易品种,值得进一步测试实践。
/*backtest
start: 2023-12-12 00:00:00
end: 2023-12-19 00:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
strategy("EMA Crossover with Trailing Stop-Loss", overlay=true)
fastEMA = ema(close, 9)
slowEMA = ema(close, 21)
// Entry conditions
longCondition = crossover(fastEMA, slowEMA)
shortCondition = crossunder(fastEMA, slowEMA)
// Trailing stop-loss calculation
var float trailingStop = na
var float highestHigh = na
if (longCondition)
highestHigh := na
trailingStop := na
if (longCondition and high > highestHigh)
highestHigh := high
if (strategy.position_size > 0)
trailingStop := highestHigh * (1 - 0.02) // Adjust the trailing percentage as needed
// Execute trades
strategy.entry("Long", strategy.long, when=longCondition)
strategy.entry("Short", strategy.short, when=shortCondition)
// Apply trailing stop-loss to long positions
strategy.exit("Long", from_entry="Long", loss=trailingStop)
// Plot EMAs and Trailing Stop-Loss
plot(fastEMA, color=color.green, title="Fast EMA")
plot(slowEMA, color=color.red, title="Slow EMA")
plot(trailingStop, color=color.orange, title="Trailing Stop-Loss", linewidth=2)