
Esta estrategia es un sistema de trading avanzado que combina el oscilador WaveTrend con bandas de media móvil EMA. Al integrar estos dos indicadores técnicos, se forma una estrategia comercial que puede capturar con precisión los puntos de inflexión en las tendencias del mercado. La estrategia adopta configuraciones dinámicas de stop-profit y stop-loss, buscando mayores retornos mientras se protege la seguridad del capital.
El núcleo de la estrategia es identificar señales comerciales a través de la coordinación del indicador WaveTrend y los ocho promedios móviles EMA. El indicador WaveTrend mide el estado de sobrecompra o sobreventa del mercado calculando la desviación entre el precio y la media móvil. La banda de media móvil EMA confirma la dirección de la tendencia al cruzar medias móviles de diferentes períodos. Específicamente:
Este es un sistema de trading completo que combina el seguimiento de tendencias y los osciladores del análisis técnico. Al utilizar las bandas de promedio móvil WaveTrend y EMA en combinación, no solo puede comprender la tendencia general, sino también ingresar al mercado a tiempo en el punto de inflexión de la tendencia. El mecanismo dinámico de gestión de stop-profit y stop-loss proporciona a la estrategia buenas capacidades de control de riesgos. El espacio de optimización de la estrategia radica principalmente en la mejora del filtrado de señales y la gestión de riesgos.
/*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="空头止盈线")