
Chiến lược này là một hệ thống giao dịch định lượng dựa trên nhiều chỉ số kỹ thuật, trung tâm được điều khiển bởi các chỉ số SuperTrend, kết hợp với cơ chế dừng lỗ động ATR, xác nhận xu hướng đa chiều và kiểm soát rủi ro thông qua các chỉ số như MACD, ADX, RSI. Chiến lược sử dụng cơ chế lọc sáu để xác định cơ hội giao dịch có khả năng cao, đồng thời giới thiệu ba lần phát hiện ngược để cảnh báo trước rủi ro thị trường.
Chiến lược này lấy chỉ số SuperTrend làm trung tâm, tính toán hướng xu hướng động thông qua factor và tham số ATR. Các tín hiệu đầu vào phải đáp ứng các điều kiện sau:
Hệ thống kiểm soát rủi ro bằng cách dừng động ATR và quản lý vị trí kết hợp với tín hiệu đảo ngược xu hướng.
Chiến lược này xây dựng một hệ thống giao dịch định lượng vững chắc bằng cách kết hợp các chỉ số đa chiều và kiểm soát rủi ro nghiêm ngặt. Thiết kế mô đun của hệ thống dễ dàng tối ưu hóa và mở rộng sau đó, nhưng trong ứng dụng thực tế cần chú ý đến điều chỉnh tham số và thích ứng với thị trường.
/*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