该策略结合了支撑/阻力(S/R)突破/反转、成交量过滤和警报系统,旨在捕捉市场中的关键转折点。策略通过识别价格突破或反转信号,并结合异常成交量确认,以提高交易信号的可靠性。策略采用固定2%的止损和可调节的止盈比例(默认3%)来管理风险。
ta.pivothigh()
和ta.pivotlow()
函数在指定周期(pivotLen)内识别关键价格水平。当价格突破阻力位(上破1%)或从支撑位反弹(下探后收回)时触发信号。strategy.exit()
实现。该策略通过三重验证(价格位置、成交量、价格行为)设计了一个高概率交易框架,特别适合趋势初期的捕捉。核心优势在于逻辑透明、风险可控,但需注意其在震荡市中的局限性。未来优化可聚焦于参数自适应和趋势过滤,以进一步提升稳定性。
/*backtest
start: 2024-04-24 00:00:00
end: 2024-12-31 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"DOGE_USDT"}]
*/
//@version=5
strategy("S/R Breakout/Reversal + Volume + Alerts", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100)
// === INPUTS ===
pivotLen = input.int(10, "Pivot Lookback for S/R")
volSmaLength = input.int(20, "Volume SMA Length")
volMultiplier = input.float(1.5, "Volume Multiplier")
tpPerc = input.float(3.0, "Take Profit %", step=0.1)
slPerc = 2.0 // Stop Loss fixed at 2%
// === S/R ZONES ===
pivotHigh = ta.pivothigh(high, pivotLen, pivotLen)
pivotLow = ta.pivotlow(low, pivotLen, pivotLen)
var float resZone = na
var float supZone = na
if not na(pivotHigh)
resZone := pivotHigh
if not na(pivotLow)
supZone := pivotLow
plot(supZone, title="Support", color=color.green, linewidth=2, style=plot.style_linebr)
plot(resZone, title="Resistance", color=color.red, linewidth=2, style=plot.style_linebr)
// === VOLUME FILTER ===
volSma = ta.sma(volume, volSmaLength)
highVolume = volume > volSma * volMultiplier
// === LONG LOGIC ===
priceAboveRes = close > resZone * 1.01
nearSupport = close >= supZone * 0.99 and close <= supZone * 1.01
rejectSupport = low <= supZone and close > supZone
longBreakoutCond = priceAboveRes and highVolume
longReversalCond = nearSupport and rejectSupport and highVolume
longCondition = longBreakoutCond or longReversalCond
// === SHORT LOGIC ===
priceBelowSup = close < supZone * 0.99
nearResistance = close >= resZone * 0.99 and close <= resZone * 1.01
rejectResistance = high >= resZone and close < resZone
shortBreakoutCond = priceBelowSup and highVolume
shortReversalCond = nearResistance and rejectResistance and highVolume
shortCondition = shortBreakoutCond or shortReversalCond
// === ENTRIES WITH LABELS ===
if (longCondition)
strategy.entry("Long", strategy.long)
label.new(bar_index, low * 0.995, "BUY", style=label.style_label_up, color=color.green, textcolor=color.white)
if (shortCondition)
strategy.entry("Short", strategy.short)
label.new(bar_index, high * 1.005, "SELL", style=label.style_label_down, color=color.red, textcolor=color.white)
// === TP/SL ===
longTP = close * (1 + tpPerc / 100)
longSL = close * (1 - slPerc / 100)
shortTP = close * (1 - tpPerc / 100)
shortSL = close * (1 + slPerc / 100)
strategy.exit("Long TP/SL", from_entry="Long", limit=longTP, stop=longSL)
strategy.exit("Short TP/SL", from_entry="Short", limit=shortTP, stop=shortSL)
// === ALERT CONDITIONS ===
alertcondition(longCondition, title="Buy Alert", message="🔔 BUY signal: S/R + Volume breakout/reversal")
alertcondition(shortCondition, title="Sell Alert", message="🔔 SELL signal: S/R + Volume breakout/reversal")