MM Flow
FlowScripts

Perfected FlowScript

Volumetric Support and Resistance (Fork)

Volumetric S/R Fork V2 is indexed as 197_volumetric_support_and_resistance_fork.flowscript. The exact FlowScript is viewable here; chart observe and trading automation use the current mmflow chart/recipe signal proxy until FlowScript v2 transpilation is available.

This exact FlowScript uses the v2 source dialect. It is viewable and connected to the chart/automation proxy, but direct editor execution needs the FlowScript v2 transpiler.

Dialect

flowscript-v2

Compatibility

flowscript-v2-needs-transpile

Position

onchart

Axis

false

Size

24.3 KB

Lines

651

Native Signal Candidates

9 source-level chart marker triggers extracted from guarded FlowScript v2 blocks.

9/9 guarded

Volume Node

line 529:5

Trigger

(showZones && volNode)

Value

px

Deps

showZones:input, volNode:timeseries

Res Pivot

line 544:5

Trigger

(showPivots && newResEvent)

Value

hi[pivotLen]

Deps

newResEvent:var, showPivots:input

Sup Pivot

line 555:5

Trigger

(showPivots && newSupEvent)

Value

lo[pivotLen]

Deps

newSupEvent:var, showPivots:input

R1 Break

line 570:5

Trigger

(showBreaks && res1BreakEvent)

Value

px

Deps

res1BreakEvent:var, showBreaks:input

R2 Break

line 580:5

Trigger

(showBreaks && res2BreakEvent)

Value

px

Deps

res2BreakEvent:var, showBreaks:input

R3 Break

line 590:5

Trigger

(showBreaks && res3BreakEvent)

Value

px

Deps

res3BreakEvent:var, showBreaks:input

S1 Break

line 600:5

Trigger

(showBreaks && sup1BreakEvent)

Value

px

Deps

showBreaks:input, sup1BreakEvent:var

S2 Break

line 610:5

Trigger

(showBreaks && sup2BreakEvent)

Value

px

Deps

showBreaks:input, sup2BreakEvent:var

S3 Break

line 620:5

Trigger

(showBreaks && sup3BreakEvent)

Value

px

Deps

showBreaks:input, sup3BreakEvent:var

197_volumetric_support_and_resistance_fork.flowscript

source path: kscripts/perfected/197_volumetric_support_and_resistance_fork.flowscript · sha256:3cd61725946617bc50dddbd52097e7f7f8cc1fb2b4be1d2bc2d11980b25c26b6

hash verified
//@version=2

// ============================================================================
// Volumetric S/R Fork V2 — Dynamic S/R with POC, Value Area & Volume Nodes
// Author: M (@mourad1987) | Perfected: kScript_Perfection_Engineer
// Tags: SPECIALIZED, CORE, #support, #resistance, #volume, #pivot, #poc, #valuearea
//
// Dynamic support and resistance zones drawn from volume-confirmed pivot highs
// and lows, with ATR-based zone thickness, volume-weighted strength scoring,
// break detection with shape markers, POC tracking, and approximate Value Area
// bounds. Tracks up to 3 support and 3 resistance levels with state-machine
// persistence.
//
// Academic foundation:
//  1. Fazen Capital / TrueData (2026), "Volume Profile Trading: Identifying
//     Support & Resistance". HVN (high volume nodes) act as fair-value S/R;
//     volume validates the strength. POC = price with highest volume;
//     Value Area = ~70% of trading volume.
//
//  2. Kirkpatrick & Dahlquist (2010), "Technical Analysis: The Complete
//     Resource for Financial Market Technicians". Support/resistance levels
//     rated 4.41/5 among practitioners; volume confirmation improves reliability.
//
//  3. FasterCapital (2024), "Volume Speaks Volumes: Integrating Volume Profile
//     with Support and Resistance Analysis". HVN + historical S/R alignment
//     reinforces significance; ATR for break threshold.
//
//  4. Wilder (1978), "New Concepts in Technical Trading Systems". ATR =
//     SMA(TR, N) where TR = max(high−low, |high−close[1]|, |low−close[1]|).
//     Adaptive volatility bands are the canonical method for dynamic S/R.
//
//  5. Steidlmayer & Hawkins (2003), "Steidlmayer on Markets: Trading with
//     Market Profile" (2nd ed.). Value Area (~70%), POC, volume clusters
//     at accepted value, auction market theory.
//
//  6. Bhusal (2025), "Timing the Trap" (SSRN 5276088). Stop-hunt zones and
//     engineered liquidity traps around S/R levels; ATR-based invalidation
//     buffer prevents false breakouts.
//
//  7. arXiv:2103.12419 (2021), "Explainable ML-driven Strategy for Automated
//     Trading Pattern Extraction". Volume-based patterns outperform price-based
//     patterns in liquid markets; POC serves as classification target.
// ============================================================================

