
This strategy is a quantitative trading system based on multiple technical indicators, primarily driven by the SuperTrend indicator, combined with ATR dynamic stop-loss mechanism, and utilizing MACD, ADX, RSI, and other indicators for multi-dimensional trend confirmation and risk control. The strategy employs a six-layer filtering mechanism to identify high-probability trading opportunities while incorporating triple divergence detection for early market risk warning.
The strategy uses SuperTrend indicator as its core, calculating trend direction through factor and ATR parameters. Entry signals must satisfy the following conditions: 1. SuperTrend direction indication 2. MACD histogram position verification 3. ADX trend strength confirmation 4. Candlestick pattern confirmation 5. Volume expansion verification 6. Triple divergence detection
The system implements ATR dynamic stop-loss for risk control and manages positions based on trend reversal signals.
This strategy constructs a robust quantitative trading system through multi-dimensional indicator fusion and strict risk control. The modular design facilitates subsequent optimization and expansion, but parameter tuning and market adaptability need attention in practical applications. Innovative designs such as triple divergence warning and Gas fee filtering further enhance the strategy’s practicality.
/*backtest
start: 2024-02-22 00:00:00
end: 2025-02-19 08:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Binance","currency":"ETH_USDT"}]
*/
//@version=6
strategy("ETH 超级趋势增强策略-精简版", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=100)
// —————————— 参数配置区 ——————————
// 超级趋势参数
atrPeriod = input.int(8, "ATR周期(8-10)", minval=8, maxval=10)
factor = input.float(3.5, "乘数(3.5-4)", minval=3.5, maxval=4, step=0.1)
// MACD参数
fastLength = input.int(10, "MACD快线周期")
slowLength = input.int(21, "MACD慢线周期")
signalLength = input.int(7, "信号线周期")
// ADX参数
adxLength = input.int(18, "ADX周期")
adxThreshold = input.int(28, "ADX趋势阈值")
// 成交量验证
volFilterRatio = input.float(1.8, "成交量放大倍数", step=0.1)
// ATR止损
atrStopMulti = input.float(2.2, "ATR止损乘数", step=0.1)
// —————————— 核心指标计算 ——————————
// 1. 超级趋势(修复索引使用)
[supertrend, direction] = ta.supertrend(factor, atrPeriod)
plot(supertrend, color=direction < 0 ? color.new(color.green, 0) : color.new(color.red, 0), linewidth=2)
// 2. MACD指标
[macdLine, signalLine, histLine] = ta.macd(close, fastLength, slowLength, signalLength)
macdCol = histLine > histLine[1] ? color.green : color.red
// 3. ADX趋势强度
[DIMinus, DIPlus, ADX] = ta.dmi(adxLength, adxLength)
// 4. 成交量验证
volMA = ta.sma(volume, 20)
volValid = volume > volMA * volFilterRatio
// 5. ATR动态止损
atrVal = ta.atr(14)
var float stopPrice = na
// —————————— 三重背离检测 ——————————
// RSI背离检测
rsiVal = ta.rsi(close, 14)
priceHigh = ta.highest(high, 5)
rsiHigh = ta.highest(rsiVal, 5)
divergenceRSI = high >= priceHigh[1] and rsiVal < rsiHigh[1]
// MACD柱状图背离
macdHigh = ta.highest(histLine, 5)
divergenceMACD = high >= priceHigh[1] and histLine < macdHigh[1]
// 成交量背离
volHigh = ta.highest(volume, 5)
divergenceVol = high >= priceHigh[1] and volume < volHigh[1]
tripleDivergence = divergenceRSI and divergenceMACD and divergenceVol
// —————————— 信号生成逻辑 ——————————
// 多头条件(6层过滤)
longCondition =
direction < 0 and // 超级趋势看涨
histLine > 0 and // MACD柱在零轴上方
ADX > adxThreshold and // 趋势强度达标
close > open and // 阳线确认
volValid and // 成交量验证
not tripleDivergence // 无三重顶背离
// 空头条件(精简条件)
shortCondition =
direction > 0 and // 超级趋势看跌
histLine < 0 and // MACD柱在零轴下方
ADX > adxThreshold and // 趋势强度达标
close < open and // 阴线确认
volValid and // 成交量验证
tripleDivergence // 出现三重顶背离
// —————————— 交易执行模块 ——————————
if (longCondition)
strategy.entry("Long", strategy.long)
stopPrice := close - atrVal * atrStopMulti
if (shortCondition)
strategy.entry("Short", strategy.short)
stopPrice := close + atrVal * atrStopMulti
// 动态止损触发
strategy.exit("Exit Long", "Long", stop=stopPrice)
strategy.exit("Exit Short", "Short", stop=stopPrice)
// 趋势反转离场
if (direction > 0 and strategy.position_size > 0)
strategy.close("Long")
if (direction < 0 and strategy.position_size < 0)
strategy.close("Short")
// —————————— 可视化提示 ——————————
plotshape(longCondition, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small, title="买入信号")
plotshape(shortCondition, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small, title="卖出信号")
plot(strategy.position_size != 0 ? stopPrice : na, color=color.orange, style=plot.style_linebr, linewidth=2, title="动态止损线")
// —————————— 预警系统 ——————————
alertcondition(tripleDivergence, title="三重顶背离预警", message="ETH出现三重顶背离!")
longCondition := longCondition