
La stratégie est un système de trading d’indicateurs techniques multidimensionnels qui combine le canal Keltner, la forme de la ligne K et l’analyse des volumes de transactions. La stratégie est conçue pour améliorer la fiabilité des signaux de négociation en surveillant la rupture des prix sur le canal et en combinant la forme de la transaction et du graphe de coupe comme conditions de filtrage. Le système est conçu pour un mécanisme de gestion de fonds complet, y compris des paramètres de stop loss et de stop loss dynamiques basés sur ATR.
La stratégie est construite sur les éléments suivants:
La stratégie a pour avantage d’avoir des mécanismes de confirmation de signaux multiples et un système de gestion des risques bien développé, mais nécessite toujours des ajustements optimisés en fonction des caractéristiques spécifiques du marché. La mise en œuvre réussie de la stratégie nécessite une compréhension approfondie du rôle de chaque composant par le trader et une utilisation flexible dans les transactions réelles.
/*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="看跌吞没")