define(title="Volumetric S/R Fork V2", position="onchart", axis=false)

// ---------------------------------------------------------------------------
// 1. USER INPUTS
// ---------------------------------------------------------------------------

// -- Pivot Detection --
var pivotLen = input(name="pivotLen", type="number", defaultValue=5, label="Pivot Length (each side)", constraints={min: 2, max: 50, step: 1}, group="Pivot Detection")
var volLookback = input(name="volLookback", type="number", defaultValue=20, label="Volume Averaging Period", constraints={min: 5, max: 100, step: 1}, group="Pivot Detection")
var volMult = input(name="volMult", type="number", defaultValue=1.5, label="Volume Confirmation Multiplier", constraints={min: 1.0, max: 5.0, step: 0.1}, group="Pivot Detection")

// -- Zone Configuration --
var atrLen = input(name="atrLen", type="number", defaultValue=14, label="ATR Length", constraints={min: 5, max: 100, step: 1}, group="Zone Configuration")
var padMult = input(name="padMult", type="number", defaultValue=0.5, label="Zone Padding (ATR Multiple)", constraints={min: 0.0, max: 3.0, step: 0.1}, group="Zone Configuration")
var minDistPct = input(name="minDistPct", type="number", defaultValue=1.0, label="Min Distance Between Zones (%)", constraints={min: 0.1, max: 10.0, step: 0.1}, group="Zone Configuration")
var breakMult = input(name="breakMult", type="number", defaultValue=1.0, label="Break Confirmation Volume Multiplier", constraints={min: 0.5, max: 3.0, step: 0.1}, group="Zone Configuration")
var maxAgeBars = input(name="maxAgeBars", type="number", defaultValue=100, label="Max Level Age (bars)", constraints={min: 20, max: 500, step: 10}, group="Zone Configuration")

// -- POC & Value Area --
var pocWindow = input(name="pocWindow", type="number", defaultValue=100, label="POC / Value Area Lookback", constraints={min: 20, max: 500, step: 10}, group="POC & Value Area")
var vaBandMult = input(name="vaBandMult", type="number", defaultValue=1.0, label="Value Area Band (ATR multiplier)", constraints={min: 0.5, max: 3.0, step: 0.5}, group="POC & Value Area")

// -- Display --
var showZones = input(name="showZones", type="boolean", defaultValue=true, label="Show S/R Zones", group="Display")
var showPivots = input(name="showPivots", type="boolean", defaultValue=true, label="Show Pivot Markers", group="Display")
var showBreaks = input(name="showBreaks", type="boolean", defaultValue=true, label="Show Break Markers", group="Display")
var showPOC = input(name="showPOC", type="boolean", defaultValue=true, label="Show POC", group="Display")
var showValueArea = input(name="showValueArea", type="boolean", defaultValue=true, label="Show Value Area", group="Display")
var showStrength = input(name="showStrength", type="boolean", defaultValue=true, label="Show Strength Score", group="Display")
var showLabels = input(name="showLabels", type="boolean", defaultValue=true, label="Show Level Labels", group="Display")

