
Bei dieser Strategie handelt es sich um ein quantitatives Handelssystem auf Grundlage technischer Analysen, das hauptsächlich durch die Identifizierung von Dreifachbodenmustern und Momentum-Durchbruchsignalen auf dem Markt handelt. Die Strategie kombiniert mehrere technische Indikatoren wie den gleitenden Durchschnitt (MA), den Crossover, den wahren Bereich (ATR), den Preiskanal usw., um ein vollständiges Handelssystem aufzubauen. Diese Strategie realisiert die automatische Identifizierung und Transaktionsausführung des Triple-Bottoming-Rebound-Musters auf programmierte Weise.
Die Kernlogik der Strategie umfasst die folgenden Schlüsselelemente:
Diese Strategie implementiert die Triple-Bottoming-Rebound-Durchbruch-Handelsstrategie auf programmatische Weise, kombiniert mehrere technische Indikatoren und Methoden des Risikomanagements und weist eine gute Praktikabilität auf. Durch kontinuierliche Optimierung und Verbesserung soll diese Strategie im tatsächlichen Handel eine bessere Performance erzielen. Es wird empfohlen, vor dem eigentlichen Handel ausreichende Backtesting-Überprüfungen durchzuführen und die Parametereinstellungen entsprechend den spezifischen Marktbedingungen anzupassen.
/*backtest
start: 2019-12-23 08:00:00
end: 2025-01-08 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT","balance":49999}]
*/
//@version=5
strategy("反彈三次突破策略", overlay=true, initial_capital=100000, commission_value=0.001425, slippage=1)
// === 參數設定 ===
fast_length = input.int(5, title="快速均線週期")
slow_length = input.int(20, title="慢速均線週期")
atr_period = input.int(14, title="ATR 週期")
atr_factor = input.float(2.0, title="ATR 因子")
profit_factor = input.float(2.0, title="止盈因子")
// === 計算均線 ===
fast_ma = ta.ema(close, fast_length)
slow_ma = ta.ema(close, slow_length)
// === 均線交叉訊號 ===
long_signal = ta.crossover(fast_ma, slow_ma)
short_signal = ta.crossunder(fast_ma, slow_ma)
// === 計算 ATR ===
atr = ta.atr(atr_period)
// === 反彈三次突破策略 ===
var float low1 = na
var float low2 = na
var float low3 = na
var bool trend_down = false
var bool long_breakout = false
var line lower_line = na
var line upper_line = na
if (na(low1) or na(low2) or na(low3))
// 初始化低點
low1 := na
low2 := na
low3 := na
if (close < low3 or na(low3))
// 更新低點
low1 := low2
low2 := low3
low3 := close
trend_down := true
if (trend_down and close > low2 and close > low1)
// 確認反轉且第三次反彈比第二次高
trend_down := false
long_breakout := true
// 清除前一個反彈通道
if (not na(lower_line))
line.delete(lower_line)
if (not na(upper_line))
line.delete(upper_line)
// 繪製新的反彈通道
if (not na(low1) and not na(low3))
lower_line := line.new(x1=bar_index[2], y1=low1, x2=bar_index, y2=low3, color=color.yellow, width=2)
upper_line := line.new(x1=bar_index[2], y1=low1 + (low3 - low1), x2=bar_index, y2=low3 + (low3 - low1), color=color.yellow, width=2)
// === 進出場條件 ===
var float last_long_exit = na
var float last_short_exit = na
var float stop_loss_long = na
var float take_profit_long = na
var float stop_loss_short = na
var float take_profit_short = na
var label stop_loss_label_long = na
var label take_profit_label_long = na
var label stop_loss_label_short = na
var label take_profit_label_short = na
if (long_signal or long_breakout)
if na(last_short_exit) or (time - last_short_exit) > 2 * 60 * 60 * 1000 // 確保多頭出場後有一段時間間隔
// 做多
strategy.entry("做多", strategy.long)
// 止損設置為最近低點下方
stop_loss_long := low3 - atr_factor * atr
take_profit_long := close + profit_factor * atr // 設定止盈位置
strategy.exit("止盈/止損", "做多", stop=stop_loss_long, limit=take_profit_long)
last_long_exit := time // 記錄多頭出場時間
// 刪除之前的止盈止損標籤
if (not na(stop_loss_label_long))
label.delete(stop_loss_label_long)
if (not na(take_profit_label_long))
label.delete(take_profit_label_long)
// 繪製新的止盈止損標籤
stop_loss_label_long := label.new(x=bar_index, y=stop_loss_long, text=str.tostring(math.round(stop_loss_long * 10) / 10), color=color.red, style=label.style_label_down, textcolor=color.white, size=size.small)
take_profit_label_long := label.new(x=bar_index, y=take_profit_long, text=str.tostring(math.round(take_profit_long * 10) / 10), color=color.green, style=label.style_label_up, textcolor=color.white, size=size.small)
if (short_signal)
if na(last_long_exit) or (time - last_long_exit) > 2 * 60 * 60 * 1000 // 確保空頭出場後有一段時間間隔
// 做空
strategy.entry("做空", strategy.short)
// 止損設置為最近高點上方
stop_loss_short := high + atr_factor * atr
take_profit_short := close - profit_factor * atr // 設定止盈位置
strategy.exit("止盈/止損", "做空", stop=stop_loss_short, limit=take_profit_short)
last_short_exit := time // 記錄空頭出場時間
// 刪除之前的止盈止損標籤
if (not na(stop_loss_label_short))
label.delete(stop_loss_label_short)
if (not na(take_profit_label_short))
label.delete(take_profit_label_short)
// 繪製新的止盈止損標籤
stop_loss_label_short := label.new(x=bar_index, y=stop_loss_short, text=str.tostring(math.round(stop_loss_short * 10) / 10), color=color.red, style=label.style_label_down, textcolor=color.white, size=size.small)
take_profit_label_short := label.new(x=bar_index, y=take_profit_short, text=str.tostring(math.round(take_profit_short * 10) / 10), color=color.green, style=label.style_label_up, textcolor=color.white, size=size.small)