该策略是一个结合了多重技术指标的趋势跟踪动量交易系统。它主要通过200日移动平均线(MA200)判断大趋势方向,利用50日指数移动平均线(EMA50)识别回调机会,并结合相对强弱指标(RSI)和移动平均线趋同散度(MACD)的交叉信号来确定入场时机。策略还包含了风险控制机制,通过设定风险收益比和追踪止损来保护盈利。
策略的核心逻辑是通过多层过滤机制来提高交易的准确性。首先通过MA200确定市场主趋势,当价格位于MA200之上时判定为多头趋势,反之为空头趋势。在确定趋势方向后,策略寻找EMA50附近的回调机会,要求价格在最近5个周期内触及EMA50。同时,使用RSI指标进行动量确认,在多头趋势中要求RSI大于50,空头趋势中要求RSI小于50。最后,通过MACD金叉死叉作为具体的入场信号。出场方面,策略采用基于风险收益比的固定止损止盈,并可选择性地启用追踪止损功能。
该策略通过综合运用多个技术指标,构建了一个完整的趋势跟踪交易系统。策略的优势在于多重信号确认提高了交易的可靠性,而风险控制机制则为策略提供了良好的防护。尽管存在一些固有的风险,但通过建议的优化方向可以进一步提升策略的表现。总体而言,这是一个逻辑严谨、实用性强的量化交易策略。
/*backtest
start: 2024-02-21 00:00:00
end: 2024-08-10 00:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Binance","currency":"ETH_USDT"}]
*/
//@version=6
strategy("Trend-Following Momentum Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=2)
// PARAMETERS
lengthMA200 = input(200, title="200-day MA Length")
lengthEMA50 = input(50, title="50-day EMA Length")
rsiLength = input(14, title="RSI Length")
macdFastLength = input(12, title="MACD Fast Length")
macdSlowLength = input(26, title="MACD Slow Length")
macdSignalLength = input(9, title="MACD Signal Length")
riskRewardRatio = input(1.5, title="Risk-Reward Ratio")
useTrailingStop = input(true, title="Use Trailing Stop?")
trailingPercent = input(1.0, title="Trailing Stop (%)") / 100
// INDICATORS
ma200 = ta.sma(close, lengthMA200) // 200-day MA
ema50 = ta.ema(close, lengthEMA50) // 50-day EMA
rsi = ta.rsi(close, rsiLength) // RSI
[macdLine, signalLine, _] = ta.macd(close, macdFastLength, macdSlowLength, macdSignalLength)
// TREND CONDITIONS
bullishTrend = close > ma200
bearishTrend = close < ma200
// PULLBACK CONDITION
recentPullbackLong = ta.barssince(close < ema50) < 5 // Price touched EMA50 in last 5 bars
recentPullbackShort = ta.barssince(close > ema50) < 5 // Price touched EMA50 in last 5 bars
// ENTRY CONDITIONS
longEntry = bullishTrend and ta.crossover(macdLine, signalLine) and rsi > 50 and recentPullbackLong
shortEntry = bearishTrend and ta.crossunder(macdLine, signalLine) and rsi < 50 and recentPullbackShort
// EXECUTE TRADES
if longEntry
strategy.entry("Long", strategy.long)
strategy.exit("Long Exit", from_entry="Long", limit=close * (1 + riskRewardRatio), stop=close * (1 - (1 / (1 + riskRewardRatio))), trail_price=useTrailingStop ? close * (1 - trailingPercent) : na)
if shortEntry
strategy.entry("Short", strategy.short)
strategy.exit("Short Exit", from_entry="Short", limit=close * (1 - riskRewardRatio), stop=close * (1 + (1 / (1 + riskRewardRatio))), trail_price=useTrailingStop ? close * (1 + trailingPercent) : na)
// PLOT INDICATORS
plot(ma200, title="200-day MA", color=color.blue, linewidth=2)
plot(ema50, title="50-day EMA", color=color.orange, linewidth=2)