// -- Colors --
var supColor = input(name="supColor", type="color", defaultValue="#26a69a", label="Support Color", group="Colors")
var resColor = input(name="resColor", type="color", defaultValue="#ef5350", label="Resistance Color", group="Colors")
var supWeakColor = input(name="supWeakColor", type="color", defaultValue="#4db6ac", label="Support Weak Color", group="Colors")
var resWeakColor = input(name="resWeakColor", type="color", defaultValue="#ef9a9a", label="Resistance Weak Color", group="Colors")
var breakColor = input(name="breakColor", type="color", defaultValue="#ffd700", label="Break Color", group="Colors")
var pocColor = input(name="pocColor", type="color", defaultValue="#9c27b0", label="POC Color", group="Colors")
var vaColor = input(name="vaColor", type="color", defaultValue="#9c27b040", label="Value Area Color", group="Colors")
var nodeColor = input(name="nodeColor", type="color", defaultValue="#ff9800", label="Volume Node Color", group="Colors")
var neutralColor = input(name="neutralColor", type="color", defaultValue="#78909c", label="Neutral Color", group="Colors")

// ---------------------------------------------------------------------------
// 2. DATA SOURCES
// ---------------------------------------------------------------------------

timeseries bars = ohlcv(symbol=currentSymbol, exchange=currentExchange)
timeseries px = bars.close
timeseries hi = bars.high
timeseries lo = bars.low
timeseries vol = bars.volume

if (isnan(px[0]) || isnan(hi[0]) || isnan(lo[0]) || isnan(vol[0])) {
    return
}

// ---------------------------------------------------------------------------
// 3. ATR (Wilder) with proper True Range
// ---------------------------------------------------------------------------

timeseries prevClose = isnan(px[1]) ? px : px[1]
timeseries tr1 = hi - lo
timeseries tr2 = math.abs(hi - prevClose)
timeseries tr3 = math.abs(lo - prevClose)
timeseries trueRange = math.max(tr1, math.max(tr2, tr3))
timeseries atr = sma(trueRange, atrLen)
timeseries atrPad = atr * padMult

// ---------------------------------------------------------------------------
// 4. Volume Average and Pivot Detection
// ---------------------------------------------------------------------------

timeseries avgVol = sma(vol, volLookback)

// Volume-confirmed pivot detection
var isSwingHigh = hi[pivotLen] == highest(hi, pivotLen * 2 + 1) && hi[pivotLen] > highest(hi, pivotLen) && vol[pivotLen] >= avgVol[pivotLen] * volMult
var isSwingLow = lo[pivotLen] == lowest(lo, pivotLen * 2 + 1) && lo[pivotLen] < lowest(lo, pivotLen) && vol[pivotLen] >= avgVol[pivotLen] * volMult

// Bar counter
static barCount = 0
if (!isLiveUpdate) {
    barCount = barCount + 1
}

// ---------------------------------------------------------------------------
// 5. POC & Value Area (rolling approximation)
// ---------------------------------------------------------------------------

// POC = price of the highest-volume bar in the lookback window
static pocPrice = 0.0
timeseries maxVolInWindow = highest(vol, pocWindow)
timeseries isNewPOC = vol == maxVolInWindow
if (isNewPOC && !isLiveUpdate) {
    pocPrice = px
}

// Rolling VWAP approximation for Value Area centre
timeseries volPx = px * vol
timeseries sumVolPx = sum(volPx, pocWindow)
timeseries sumVol = sum(vol, pocWindow)
timeseries vwap = sumVol > 0 ? sumVolPx / sumVol : px

// Value Area width via ATR proxy (sqrt unavailable; ATR is a robust volatility proxy)
timeseries vaWidth = atr * vaBandMult
timeseries vaHigh = vwap + vaWidth
timeseries vaLow = vwap - vaWidth

// Volume Node detection: high-volume bar whose price is near current price
// (approximates a High Volume Node at the current price level)
timeseries highVolBar = vol >= avgVol * volMult
timeseries nearPOC = math.abs(px - pocPrice) < atr * 0.5
timeseries volNode = highVolBar && nearPOC

// ---------------------------------------------------------------------------
// 6. Static State: S/R Level Tracking (up to 3 res + 3 sup)
// ---------------------------------------------------------------------------

// --- Resistance Levels ---
static res1Price = 0.0
static res1Top = 0.0
static res1Bot = 0.0
static res1Str = 0.0
static res1Bar = 0
static res1Vol = 0.0
static res1Active = 0
static res1Broken = 0

static res2Price = 0.0
static res2Top = 0.0
static res2Bot = 0.0
static res2Str = 0.0
static res2Bar = 0
static res2Vol = 0.0
static res2Active = 0
static res2Broken = 0

