本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("JZ Breakout Volume", shorttitle="JZ Volume", overlay=true)
// ─────────────────────────────────────────────────────────────
// INPUTS
// ─────────────────────────────────────────────────────────────
// Relative Volume
volLookback = input.int(20, "Volume Average Lookback", minval=5, group="Relative Volume")
elevatedRvol = input.float(1.5, "Elevated Volume (x)", step=0.1, group="Relative Volume")
strongRvol = input.float(2.0, "Strong Volume (x)", step=0.1, group="Relative Volume")
extremeRvol = input.float(3.0, "Extreme Volume (x)", step=0.1, group="Relative Volume")
// Price Expansion
atrLength = input.int(14, "ATR Length", minval=1, group="Price Expansion")
atrThreshold = input.float(1.25, "Expansion Threshold (x ATR)", step=0.05, group="Price Expansion")
// Display
colorElevated = input.bool(true, "Colour Elevated Volume Candles", group="Display")
colorStrong = input.bool(true, "Colour Strong Volume Candles", group="Display")
colorExpansion = input.bool(true, "Highlight Volume + Price Expansion", group="Display")
colorExtreme = input.bool(true, "Highlight Extreme Volume", group="Display")
// ─────────────────────────────────────────────────────────────
// CALCULATIONS
// ─────────────────────────────────────────────────────────────
// Average volume from PREVIOUS completed candles.
// Current candle is deliberately excluded.
avgVolume = ta.sma(volume[1], volLookback)
// Relative Volume
rvol = avgVolume > 0 ? volume / avgVolume : na
// ATR
atr = ta.atr(atrLength)
// True Range of current candle
trueRange = ta.tr(true)
// Range relative to ATR
rangeExpansion = atr > 0 ? trueRange / atr : na
// Direction
bullish = close > open
bearish = close < open
// ─────────────────────────────────────────────────────────────
// CONDITIONS
// ─────────────────────────────────────────────────────────────
elevatedVolume = rvol >= elevatedRvol
strongVolume = rvol >= strongRvol
extremeVolume = rvol >= extremeRvol
// The key breakout condition:
// Strong relative volume AND meaningful price expansion
breakoutExpansion = strongVolume and rangeExpansion >= atrThreshold
// ─────────────────────────────────────────────────────────────
// COLOURS
// ─────────────────────────────────────────────────────────────
// Default = don't override normal candle colour
color candleColor = na
// Elevated volume
if colorElevated and elevatedVolume
candleColor := bullish ? color.new(color.lime, 55) : color.new(color.red, 55)
// Strong volume
if colorStrong and strongVolume
candleColor := bullish ? color.new(color.lime, 25) : color.new(color.red, 25)
// Strong volume + range expansion
if colorExpansion and breakoutExpansion
candleColor := bullish ? color.lime : color.red
// Extreme volume gets its own colour.
// Purple highlights potential climax / exceptionally abnormal activity.
if colorExtreme and extremeVolume
candleColor := color.purple
barcolor(candleColor)
// ─────────────────────────────────────────────────────────────
// OPTIONAL DATA WINDOW VALUES
// These don't clutter the chart but let you inspect values.
// ─────────────────────────────────────────────────────────────
plot(rvol, "Relative Volume", display=display.data_window)
plot(rangeExpansion, "Range / ATR", display=display.data_window)
// ─────────────────────────────────────────────────────────────
// ALERTS
// ─────────────────────────────────────────────────────────────
alertcondition(
breakoutExpansion and bullish,
title="Bullish High Volume Expansion",
message="Bullish breakout-style candle: strong relative volume + price expansion."
)
alertcondition(
breakoutExpansion and bearish,
title="Bearish High Volume Expansion",
message="Bearish breakout-style candle: strong relative volume + price expansion."
)
alertcondition(
extremeVolume,
title="Extreme Relative Volume",
message="Extreme relative volume detected."
)