该策略是一个结合了Supertrend趋势指标和RSI(相对强弱指标)的交易系统。策略通过将趋势跟踪与动量指标相结合,在市场趋势明确且具有良好动量的情况下进行交易。系统使用ATR(平均真实波幅)来计算动态的支撑和阻力水平,并结合RSI超买超卖信号来确定入场时机。
策略的核心逻辑基于以下几个关键要素: 1. Supertrend指标的计算基于ATR和SMA,用于确定当前市场趋势。上轨通过将因子乘以ATR后加到SMA上得出,下轨则是从SMA中减去相同的值。 2. 当价格高于Supertrend线时产生买入信号,低于时产生卖出信号。 3. RSI指标用于确认市场动量,通过设定超买超卖水平(默认70和30)来过滤交易信号。 4. 做多条件要求Supertrend显示买入信号且RSI从超卖区域向上突破。 5. 做空条件需要Supertrend显示卖出信号且RSI从超买区域向下突破。 6. 止损设置在Supertrend线位置,止盈设为2倍ATR距离。
该策略通过结合Supertrend和RSI指标,构建了一个完整的趋势跟踪交易系统。策略在趋势明确的市场中表现较好,通过动态止损和合理的止盈设置来控制风险。虽然存在一些局限性,但通过提议的优化方向可以进一步提升策略的稳定性和适应性。策略适合追踪中长期趋势,并在保持一定盈利能力的同时较好地控制了风险。
/*backtest
start: 2024-04-11 00:00:00
end: 2025-02-19 08:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Binance","currency":"ETH_USDT"}]
*/
//@version=5
strategy("Supertrend + RSI Strategy", overlay=true)
// Input Parameters
atrLength = input.int(10, title="ATR Length", minval=1)
factor = input.float(3.0, title="Supertrend Factor", step=0.1)
rsiLength = input.int(14, title="RSI Length", minval=1)
rsiOverbought = input.int(70, title="RSI Overbought Level")
rsiOversold = input.int(30, title="RSI Oversold Level")
// Supertrend Calculation
atr = ta.atr(atrLength)
upperBand = ta.sma(close, atrLength) + (factor * atr)
lowerBand = ta.sma(close, atrLength) - (factor * atr)
supertrend = 0.0
supertrend := close > nz(supertrend[1], close) ? lowerBand : upperBand
supertrendSignal = close > supertrend ? "Buy" : "Sell"
// RSI Calculation
rsi = ta.rsi(close, rsiLength)
// Trading Logic
longCondition = (supertrendSignal == "Buy") and (rsi > rsiOversold)
shortCondition = (supertrendSignal == "Sell") and (rsi < rsiOverbought)
// Entry and Exit Conditions
if longCondition
strategy.entry("Long", strategy.long)
if shortCondition
strategy.entry("Short", strategy.short)
// Plot Supertrend
plot(supertrend, title="Supertrend", color=color.new(color.blue, 0), linewidth=2, style=plot.style_line)
// Plot RSI Levels
hline(rsiOverbought, "Overbought", color=color.red)
hline(rsiOversold, "Oversold", color=color.green)
plot(rsi, title="RSI", color=color.orange, style=plot.style_stepline)
// Alerts
alertcondition(longCondition, title="Buy Alert", message="Supertrend + RSI Buy Signal")
alertcondition(shortCondition, title="Sell Alert", message="Supertrend + RSI Sell Signal")