static res3Price = 0.0
static res3Top = 0.0
static res3Bot = 0.0
static res3Str = 0.0
static res3Bar = 0
static res3Vol = 0.0
static res3Active = 0
static res3Broken = 0

// --- Support Levels ---
static sup1Price = 0.0
static sup1Top = 0.0
static sup1Bot = 0.0
static sup1Str = 0.0
static sup1Bar = 0
static sup1Vol = 0.0
static sup1Active = 0
static sup1Broken = 0

static sup2Price = 0.0
static sup2Top = 0.0
static sup2Bot = 0.0
static sup2Str = 0.0
static sup2Bar = 0
static sup2Vol = 0.0
static sup2Active = 0
static sup2Broken = 0

static sup3Price = 0.0
static sup3Top = 0.0
static sup3Bot = 0.0
static sup3Str = 0.0
static sup3Bar = 0
static sup3Vol = 0.0
static sup3Active = 0
static sup3Broken = 0

// ---------------------------------------------------------------------------
// 7. Helpers
// ---------------------------------------------------------------------------

var minDist = px * minDistPct / 100.0

function isFarFromExisting(newPrice, existingPrice) {
    return existingPrice == 0.0 || math.abs(newPrice - existingPrice) > minDist
}

function canAddResistance(newPrice) {
    return isFarFromExisting(newPrice, res1Price) && isFarFromExisting(newPrice, res2Price) && isFarFromExisting(newPrice, res3Price)
}

function canAddSupport(newPrice) {
    return isFarFromExisting(newPrice, sup1Price) && isFarFromExisting(newPrice, sup2Price) && isFarFromExisting(newPrice, sup3Price)
}

function calcStrength(pivotVol, pivotBar, currentBar) {
    var volRatio = avgVol > 0 ? pivotVol / avgVol : 1.0
    var barsSince = currentBar - pivotBar
    var recencyDecay = barsSince < maxAgeBars ? 1.0 - (barsSince / maxAgeBars) * 0.7 : 0.3
    return volRatio * recencyDecay
}

function shiftResLevels() {
    res3Price = res2Price
    res3Top = res2Top
    res3Bot = res2Bot
    res3Str = res2Str
    res3Bar = res2Bar
    res3Vol = res2Vol
    res3Active = res2Active
    res3Broken = res2Broken

    res2Price = res1Price
    res2Top = res1Top
    res2Bot = res1Bot
    res2Str = res1Str
    res2Bar = res1Bar
    res2Vol = res1Vol
    res2Active = res1Active
    res2Broken = res1Broken
}

function shiftSupLevels() {
    sup3Price = sup2Price
    sup3Top = sup2Top
    sup3Bot = sup2Bot
    sup3Str = sup2Str
    sup3Bar = sup2Bar
    sup3Vol = sup2Vol
    sup3Active = sup2Active
    sup3Broken = sup2Broken

    sup2Price = sup1Price
    sup2Top = sup1Top
    sup2Bot = sup1Bot
    sup2Str = sup1Str
    sup2Bar = sup1Bar
    sup2Vol = sup1Vol
    sup2Active = sup1Active
    sup2Broken = sup1Broken
}

function invalidateOldLevels(currentBar) {
    if (res1Active == 1 && currentBar - res1Bar > maxAgeBars) { res1Active = 0 }
    if (res2Active == 1 && currentBar - res2Bar > maxAgeBars) { res2Active = 0 }
    if (res3Active == 1 && currentBar - res3Bar > maxAgeBars) { res3Active = 0 }
    if (sup1Active == 1 && currentBar - sup1Bar > maxAgeBars) { sup1Active = 0 }
    if (sup2Active == 1 && currentBar - sup2Bar > maxAgeBars) { sup2Active = 0 }
    if (sup3Active == 1 && currentBar - sup3Bar > maxAgeBars) { sup3Active = 0 }
}

