
Chiến lược này là một hệ thống giao dịch tiên tiến kết hợp bộ dao động WaveTrend với các dải trung bình động EMA. Bằng cách tích hợp hai chỉ báo kỹ thuật này, một chiến lược giao dịch được hình thành có thể nắm bắt chính xác các điểm ngoặt trong xu hướng thị trường. Chiến lược này áp dụng các thiết lập dừng lợi nhuận và dừng lỗ linh hoạt, theo đuổi lợi nhuận cao hơn trong khi vẫn bảo vệ an ninh vốn.
Cốt lõi của chiến lược này là xác định tín hiệu giao dịch thông qua sự phối hợp của chỉ báo WaveTrend và tám đường trung bình động EMA. Chỉ báo WaveTrend đo trạng thái mua quá mức hoặc bán quá mức của thị trường bằng cách tính toán độ lệch giữa giá và đường trung bình động. Đường trung bình động EMA xác nhận hướng xu hướng bằng cách cắt đường trung bình động của các giai đoạn khác nhau. Cụ thể:
Đây là một hệ thống giao dịch hoàn chỉnh kết hợp giữa việc theo dõi xu hướng và các chỉ báo dao động từ phân tích kỹ thuật. Bằng cách sử dụng kết hợp các dải trung bình động WaveTrend và EMA, bạn không chỉ nắm bắt được xu hướng chung mà còn có thể tham gia thị trường kịp thời tại thời điểm chuyển hướng của xu hướng. Cơ chế quản lý dừng lỗ và dừng lãi năng động cung cấp cho chiến lược khả năng kiểm soát rủi ro tốt. Không gian tối ưu hóa của chiến lược chủ yếu nằm ở việc cải thiện khả năng lọc tín hiệu và quản lý rủi ro.
/*backtest
start: 2024-12-06 00:00:00
end: 2025-01-04 08:00:00
period: 2h
basePeriod: 2h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("VuManChu Cipher A Strategy", overlay=true, initial_capital=10000, default_qty_type=strategy.fixed, default_qty_value=1.0)
// === 函数定义 ===
// WaveTrend函数
f_wavetrend(_src, _chlen, _avg, _malen) =>
_esa = ta.ema(_src, _chlen)
_de = ta.ema(math.abs(_src - _esa), _chlen)
_ci = (_src - _esa) / (0.015 * _de)
_tci = ta.ema(_ci, _avg)
_wt1 = _tci
_wt2 = ta.sma(_wt1, _malen)
[_wt1, _wt2]
// EMA Ribbon函数
f_emaRibbon(_src, _e1, _e2, _e3, _e4, _e5, _e6, _e7, _e8) =>
_ema1 = ta.ema(_src, _e1)
_ema2 = ta.ema(_src, _e2)
_ema3 = ta.ema(_src, _e3)
_ema4 = ta.ema(_src, _e4)
_ema5 = ta.ema(_src, _e5)
_ema6 = ta.ema(_src, _e6)
_ema7 = ta.ema(_src, _e7)
_ema8 = ta.ema(_src, _e8)
[_ema1, _ema2, _ema3, _ema4, _ema5, _ema6, _ema7, _ema8]
// === 变量声明 ===
var float stopPrice = na // 止损价格变量
var float targetPrice = na // 止盈价格变量
var float lastLongPrice = na
var float lastShortPrice = na
var float highestSinceLastLong = na
var float lowestSinceLastShort = na
// === WaveTrend参数 ===
wtChannelLen = input.int(9, title = 'WT Channel Length')
wtAverageLen = input.int(13, title = 'WT Average Length')
wtMASource = hlc3
wtMALen = input.int(3, title = 'WT MA Length')
// === EMA Ribbon参数 ===
ema1Len = input.int(5, "EMA 1 Length")
ema2Len = input.int(11, "EMA 2 Length")
ema3Len = input.int(15, "EMA 3 Length")
ema4Len = input.int(18, "EMA 4 Length")
ema5Len = input.int(21, "EMA 5 Length")
ema6Len = input.int(24, "EMA 6 Length")
ema7Len = input.int(28, "EMA 7 Length")
ema8Len = input.int(34, "EMA 8 Length")
// === 计算指标 ===
// WaveTrend计算
[wt1, wt2] = f_wavetrend(wtMASource, wtChannelLen, wtAverageLen, wtMALen)
// WaveTrend交叉条件
wtCross = ta.cross(wt1, wt2)
wtCrossDown = wt2 - wt1 >= 0
// EMA Ribbon计算
[ema1, ema2, ema3, ema4, ema5, ema6, ema7, ema8] = f_emaRibbon(close, ema1Len, ema2Len, ema3Len, ema4Len, ema5Len, ema6Len, ema7Len, ema8Len)
// === 交易信号 ===
longEma = ta.crossover(ema2, ema8)
shortEma = ta.crossover(ema8, ema2)
redCross = ta.crossunder(ema1, ema2)
blueTriangle = ta.crossover(ema2, ema3)
redDiamond = wtCross and wtCrossDown
bloodDiamond = redDiamond and redCross
// 更新最高最低价
if not na(lastLongPrice)
highestSinceLastLong := math.max(high, nz(highestSinceLastLong))
if not na(lastShortPrice)
lowestSinceLastShort := math.min(low, nz(lowestSinceLastShort))
// === 交易信号条件 ===
longCondition = longEma or (blueTriangle and not bloodDiamond)
shortCondition = shortEma or bloodDiamond
// === 执行交易 ===
if (longCondition)
// 记录多头入场价格
lastLongPrice := close
// 重置最高价跟踪
highestSinceLastLong := high
stopPrice := nz(lowestSinceLastShort, close * 0.98) // 使用前一个空头信号后的最低价作为止损
float riskAmount = math.abs(close - stopPrice)
targetPrice := close + (riskAmount * 2) // 止盈为止损距离的2倍
strategy.entry("做多", strategy.long)
strategy.exit("多头止盈止损", "做多", limit=targetPrice, stop=stopPrice)
if (shortCondition)
// 记录空头入场价格
lastShortPrice := close
// 重置最低价跟踪
lowestSinceLastShort := low
stopPrice := nz(highestSinceLastLong, close * 1.02) // 使用前一个多头信号后的最高价作为止损
float riskAmount = math.abs(stopPrice - close)
targetPrice := close - (riskAmount * 3) // 止盈为止损距离的2倍
strategy.entry("做空", strategy.short)
strategy.exit("空头止盈止损", "做空", limit=targetPrice, stop=stopPrice)
// === 绘制信号 ===
plotshape(longCondition, style=shape.triangleup, color=color.green, location=location.belowbar, size=size.small, title="做多信号")
plotshape(shortCondition, style=shape.triangledown, color=color.red, location=location.abovebar, size=size.small, title="做空信号")
// 绘制止损线
plot(strategy.position_size > 0 ? stopPrice : na, color=color.red, style=plot.style_linebr, linewidth=2, title="多头止损线")
plot(strategy.position_size < 0 ? stopPrice : na, color=color.red, style=plot.style_linebr, linewidth=2, title="空头止损线")
// 绘制止盈线
plot(strategy.position_size > 0 ? targetPrice : na, color=color.green, style=plot.style_linebr, linewidth=2, title="多头止盈线")
plot(strategy.position_size < 0 ? targetPrice : na, color=color.green, style=plot.style_linebr, linewidth=2, title="空头止盈线")