
La stratégie est un système de trading quantitatif basé sur de multiples indicateurs techniques, dont le cœur est propulsé par les indicateurs SuperTrend, en combinaison avec le mécanisme d’arrêt de perte dynamique ATR, pour la confirmation de tendance multidimensionnelle et le contrôle du risque via des indicateurs tels que MACD, ADX, RSI. La stratégie utilise un mécanisme de filtrage à six pour identifier les opportunités de trading à haute probabilité, tout en introduisant une triple détection de revers pour alerter à l’avance les risques du marché.
La stratégie est centrée sur l’indicateur SuperTrend, qui calcule dynamiquement la direction de la tendance via le facteur et les paramètres ATR. Les signaux d’entrée doivent satisfaire aux conditions suivantes:
Le système contrôle le risque par l’arrêt dynamique de l’ATR et gère les positions en combinaison avec les signaux de renversement de tendance.
La stratégie construit un système de négociation quantifié robuste grâce à la fusion d’indicateurs multidimensionnels et à un contrôle strict des risques. La conception modulaire du système permet une optimisation et une expansion ultérieures, mais nécessite une attention particulière à l’ajustement des paramètres et à l’adaptation au marché dans les applications réelles. Des conceptions innovantes telles que le triple décalage de l’alerte précoce et le filtrage des frais de gaz améliorent encore la pratique de la stratégie.
/*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