function checkBreaks() {
    if (res1Active == 1 && res1Broken == 0 && px > res1Top && vol >= avgVol * breakMult) { res1Broken = 1 }
    if (res2Active == 1 && res2Broken == 0 && px > res2Top && vol >= avgVol * breakMult) { res2Broken = 1 }
    if (res3Active == 1 && res3Broken == 0 && px > res3Top && vol >= avgVol * breakMult) { res3Broken = 1 }
    if (sup1Active == 1 && sup1Broken == 0 && px < sup1Bot && vol >= avgVol * breakMult) { sup1Broken = 1 }
    if (sup2Active == 1 && sup2Broken == 0 && px < sup2Bot && vol >= avgVol * breakMult) { sup2Broken = 1 }
    if (sup3Active == 1 && sup3Broken == 0 && px < sup3Bot && vol >= avgVol * breakMult) { sup3Broken = 1 }
}

// ---------------------------------------------------------------------------
// 8. State Update (only on bar close)
// ---------------------------------------------------------------------------

if (!isLiveUpdate) {
    invalidateOldLevels(barCount)
    checkBreaks()

    if (isSwingHigh) {
        var swingPrice = hi[pivotLen]
        var swingVol = vol[pivotLen]
        if (canAddResistance(swingPrice)) {
            shiftResLevels()
            res1Price = swingPrice
            res1Top = swingPrice + atrPad
            res1Bot = swingPrice - atrPad
            res1Str = calcStrength(swingVol, barCount - pivotLen, barCount)
            res1Bar = barCount - pivotLen
            res1Vol = swingVol
            res1Active = 1
            res1Broken = 0
        }
    }

    if (isSwingLow) {
        var swingPrice = lo[pivotLen]
        var swingVol = vol[pivotLen]
        if (canAddSupport(swingPrice)) {
            shiftSupLevels()
            sup1Price = swingPrice
            sup1Top = swingPrice + atrPad
            sup1Bot = swingPrice - atrPad
            sup1Str = calcStrength(swingVol, barCount - pivotLen, barCount)
            sup1Bar = barCount - pivotLen
            sup1Vol = swingVol
            sup1Active = 1
            sup1Broken = 0
        }
    }

    if (res1Active == 1) { res1Str = calcStrength(res1Vol, res1Bar, barCount) }
    if (res2Active == 1) { res2Str = calcStrength(res2Vol, res2Bar, barCount) }
    if (res3Active == 1) { res3Str = calcStrength(res3Vol, res3Bar, barCount) }
    if (sup1Active == 1) { sup1Str = calcStrength(sup1Vol, sup1Bar, barCount) }
    if (sup2Active == 1) { sup2Str = calcStrength(sup2Vol, sup2Bar, barCount) }
    if (sup3Active == 1) { sup3Str = calcStrength(sup3Vol, sup3Bar, barCount) }
}

// ---------------------------------------------------------------------------
// 9. Event Flags
// ---------------------------------------------------------------------------

var newResEvent = isSwingHigh && barCount > pivotLen
var newSupEvent = isSwingLow && barCount > pivotLen

var res1BreakEvent = res1Broken == 1 && barCount - res1Bar <= maxAgeBars && px > res1Top && vol >= avgVol * breakMult
var res2BreakEvent = res2Broken == 1 && barCount - res2Bar <= maxAgeBars && px > res2Top && vol >= avgVol * breakMult
var res3BreakEvent = res3Broken == 1 && barCount - res3Bar <= maxAgeBars && px > res3Top && vol >= avgVol * breakMult
var sup1BreakEvent = sup1Broken == 1 && barCount - sup1Bar <= maxAgeBars && px < sup1Bot && vol >= avgVol * breakMult
var sup2BreakEvent = sup2Broken == 1 && barCount - sup2Bar <= maxAgeBars && px < sup2Bot && vol >= avgVol * breakMult
var sup3BreakEvent = sup3Broken == 1 && barCount - sup3Bar <= maxAgeBars && px < sup3Bot && vol >= avgVol * breakMult

// ---------------------------------------------------------------------------
// 10. Plots: Resistance Zones
// ---------------------------------------------------------------------------

if (showZones && res1Active == 1) {
    var r1Color = res1Broken == 1 ? resWeakColor : resColor
    var r1FillOpacity = res1Broken == 1 ? opacity(resWeakColor, 20) : opacity(resColor, 30)
    plotLine(
        value=[res1Top, res1Bot],
        width=1,
        colors=[r1Color, r1Color],
        fill=r1FillOpacity,
        label=["R1 Zone", "R1 Zone"],
        desc=["Resistance zone 1 top (ATR-padded, volume-confirmed pivot)", "Resistance zone 1 bottom"]
    )
    if (showLabels) {
        plotLine(
            value=res1Price,
            width=1,
            colors=[r1Color],
            label=["R1"],
            desc=["Resistance level 1: volume-confirmed pivot high"]
        )
    }
}

