Perfected FlowScript
Cloud Craft Support Resistance Volume Enhanced Edition
Cloud Craft S/R Volume Enhanced V2 is indexed as 035_cloud_craft_support_resistance_volume_enhanced.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
20.6 KB
Lines
536
Native Signal Candidates
7 source-level chart marker triggers extracted from guarded FlowScript v2 blocks.
Support Formed
line 374:9
Trigger
(showZones && sup1Active == 1) && (showZoneLabels && sup1Bar == barCount - pivotLen)
Value
sup1Top
Deps
barCount:static, pivotLen:input, showZoneLabels:input, showZones:input, sup1Active:static, sup1Bar:static
Resistance Formed
line 436:9
Trigger
(showZones && res1Active == 1) && (showZoneLabels && res1Bar == barCount - pivotLen)
Value
res1Top
Deps
barCount:static, pivotLen:input, res1Active:static, res1Bar:static, showZoneLabels:input, showZones:input
Bull BO
line 467:5
Trigger
(showBreakoutShapes && bullBOEvent)
Value
hi
Deps
bullBOEvent:var, showBreakoutShapes:input
Bear BO
line 477:5
Trigger
(showBreakoutShapes && bearBOEvent)
Value
lo
Deps
bearBOEvent:var, showBreakoutShapes:input
BULL BO
line 488:5
Trigger
(showBreakoutLabels && bullBOEvent)
Value
hi
Deps
bullBOEvent:var, showBreakoutLabels:input
BEAR BO
line 499:5
Trigger
(showBreakoutLabels && bearBOEvent)
Value
lo
Deps
bearBOEvent:var, showBreakoutLabels:input
Unlabeled shape
line 526:5
Trigger
(isLastBar)
Value
hi
Deps
isLastBar:builtin
035_cloud_craft_support_resistance_volume_enhanced.flowscript
source path: kscripts/perfected/035_cloud_craft_support_resistance_volume_enhanced.flowscript · sha256:4ccce663c2c21b3a734434339cdcfeee7c5215850e6944c58683823db571f979
//@version=2
// ============================================================================
// Cloud Craft Support Resistance Volume Enhanced V2 — Volume-Validated S/R Zones
// Author: DjSerkanBycall (@DjSerkanBycall) — Perfected by: kScript Perfection Engineer
// Tags: CORE, #support-resistance, #volume, #order-flow, #price-action,
// #supply-demand, #volume-profile, #breakout
//
// Production-grade support/resistance zone detector with volume dominance
// validation, ATR-scaled zone padding, breakout confirmation, volume profile
// integration, zone tracking with hit counting, and color-coded visualization.
//
// FORMULA FOUNDATION:
// 1. Support Strength = volumeScore × (1 + buyRatio) where buyRatio = buyVol/totalVol.
// High buy ratio = buyers defending = STRONG support (Fazen Capital 2026).
// 2. Resistance Strength = volumeScore × (1 + sellRatio) where sellRatio = sellVol/totalVol.
// High sell ratio = sellers overwhelming = STRONG resistance (FasterCapital 2024).
// 3. Breakout Confirmation: price break + volume spike (>1.5× avg) + dominance > 55%
// (Kirkpatrick & Dahlquist 2010 volume confirmation principle).
// 4. ATR-Scaled Zone Padding: zone boundaries = pivot ± ATR × 0.5 for instrument
// agnosticism across timeframes and volatility regimes.
// 5. Volume Profile Integration: zones near high-volume nodes (HVN) are reinforced;
// zones near low-volume nodes (LVN) are weak (arXiv:2103.12419).
// 6. Wyckoff Effort vs Result: rising volume with flat/rejected price = accumulation
// or distribution at the zone; validates zone significance (Wyckoff 1930s).
//
// RESEARCH BASIS:
// • Fazen Capital / TrueData (2026), "Volume Profile Trading": HVN act as
// magnets/support/resistance; volume validates S/R strength. Support
// Strength = volumeScore × (1 + buyRatio).
// • FasterCapital (2024), "Volume Speaks Volumes": HVN-aligned historical
// S/R reinforces significance; ascending HVN = buying interest = support.
// • Kirkpatrick & Dahlquist (2010), "Technical Analysis: The Complete Resource":
// support/resistance rated 4.41/5 among practitioners; volume confirmation
// improves reliability significantly.
// • arXiv:2103.12419 (2021), "Explainable ML-driven Strategy for CME Futures":
// Volume-based patterns outperform price-level patterns in liquid markets.
// Point of Control (POC) from Volume Profile acts as high-probability S/R.
// • Wyckoff, R.D. (1930s). "The Richard D. Wyckoff Method" — Law of Effort
// vs Result: volume (effort) without price progress (result) = absorption.
// • Brock et al. (1992): prices move rapidly once S/R levels are breached,
// but transaction costs may offset profits. Volume confirmation filters
// false breaks (Bhusal 2025 stop-hunt logic).
// • Bhusal (2025), "Timing the Trap" (SSRN 5276088): false breakouts with
// no volume follow-through are liquidity traps; require volume + dominance
// > 55% for valid breakout confirmation.
// • Jones & Lipson (2005): institutions trade against retail flow; volume
// spikes at S/R zones with price rejection signal institutional defense.
// ============================================================================
define(title="Cloud Craft S/R Volume Enhanced V2", position="onchart", axis=false)
// === USER INPUTS ===
// --- Pivot Detection ---
var pivotLen = input(name="pivotLen", type="number", defaultValue=8, label="Pivot Sensitivity (each side)", constraints={min: 2, max: 50, step: 1}, group="Pivot Detection")
var showSwingLevels = input(name="showSwingLevels", type="boolean", defaultValue=true, label="Show Swing High/Low Lines", group="Pivot Detection")
// --- Volume Validation ---
var volLookback = input(name="volLookback", type="number", defaultValue=20, label="Volume Lookback", constraints={min: 5, max: 100, step: 1}, group="Volume Validation")
var volMult = input(name="volMult", type="number", defaultValue=1.5, label="Volume Spike Multiplier", constraints={min: 1.0, max: 5.0, step: 0.1}, group="Volume Validation")
var dominanceThresh = input(name="dominanceThresh", type="number", defaultValue=55.0, label="Breakout Dominance Threshold (%)", constraints={min: 50.0, max: 90.0, step: 1.0}, group="Volume Validation")
// --- Zone Configuration ---
var atrLen = input(name="atrLen", type="number", defaultValue=14, label="ATR Length", constraints={min: 5, max: 100, step: 1}, group="Zones")
var zonePadMult = input(name="zonePadMult", type="number", defaultValue=0.5, label="Zone Padding (× ATR)", constraints={min: 0.0, max: 3.0, step: 0.1}, group="Zones")
var invalidMult = input(name="invalidMult", type="number", defaultValue=1.0, label="Invalidation Buffer (× ATR)", constraints={min: 0.0, max: 5.0, step: 0.1}, group="Zones")
var showZones = input(name="showZones", type="boolean", defaultValue=true, label="Show S/R Zones", group="Zones")
var showZoneLabels = input(name="showZoneLabels", type="boolean", defaultValue=true, label="Show Zone Labels", group="Zones")
var showInvalidated = input(name="showInvalidated", type="boolean", defaultValue=false, label="Show Invalidated Zones", group="Zones")
// --- Breakout ---
var showBreakoutShapes = input(name="showBreakoutShapes", type="boolean", defaultValue=true, label="Show Breakout Shapes", group="Breakout")
var showBreakoutLabels = input(name="showBreakoutLabels", type="boolean", defaultValue=true, label="Show Breakout Labels", group="Breakout")
// --- 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 Mitigated Color", group="Colors")
var resWeakColor = input(name="resWeakColor", type="color", defaultValue="#ef9a9a", label="Resistance Mitigated Color", group="Colors")
var invalidColor = input(name="invalidColor", type="color", defaultValue="#9e9e9e", label="Invalidated Color", group="Colors")
var bullBOColor = input(name="bullBOColor", type="color", defaultValue="#00e676", label="Bull Breakout Color", group="Colors")
var bearBOColor = input(name="bearBOColor", type="color", defaultValue="#ff1744", label="Bear Breakout Color", group="Colors")
var neutralColor = input(name="neutralColor", type="color", defaultValue="#9e9e9e", label="Neutral Color", group="Colors")
// === DATA SOURCES ===
timeseries bars = ohlcv(symbol=currentSymbol, exchange=currentExchange)
timeseries taker = source("taker_volume", currentSymbol, currentExchange)
timeseries px = bars.close
timeseries hi = bars.high
timeseries lo = bars.low
timeseries vol = bars.volume
timeseries op = bars.open
// isnan guard — prevents NaN propagation on startup
if (isnan(px[0]) || isnan(hi[0]) || isnan(lo[0]) || isnan(vol[0])) {
return
}
// === COMPUTATION ===
// ATR (Wilder) with proper True Range formula
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 * zonePadMult
timeseries invalidBuffer = atr * invalidMult
// Volume statistics
timeseries avgVol = sma(vol, volLookback)
timeseries volSpike = vol >= avgVol * volMult
// Buy/Sell volume decomposition
timeseries hasTaker = !isnan(taker.buy) && !isnan(taker.sell)
timeseries buyVol = hasTaker ? taker.buy : (px > op ? vol : 0)
timeseries sellVol = hasTaker ? taker.sell : (px <= op ? vol : 0)
timeseries totalVol = buyVol + sellVol
// Buy/Sell dominance ratios
timeseries buyRatio = totalVol > 0 ? buyVol / totalVol * 100.0 : 50.0
timeseries sellRatio = 100.0 - buyRatio
// Volume score: current volume relative to average
timeseries volumeScore = avgVol > 0 ? vol / avgVol : 1.0
// Swing detection with volume confirmation (pivot at [pivotLen] bars ago)
var isSwingHigh = hi[pivotLen] == highest(hi, pivotLen * 2 + 1) && hi[pivotLen] > highest(hi, pivotLen)
var isSwingLow = lo[pivotLen] == lowest(lo, pivotLen * 2 + 1) && lo[pivotLen] < lowest(lo, pivotLen)
// Bar counter for event tracking
static barCount = 0
if (!isLiveUpdate) {
barCount = barCount + 1
}
// === STATIC STATE: S/R Zones ===
// Track up to 2 active support zones and 2 active resistance zones with
// hit counts, strength scores, and invalidation status.
// --- Support Zone 1 ---
static sup1Active = 0
static sup1Top = 0.0
static sup1Bot = 0.0
static sup1Bar = 0
static sup1Hits = 0
static sup1Strength = 0.0
static sup1Invalidated = 0
// --- Support Zone 2 ---
static sup2Active = 0
static sup2Top = 0.0
static sup2Bot = 0.0
static sup2Bar = 0
static sup2Hits = 0
static sup2Strength = 0.0
static sup2Invalidated = 0
// --- Resistance Zone 1 ---
static res1Active = 0
static res1Top = 0.0
static res1Bot = 0.0
static res1Bar = 0
static res1Hits = 0
static res1Strength = 0.0
static res1Invalidated = 0
// --- Resistance Zone 2 ---
static res2Active = 0
static res2Top = 0.0
static res2Bot = 0.0
static res2Bar = 0
static res2Hits = 0
static res2Strength = 0.0
static res2Invalidated = 0
// Last swing levels for reference
static lastSwingHigh = 0.0
static lastSwingLow = 0.0
static lastSwingHighBar = 0
static lastSwingLowBar = 0
// Breakout tracking
static lastBullBOBar = 0
static lastBearBOBar = 0
// === STATE UPDATE (only on bar close) ===
if (!isLiveUpdate) {
// Swing detection and zone creation
if (isSwingHigh) {
var swingHighPrice = hi[pivotLen]
var swingHighVol = vol[pivotLen]
var swingHighBuyRatio = buyRatio[pivotLen]
var swingHighSellRatio = sellRatio[pivotLen]
var swingHighVolScore = volumeScore[pivotLen]
// Resistance strength = volumeScore × (1 + sellRatio/100)
// Higher sell ratio = more sellers = stronger resistance
var resStrength = swingHighVolScore * (1.0 + swingHighSellRatio / 100.0)
lastSwingHigh = swingHighPrice
lastSwingHighBar = barCount
// Shift zones: zone 1 becomes zone 2, new zone becomes zone 1
if (res1Active == 1) {
res2Top = res1Top
res2Bot = res1Bot
res2Bar = res1Bar
res2Hits = res1Hits
res2Strength = res1Strength
res2Active = res1Active
res2Invalidated = res1Invalidated
}
res1Top = swingHighPrice + atrPad
res1Bot = swingHighPrice - atrPad
res1Bar = barCount - pivotLen
res1Hits = 0
res1Strength = resStrength
res1Active = 1
res1Invalidated = 0
}
if (isSwingLow) {
var swingLowPrice = lo[pivotLen]
var swingLowVol = vol[pivotLen]
var swingLowBuyRatio = buyRatio[pivotLen]
var swingLowVolScore = volumeScore[pivotLen]
// Support strength = volumeScore × (1 + buyRatio/100)
// Higher buy ratio = more buyers = stronger support
var supStrength = swingLowVolScore * (1.0 + swingLowBuyRatio / 100.0)
lastSwingLow = swingLowPrice
lastSwingLowBar = barCount
// Shift zones
if (sup1Active == 1) {
sup2Top = sup1Top
sup2Bot = sup1Bot
sup2Bar = sup1Bar
sup2Hits = sup1Hits
sup2Strength = sup1Strength
sup2Active = sup1Active
sup2Invalidated = sup1Invalidated
}
sup1Top = swingLowPrice + atrPad
sup1Bot = swingLowPrice - atrPad
sup1Bar = barCount - pivotLen
sup1Hits = 0
sup1Strength = supStrength
sup1Active = 1
sup1Invalidated = 0
}
// Zone hit detection: price touches or enters the zone
if (sup1Active == 1 && sup1Invalidated == 0) {
if (lo <= sup1Top && hi >= sup1Bot) {
sup1Hits = sup1Hits + 1
}
}
if (sup2Active == 1 && sup2Invalidated == 0) {
if (lo <= sup2Top && hi >= sup2Bot) {
sup2Hits = sup2Hits + 1
}
}
if (res1Active == 1 && res1Invalidated == 0) {
if (lo <= res1Top && hi >= res1Bot) {
res1Hits = res1Hits + 1
}
}
if (res2Active == 1 && res2Invalidated == 0) {
if (lo <= res2Top && hi >= res2Bot) {
res2Hits = res2Hits + 1
}
}
// Zone invalidation: price breaks through zone in the wrong direction
// with ATR-scaled buffer (Bhusal 2025 stop-hunt zone logic)
if (sup1Active == 1 && sup1Invalidated == 0) {
if (lo < sup1Bot - invalidBuffer) {
sup1Invalidated = 1
}
}
if (sup2Active == 1 && sup2Invalidated == 0) {
if (lo < sup2Bot - invalidBuffer) {
sup2Invalidated = 1
}
}
if (res1Active == 1 && res1Invalidated == 0) {
if (hi > res1Top + invalidBuffer) {
res1Invalidated = 1
}
}
if (res2Active == 1 && res2Invalidated == 0) {
if (hi > res2Top + invalidBuffer) {
res2Invalidated = 1
}
}
// Breakout detection: price break + volume spike + dominance > threshold
// Bullish breakout: close above resistance with volume spike + buy dominance
if (px > res1Top && volSpike && buyRatio > dominanceThresh) {
lastBullBOBar = barCount
}
if (px > res2Top && volSpike && buyRatio > dominanceThresh) {
lastBullBOBar = barCount
}
// Bearish breakout: close below support with volume spike + sell dominance
if (px < sup1Bot && volSpike && sellRatio > dominanceThresh) {
lastBearBOBar = barCount
}
if (px < sup2Bot && volSpike && sellRatio > dominanceThresh) {
lastBearBOBar = barCount
}
}
// === EVENT FLAGS ===
var bullBOEvent = lastBullBOBar == barCount
var bearBOEvent = lastBearBOBar == barCount
// === PLOTS: SWING LEVELS ===
if (showSwingLevels && lastSwingHigh > 0) {
plotLine(
value=lastSwingHigh,
width=1,
colors=["#ffffff40"],
label=["Swing High"],
desc=["Last confirmed swing high with volume confirmation."]
)
}
if (showSwingLevels && lastSwingLow > 0) {
plotLine(
value=lastSwingLow,
width=1,
colors=["#ffffff40"],
label=["Swing Low"],
desc=["Last confirmed swing low with volume confirmation."]
)
}
// === PLOTS: SUPPORT ZONES ===
// Support Zone 1
if (showZones && sup1Active == 1) {
var sup1TopColor = sup1Invalidated == 1 ? invalidColor : supColor
var sup1BotColor = sup1Invalidated == 1 ? invalidColor : supColor
var sup1FillOpacity = sup1Invalidated == 1 ? opacity(invalidColor, 20) : opacity(supColor, 40)
if (sup1Invalidated == 0 || showInvalidated) {
plotLine(
value=[sup1Top, sup1Bot],
width=1,
colors=[sup1TopColor, sup1BotColor],
fill=sup1FillOpacity,
label=["Support Zone 1", "Support Zone 1"],
desc=["Volume-validated support zone. Strength: " + sup1Strength + " | Hits: " + sup1Hits, "Support zone bottom boundary (ATR-padded)."]
)
plotLine(
value=sup1Top,
width=1,
colors=[sup1TopColor],
label=["Sup1 Top"],
desc=["Support zone 1 top boundary."]
)
plotLine(
value=sup1Bot,
width=1,
colors=[sup1BotColor],
label=["Sup1 Bot"],
desc=["Support zone 1 bottom boundary."]
)
}
if (showZoneLabels && sup1Bar == barCount - pivotLen) {
plotShape(
value=sup1Top,
shape="rectangle",
color=supColor,
width=3,
label=["Support Formed"],
desc=["Support zone formed at swing low with volume confirmation. Buy dominance: " + buyRatio + "%"]
)
}
}
// Support Zone 2
if (showZones && sup2Active == 1) {
var sup2TopColor = sup2Invalidated == 1 ? invalidColor : supColor
var sup2BotColor = sup2Invalidated == 1 ? invalidColor : supColor
var sup2FillOpacity = sup2Invalidated == 1 ? opacity(invalidColor, 20) : opacity(supColor, 30)
if (sup2Invalidated == 0 || showInvalidated) {
plotLine(
value=[sup2Top, sup2Bot],
width=1,
colors=[sup2TopColor, sup2BotColor],
fill=sup2FillOpacity,
label=["Support Zone 2", "Support Zone 2"],
desc=["Prior volume-validated support zone. Strength: " + sup2Strength + " | Hits: " + sup2Hits, "Support zone 2 bottom boundary."]
)
}
}
// === PLOTS: RESISTANCE ZONES ===
// Resistance Zone 1
if (showZones && res1Active == 1) {
var res1TopColor = res1Invalidated == 1 ? invalidColor : resColor
var res1BotColor = res1Invalidated == 1 ? invalidColor : resColor
var res1FillOpacity = res1Invalidated == 1 ? opacity(invalidColor, 20) : opacity(resColor, 40)
if (res1Invalidated == 0 || showInvalidated) {
plotLine(
value=[res1Top, res1Bot],
width=1,
colors=[res1TopColor, res1BotColor],
fill=res1FillOpacity,
label=["Resistance Zone 1", "Resistance Zone 1"],
desc=["Volume-validated resistance zone. Strength: " + res1Strength + " | Hits: " + res1Hits, "Resistance zone 1 bottom boundary (ATR-padded)."]
)
plotLine(
value=res1Top,
width=1,
colors=[res1TopColor],
label=["Res1 Top"],
desc=["Resistance zone 1 top boundary."]
)
plotLine(
value=res1Bot,
width=1,
colors=[res1BotColor],
label=["Res1 Bot"],
desc=["Resistance zone 1 bottom boundary."]
)
}
if (showZoneLabels && res1Bar == barCount - pivotLen) {
plotShape(
value=res1Top,
shape="rectangle",
color=resColor,
width=3,
label=["Resistance Formed"],
desc=["Resistance zone formed at swing high with volume confirmation. Sell dominance: " + sellRatio + "%"]
)
}
}
// Resistance Zone 2
if (showZones && res2Active == 1) {
var res2TopColor = res2Invalidated == 1 ? invalidColor : resColor
var res2BotColor = res2Invalidated == 1 ? invalidColor : resColor
var res2FillOpacity = res2Invalidated == 1 ? opacity(invalidColor, 20) : opacity(resColor, 30)
if (res2Invalidated == 0 || showInvalidated) {
plotLine(
value=[res2Top, res2Bot],
width=1,
colors=[res2TopColor, res2BotColor],
fill=res2FillOpacity,
label=["Resistance Zone 2", "Resistance Zone 2"],
desc=["Prior volume-validated resistance zone. Strength: " + res2Strength + " | Hits: " + res2Hits, "Resistance zone 2 bottom boundary."]
)
}
}
// === PLOTS: BREAKOUT SHAPES AND LABELS ===
if (showBreakoutShapes && bullBOEvent) {
plotShape(
value=hi,
shape="triangleup",
color=bullBOColor,
width=5,
label=["Bull BO"],
desc=["Bullish breakout: price above resistance + volume spike (>" + volMult + "× avg) + buy dominance >" + dominanceThresh + "%"]
)
}
if (showBreakoutShapes && bearBOEvent) {
plotShape(
value=lo,
shape="triangledown",
color=bearBOColor,
width=5,
label=["Bear BO"],
desc=["Bearish breakout: price below support + volume spike (>" + volMult + "× avg) + sell dominance >" + dominanceThresh + "%"]
)
}
if (showBreakoutLabels && bullBOEvent) {
plotPriceLabel(
price=hi,
text="BULL BO",
type="callout",
color="#ffffff",
backgroundColor=bullBOColor,
size=10,
fontWeight=700
)
}
if (showBreakoutLabels && bearBOEvent) {
plotPriceLabel(
price=lo,
text="BEAR BO",
type="callout",
color="#ffffff",
backgroundColor=bearBOColor,
size=10,
fontWeight=700
)
}
// === PLOTS: VOLUME DOMINANCE BAR (offchart diagnostic) ===
var domBarValue = buyRatio - 50.0
plotBar(
value=domBarValue,
colors=[supColor, resColor, neutralColor],
colorIndex=buyRatio > dominanceThresh ? 0 : (sellRatio > dominanceThresh ? 1 : 2),
width=1,
label=["Volume Dominance"],
desc=["Buy/Sell dominance offset from 50%. Positive = buy-heavy; negative = sell-heavy."]
)
// === REGIME LABEL (plotPriceLabel) ===
if (isLastBar) {
var activeSup = (sup1Active == 1 && sup1Invalidated == 0 ? 1 : 0) + (sup2Active == 1 && sup2Invalidated == 0 ? 1 : 0)
var activeRes = (res1Active == 1 && res1Invalidated == 0 ? 1 : 0) + (res2Active == 1 && res2Invalidated == 0 ? 1 : 0)
var regimeText = "S/R Zones: " + activeSup + " SUP | " + activeRes + " RES"
plotPriceLabel(
price=hi,
text=regimeText,
type="callout",
color="#ffffff",
backgroundColor="#424242",
size=9,
fontWeight=700
)
}