本策略是一个结合了SuperTrend指标和随机指标(Stochastic Oscillator)的趋势跟踪交易系统。该策略通过SuperTrend指标识别市场趋势方向,同时利用随机指标的超买超卖信号作为交易的确认信号。策略采用动量交叉方法在趋势方向上寻找最佳入场和出场时机,实现趋势跟踪与动量分析的完美结合。
策略的核心逻辑基于两个主要指标的配合: 1. SuperTrend指标:基于ATR(平均真实波幅)计算,用于确定市场趋势。当指标线由红转绿时表示上升趋势,由绿转红时表示下降趋势。指标参数采用ATR周期为10,乘数因子为3.0。 2. 随机指标:用于识别市场的超买超卖状态。采用%K周期为14,%D周期为3的参数设置,超买水平为80,超卖水平为20。
交易规则如下: - 做多条件:SuperTrend显示上升趋势(绿色),且随机指标%K线从下向上穿越超卖水平(20) - 做空条件:SuperTrend显示下降趋势(红色),且随机指标%K线从上向下穿越超买水平(80) - 平多条件:SuperTrend转为下降趋势,或随机指标%K线向下穿越超买水平 - 平空条件:SuperTrend转为上升趋势,或随机指标%K线向上穿越超卖水平
该策略通过结合趋势跟踪和动量分析,构建了一个较为完整的交易系统。它不仅提供清晰的入场出场信号,还包含了风险管理和参数优化的框架。虽然存在一些固有风险,但通过提供的优化建议可以进一步提升策略的稳定性和适应性。适合那些希望在趋势市场中把握机会的交易者使用。
/*backtest
start: 2024-02-21 00:00:00
end: 2024-10-01 00:00:00
period: 2d
basePeriod: 2d
exchanges: [{"eid":"Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("SuperTrend + Stochastic Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10)
// SuperTrend Settings
superTrendFactor = input.float(3.0, title="SuperTrend Factor", step=0.1)
superTrendATRLength = input.int(10, title="SuperTrend ATR Length")
// Calculate SuperTrend
[superTrend, direction] = ta.supertrend(superTrendFactor, superTrendATRLength)
// Plot SuperTrend
plot(superTrend, color=direction == 1 ? color.green : color.red, title="SuperTrend")
bgcolor(direction == 1 ? color.new(color.green, 90) : color.new(color.red, 90), transp=90)
// Stochastic Settings
stochKLength = input.int(14, title="Stochastic %K Length")
stochDLength = input.int(3, title="Stochastic %D Length")
stochSmoothK = input.int(3, title="Stochastic %K Smoothing")
stochOverbought = input.int(80, title="Stochastic Overbought Level")
stochOversold = input.int(20, title="Stochastic Oversold Level")
// Calculate Stochastic
k = ta.sma(ta.stoch(close, high, low, stochKLength), stochSmoothK)
d = ta.sma(k, stochDLength)
// Plot Stochastic in separate pane
hline(stochOverbought, "Overbought", color=color.red)
hline(stochOversold, "Oversold", color=color.green)
plot(k, color=color.blue, title="%K", linewidth=2)
plot(d, color=color.orange, title="%D", linewidth=2)
// Long Condition: SuperTrend is up and Stochastic %K crosses above oversold
longCondition = direction == 1 and ta.crossover(k, stochOversold)
if (longCondition)
strategy.entry("Long", strategy.long)
// Short Condition: SuperTrend is down and Stochastic %K crosses below overbought
shortCondition = direction == -1 and ta.crossunder(k, stochOverbought)
if (shortCondition)
strategy.entry("Short", strategy.short)
// Exit Long: SuperTrend turns down or Stochastic %K crosses below overbought
exitLong = direction == -1 or ta.crossunder(k, stochOverbought)
if (exitLong)
strategy.close("Long")
// Exit Short: SuperTrend turns up or Stochastic %K crosses above oversold
exitShort = direction == 1 or ta.crossover(k, stochOversold)
if (exitShort)
strategy.close("Short")