if (showZones && res2Active == 1) {
    var r2Color = res2Broken == 1 ? resWeakColor : resColor
    var r2FillOpacity = res2Broken == 1 ? opacity(resWeakColor, 20) : opacity(resColor, 25)
    plotLine(
        value=[res2Top, res2Bot],
        width=1,
        colors=[r2Color, r2Color],
        fill=r2FillOpacity,
        label=["R2 Zone", "R2 Zone"],
        desc=["Resistance zone 2 top", "Resistance zone 2 bottom"]
    )
    if (showLabels) {
        plotLine(
            value=res2Price,
            width=1,
            colors=[r2Color],
            label=["R2"],
            desc=["Resistance level 2: volume-confirmed pivot high"]
        )
    }
}

if (showZones && res3Active == 1) {
    var r3Color = res3Broken == 1 ? resWeakColor : resColor
    var r3FillOpacity = res3Broken == 1 ? opacity(resWeakColor, 20) : opacity(resColor, 20)
    plotLine(
        value=[res3Top, res3Bot],
        width=1,
        colors=[r3Color, r3Color],
        fill=r3FillOpacity,
        label=["R3 Zone", "R3 Zone"],
        desc=["Resistance zone 3 top", "Resistance zone 3 bottom"]
    )
    if (showLabels) {
        plotLine(
            value=res3Price,
            width=1,
            colors=[r3Color],
            label=["R3"],
            desc=["Resistance level 3: volume-confirmed pivot high"]
        )
    }
}

// ---------------------------------------------------------------------------
// 11. Plots: Support Zones
// ---------------------------------------------------------------------------

if (showZones && sup1Active == 1) {
    var s1Color = sup1Broken == 1 ? supWeakColor : supColor
    var s1FillOpacity = sup1Broken == 1 ? opacity(supWeakColor, 20) : opacity(supColor, 30)
    plotLine(
        value=[sup1Top, sup1Bot],
        width=1,
        colors=[s1Color, s1Color],
        fill=s1FillOpacity,
        label=["S1 Zone", "S1 Zone"],
        desc=["Support zone 1 top", "Support zone 1 bottom"]
    )
    if (showLabels) {
        plotLine(
            value=sup1Price,
            width=1,
            colors=[s1Color],
            label=["S1"],
            desc=["Support level 1: volume-confirmed pivot low"]
        )
    }
}

if (showZones && sup2Active == 1) {
    var s2Color = sup2Broken == 1 ? supWeakColor : supColor
    var s2FillOpacity = sup2Broken == 1 ? opacity(supWeakColor, 20) : opacity(supColor, 25)
    plotLine(
        value=[sup2Top, sup2Bot],
        width=1,
        colors=[s2Color, s2Color],
        fill=s2FillOpacity,
        label=["S2 Zone", "S2 Zone"],
        desc=["Support zone 2 top", "Support zone 2 bottom"]
    )
    if (showLabels) {
        plotLine(
            value=sup2Price,
            width=1,
            colors=[s2Color],
            label=["S2"],
            desc=["Support level 2: volume-confirmed pivot low"]
        )
    }
}

if (showZones && sup3Active == 1) {
    var s3Color = sup3Broken == 1 ? supWeakColor : supColor
    var s3FillOpacity = sup3Broken == 1 ? opacity(supWeakColor, 20) : opacity(supColor, 20)
    plotLine(
        value=[sup3Top, sup3Bot],
        width=1,
        colors=[s3Color, s3Color],
        fill=s3FillOpacity,
        label=["S3 Zone", "S3 Zone"],
        desc=["Support zone 3 top", "Support zone 3 bottom"]
    )
    if (showLabels) {
        plotLine(
            value=sup3Price,
            width=1,
            colors=[s3Color],
            label=["S3"],
            desc=["Support level 3: volume-confirmed pivot low"]
        )
    }
}

