
La estrategia es un sistema de trading de indicadores tecnológicos multidimensional que combina el canal Keltner, la forma de la línea K y el análisis de volumen de transacciones. La estrategia mejora la fiabilidad de las señales de negociación mediante el monitoreo de las rupturas de precios en el canal y la combinación de la forma de la transacción y el grafo de la barra como condiciones de filtración. El sistema diseña un mecanismo de gestión de fondos completo, que incluye una configuración de stop loss y stop loss dinámica basada en el ATR.
La estrategia se basa en los siguientes componentes centrales:
La estrategia integra varias herramientas de análisis técnico para construir un sistema de negociación relativamente completo. Su ventaja radica en el mecanismo de confirmación de múltiples señales y un sistema de gestión de riesgos completo, pero aún así requiere ajustes optimizados según las características específicas del mercado. La aplicación exitosa de la estrategia requiere que el comerciante entienda en profundidad el papel de cada componente y que se mantenga flexible en su uso en operaciones reales.
/*backtest
start: 2024-06-01 00:00:00
end: 2024-12-01 00:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Binance","currency":"ETH_USDT"}]
*/
//@version=5
strategy("Keltner Channel Breakout with Candlestick Patterns (Manual) - Visualize False Breakouts with Chinese Labels", overlay=true)
// 输入参数
length = input.int(20, title="EMA 长度")
mult = input.float(1.5, title="ATR 乘数") // 让通道稍微紧一点,增加突破机会
atrLength = input.int(14, title="ATR 长度")
volLength = input.int(20, title="成交量长度")
stopLossMultiplier = input.float(1.5, title="止损ATR倍数")
takeProfitMultiplier = input.float(2.0, title="止盈ATR倍数")
// 计算 Keltner 通道
ema20 = ta.ema(close, length)
atr = ta.atr(atrLength)
upper = ema20 + mult * atr
lower = ema20 - mult * atr
// 绘制 Keltner 通道
plot(upper, color=color.green, linewidth=2, title="上轨")
plot(lower, color=color.red, linewidth=2, title="下轨")
plot(ema20, color=color.blue, linewidth=2, title="中轨 (EMA20)")
// 判断突破
breakout_up = close > upper
breakout_down = close < lower
// 成交量过滤:当前成交量是否高于过去 N 根 K 线的平均成交量
volume_above_avg = volume > ta.sma(volume, volLength)
// 手动判断 K线形态:看涨吞没和看跌吞没
bullish_engulfing = close > open and open[1] > close[1] and close > open[1] and open < close[1]
bearish_engulfing = close < open and open[1] < close[1] and close < open[1] and open > close[1]
// 只在突破上轨和下轨时应用 K线形态过滤
valid_breakout_up = breakout_up and volume_above_avg and bullish_engulfing
valid_breakout_down = breakout_down and volume_above_avg and bearish_engulfing
// 交易信号
long_condition = valid_breakout_up
short_condition = valid_breakout_down
// 交易策略
if (long_condition)
strategy.entry("Long", strategy.long, comment="做多")
if (short_condition)
strategy.entry("Short", strategy.short, comment="做空")
// 止损 & 止盈
long_stop_loss = close - stopLossMultiplier * atr
long_take_profit = close + takeProfitMultiplier * atr
short_stop_loss = close + stopLossMultiplier * atr
short_take_profit = close - takeProfitMultiplier * atr
strategy.exit("Exit Long", from_entry="Long", stop=long_stop_loss, limit=long_take_profit)
strategy.exit("Exit Short", from_entry="Short", stop=short_stop_loss, limit=short_take_profit)
// 可视化假突破事件
plotshape(series=breakout_up and not bullish_engulfing, location=location.abovebar, color=color.red, style=shape.triangledown, title="假突破-上")
plotshape(series=breakout_down and not bearish_engulfing, location=location.belowbar, color=color.green, style=shape.triangleup, title="假突破-下")
// 可视化 K线形态(中文标签)
plotshape(series=bullish_engulfing and breakout_up, location=location.belowbar, color=color.green, style=shape.labelup, title="看涨吞没", text="看涨吞没")
plotshape(series=bearish_engulfing and breakout_down, location=location.abovebar, color=color.red, style=shape.labeldown, title="看跌吞没", text="看跌吞没")