Here is the "Pro" version. It upgrades the HMA into a Dynamic Volatility Zone, requires price-action confluence, draws precise stop-loss levels, and includes JSON-formatted alerts for automated execution routing.
Code: Select all
//@version=5
indicator("HMA Volatility Zone & Institutional Sweeps", overlay=true, max_lines_count=100)
// =========================================================================
// 1. INPUTS & PARAMETERS
// =========================================================================
// Trend Regime
grp_trend = "Macro Regime Filter"
emaLength = input.int(200, "Baseline EMA", group=grp_trend, tooltip="Defines the overarching market regime.")
// Dynamic Value Area
grp_hma = "HMA Volatility Zone"
hmaLength = input.int(55, "HMA Period", group=grp_hma)
atrLength = input.int(14, "ATR Period (Volatility)", group=grp_hma)
atrMult = input.float(0.75, "ATR Band Multiplier", step=0.25, group=grp_hma, tooltip="Width of the HMA support/resistance zone.")
// Risk Management
grp_risk = "Risk Management"
slAtrMult = input.float(1.5, "Stop Loss ATR Multiplier", step=0.1, group=grp_risk, tooltip="Buffer for stop loss placement below/above the sweep candle.")
// =========================================================================
// 2. CORE CALCULATIONS
// =========================================================================
// Regime
baselineEma = ta.ema(close, emaLength)
// Value Area (HMA + Volatility Bands)
hmaCore = ta.hma(close, hmaLength)
atr = ta.atr(atrLength)
hmaUpper = hmaCore + (atr * atrMult)
hmaLower = hmaCore - (atr * atrMult)
// Market State
bullRegime = close > baselineEma and hmaCore > baselineEma
bearRegime = close < baselineEma and hmaCore < baselineEma
// =========================================================================
// 3. PRICE ACTION LOGIC (THE "SWEEP")
// =========================================================================
// A valid setup requires price to sweep into the volatility band, grab liquidity,
// and then close strongly back over the core HMA, proving institutional defense.
bullishSweep = bullRegime and (low <= hmaLower) and (close > hmaCore) and (close > open)
bearishSweep = bearRegime and (high >= hmaUpper) and (close < hmaCore) and (close < open)
// =========================================================================
// 4. VISUALS & UI
// =========================================================================
// Plot Macro Baseline
plot(baselineEma, "Macro Baseline", color=color.new(color.white, 50), linewidth=2)
// Plot HMA Volatility Zone (The "River")
pHmaU = plot(hmaUpper, "HMA Upper Band", color=color.new(color.gray, 80))
pHmaL = plot(hmaLower, "HMA Lower Band", color=color.new(color.gray, 80))
fill(pHmaU, pHmaL, color=bullRegime ? color.new(color.teal, 85) : bearRegime ? color.new(color.maroon, 85) : color.new(color.gray, 85), title="HMA Zone")
// Plot Core HMA
plot(hmaCore, "HMA Core", color=bullRegime ? color.teal : bearRegime ? color.maroon : color.gray, linewidth=2)
// Setup Highlights
plotshape(bullishSweep, "Long Trigger", style=shape.triangleup, location=location.belowbar, color=color.teal, size=size.small)
plotshape(bearishSweep, "Short Trigger", style=shape.triangledown, location=location.abovebar, color=color.maroon, size=size.small)
// Bar Colors to highlight setups
barcolor(bullishSweep ? color.aqua : bearishSweep ? color.fuchsia : na)
// =========================================================================
// 5. RISK MANAGEMENT (STOP LOSS GENERATION)
// =========================================================================
// Draw a strict invalidation line based on volatility when a signal fires
if bullishSweep
slLevel = low - (atr * slAtrMult)
line.new(bar_index, slLevel, bar_index + 5, slLevel, color=color.red, width=2, style=line.style_solid)
label.new(bar_index + 5, slLevel, "SL", color=color.new(color.red, 80), style=label.style_label_left, textcolor=color.white, size=size.tiny)
if bearishSweep
slLevel = high + (atr * slAtrMult)
line.new(bar_index, slLevel, bar_index + 5, slLevel, color=color.red, width=2, style=line.style_solid)
label.new(bar_index + 5, slLevel, "SL", color=color.new(color.red, 80), style=label.style_label_left, textcolor=color.white, size=size.tiny)
// =========================================================================
// 6. ALERTS (JSON PAYLOADS FOR AUTOMATION)
// =========================================================================
if bullishSweep
alert('{"action": "long", "symbol": "' + syminfo.ticker + '", "price": ' + str.tostring(close) + ', "sl": ' + str.tostring(low - (atr * slAtrMult)) + '}', alert.freq_once_per_bar_close)
if bearishSweep
alert('{"action": "short", "symbol": "' + syminfo.ticker + '", "price": ' + str.tostring(close) + ', "sl": ' + str.tostring(high + (atr * slAtrMult)) + '}', alert.freq_once_per_bar_close)