// ---------------------------------------------------------------------------
// 12. Plots: POC, Value Area & Volume Nodes
// ---------------------------------------------------------------------------

if (showPOC && pocPrice > 0) {
    plotLine(
        value=pocPrice,
        width=2,
        colors=[pocColor],
        label=["POC"],
        desc=["Point of Control: price of highest-volume bar in lookback window"]
    )
}

if (showValueArea) {
    plotLine(
        value=[vaHigh, vaLow],
        width=1,
        colors=[pocColor, pocColor],
        fill=vaColor,
        label=["VA High", "VA Low"],
        desc=["Value Area: VWAP ± ATR × multiplier; approximates 70% volume zone"]
    )
}

if (showZones && volNode) {
    plotShape(
        value=px,
        shape="square",
        color=nodeColor,
        width=2,
        label=["Volume Node"],
        desc=["High-volume node near POC: price level with significant institutional participation"]
    )
}

// ---------------------------------------------------------------------------
// 13. Plots: Pivot Markers
// ---------------------------------------------------------------------------

if (showPivots && newResEvent) {
    plotShape(
        value=hi[pivotLen],
        shape="triangleup",
        color=resColor,
        width=3,
        label=["Res Pivot"],
        desc=["Volume-confirmed resistance pivot: high exceeds surrounding bars with above-average volume"]
    )
}

if (showPivots && newSupEvent) {
    plotShape(
        value=lo[pivotLen],
        shape="triangledown",
        color=supColor,
        width=3,
        label=["Sup Pivot"],
        desc=["Volume-confirmed support pivot: low below surrounding bars with above-average volume"]
    )
}

// ---------------------------------------------------------------------------
// 14. Plots: Break Markers
// ---------------------------------------------------------------------------

if (showBreaks && res1BreakEvent) {
    plotShape(
        value=px,
        shape="cross",
        color=breakColor,
        width=4,
        label=["R1 Break"],
        desc=["Resistance level 1 broken with volume confirmation"]
    )
}
if (showBreaks && res2BreakEvent) {
    plotShape(
        value=px,
        shape="cross",
        color=breakColor,
        width=4,
        label=["R2 Break"],
        desc=["Resistance level 2 broken with volume confirmation"]
    )
}
if (showBreaks && res3BreakEvent) {
    plotShape(
        value=px,
        shape="cross",
        color=breakColor,
        width=4,
        label=["R3 Break"],
        desc=["Resistance level 3 broken with volume confirmation"]
    )
}
if (showBreaks && sup1BreakEvent) {
    plotShape(
        value=px,
        shape="cross",
        color=breakColor,
        width=4,
        label=["S1 Break"],
        desc=["Support level 1 broken with volume confirmation"]
    )
}
if (showBreaks && sup2BreakEvent) {
    plotShape(
        value=px,
        shape="cross",
        color=breakColor,
        width=4,
        label=["S2 Break"],
        desc=["Support level 2 broken with volume confirmation"]
    )
}
if (showBreaks && sup3BreakEvent) {
    plotShape(
        value=px,
        shape="cross",
        color=breakColor,
        width=4,
        label=["S3 Break"],
        desc=["Support level 3 broken with volume confirmation"]
    )
}

// ---------------------------------------------------------------------------
// 15. Plots: Strength Score
// ---------------------------------------------------------------------------

if (showStrength) {
    var totalStrength = 0.0
    if (res1Active == 1 && res1Broken == 0) { totalStrength = totalStrength + res1Str }
    if (res2Active == 1 && res2Broken == 0) { totalStrength = totalStrength + res2Str }
    if (res3Active == 1 && res3Broken == 0) { totalStrength = totalStrength + res3Str }
    if (sup1Active == 1 && sup1Broken == 0) { totalStrength = totalStrength + sup1Str }
    if (sup2Active == 1 && sup2Broken == 0) { totalStrength = totalStrength + sup2Str }
    if (sup3Active == 1 && sup3Broken == 0) { totalStrength = totalStrength + sup3Str }

    plotBar(
        value=totalStrength,
        colors=[neutralColor],
        width=1,
        label=["S/R Strength"],
        desc=["Combined volume-weighted strength of active S/R levels (recency-decayed)"]
    )
}