该策略是一种基于移动平均线交叉和动态ATR止盈止损的量化交易策略。该策略使用两条不同周期的简单移动平均线(SMA)来生成交易信号,同时采用平均真实波动幅度(ATR)来动态设置止盈和止损位,以更好地控制风险。此外,该策略还根据不同的交易时段来过滤交易信号,以提高策略的稳健性。
该策略的核心原理是利用移动平均线的交叉来捕捉价格趋势的变化。当快速移动平均线从下向上穿越慢速移动平均线时,生成买入信号;当快速移动平均线从上向下穿越慢速移动平均线时,生成卖出信号。同时,该策略使用ATR来动态设置止盈和止损位,止盈位设置为入场价格加上3倍的ATR,止损位设置为入场价格减去1.5倍的ATR。此外,该策略只在欧洲交易时段生成交易信号,以避免在流动性较差的时段交易。
该策略是一种简单易懂的趋势追踪策略,通过移动平均线交叉来捕捉价格趋势,同时使用ATR来控制风险。尽管该策略存在一定的风险,但通过参数优化、信号过滤、风险管理等方面的优化,可以进一步提高策略的稳健性和盈利能力。对于初学者来说,该策略是一个很好的学习和实践案例。
/*backtest start: 2024-04-01 00:00:00 end: 2024-04-30 23:59:59 period: 2h basePeriod: 15m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy("Enhanced Moving Average Crossover Strategy", overlay=true) // Input parameters fastLength = input(10, title="Fast MA Length") slowLength = input(50, title="Slow MA Length") atrLength = input(14, title="ATR Length") riskPerTrade = input(1, title="Risk Per Trade (%)") / 100 // Time-based conditions isLondonSession = hour >= 8 and hour <= 15 isAsianSession = hour >= 0 and hour <= 7 isEuropeanSession = hour >= 7 and hour <= 14 // Moving Averages fastMA = ta.sma(close, fastLength) slowMA = ta.sma(close, slowLength) // Average True Range (ATR) for dynamic stop loss and take profit atr = ta.atr(atrLength) // Buy and Sell Conditions buySignal = ta.crossover(fastMA, slowMA) sellSignal = ta.crossunder(fastMA, slowMA) // Dynamic stop loss and take profit stopLoss = close - atr * 1.5 takeProfit = close + atr * 3 // Strategy Logic if (buySignal and isEuropeanSession) strategy.entry("Buy", strategy.long) strategy.exit("Take Profit/Stop Loss", "Buy", limit=takeProfit, stop=stopLoss) if (sellSignal and isEuropeanSession) strategy.entry("Sell", strategy.short) strategy.exit("Take Profit/Stop Loss", "Sell", limit=takeProfit, stop=stopLoss) // Plotting plot(fastMA, color=color.blue, title="Fast MA") plot(slowMA, color=color.red, title="Slow MA") plotshape(series=buySignal, location=location.belowbar, color=color.green, style=shape.labelup, text="BUY") plotshape(series=sellSignal, location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")