To successfully scalp XAG/USD (Silver), you need an indicator that accounts for its unique characteristics: higher intraday volatility, wider relative spreads compared to major currency pairs, and sharp momentum bursts that often trap breakout traders.Standard moving averages or default oscillators (like a 14-period RSI) are often too slow or generate excessive false signals on 1-minute (M1) or 5-minute (M5) charts.Below is a complete, production-ready Pine Script v5 custom indicator for TradingView, tailored specifically for XAG/USD scalping. It combines a Hull Moving Average (HMA) for low-lag trend tracking with an ATR-based Volatility Band (Keltner-style) to filter out choppy market noise and highlight explosive breakout windows. Custom Pine Script v5 Code: XAG Scalp Pro EngineOpen your TradingView chart, go to the Pine Editor tab at the bottom, paste the code below, and click "Add to Chart".
Code: Select all
//@version=5
indicator("XAG Scalp Pro Engine", overlay=true, precision=3)
// --- INPUTS ---
// Core Trend Settings
hmaSource = input.source(close, title="HMA Source")
hmaLength = input.int(9, title="HMA Period (Fast Trend)", minval=1)
// Volatility & Filter Settings
atrLength = input.int(14, title="ATR Length for Bands")
atrMult = input.float(1.5, title="ATR Multiplier (Width)", step=0.1)
// Session Filters (UTC default, adjust to your broker time - e.g., London/NY overlap)
useSession = input.bool(true, title="Filter by Active Trading Session?")
tradeSession= input.session("0700-1600", title="Active Session (UTC)")
// --- CALCULATIONS ---
// 1. Hull Moving Average for lightning-fast direction without lag
f_hma(src, length) =>
ta.wma(2 * ta.wma(src, length / 2) - ta.wma(src, length), math.round(math.sqrt(length)))
trendLine = f_hma(hmaSource, hmaLength)
// 2. Trend Direction Determination
isBullish = trendLine > trendLine[1]
isBearish = trendLine < trendLine[1]
// 3. ATR Volatility Bands for Breakout / Pullback detection
atrValue = ta.atr(atrLength)
upperBand = trendLine + (atrValue * atrMult)
lowerBand = trendLine - (atrValue * atrMult)
// 4. Session Time Check
inSession = not useSession or not na(time(timeframe.period, tradeSession + ":234560"))
// --- SIGNAL GENERATION ---
// Scalp triggers: Price piercing the volatility band while HMA changes direction
longSignal = ta.crossover(close, lowerBand) and isBullish and inSession
shortSignal = ta.crossunder(close, upperBand) and isBearish and inSession
// --- PLOTTING ---
// Plot HMA Trend Line
barColor = isBullish ? color.green : color.red
plot(trendLine, title="Fast HMA", color=barColor, linewidth=2)
// Plot ATR Volatility Channels
uPlot = plot(upperBand, title="Upper Volatility Band", color=color.new(color.blue, 50))
lPlot = plot(lowerBand, title="Lower Volatility Band", color=color.new(color.blue, 50))
fill(uPlot, lPlot, color=color.new(color.blue, 95), title="Channel Background")
// Visual Chart Signals
plotshape(longSignal, title="Scalp Buy", location=location.belowbar, style=shape.triangleup, size=size.small, color=color.green, text="BUY")
plotshape(shortSignal, title="Scalp Sell", location=location.abovebar, style=shape.triangledown, size=size.small, color=color.red, text="SELL")
// --- ALERTS ---
alertcondition(longSignal, title="XAG Scalp BUY Alert", message="XAG/USD Bullish Scalp Setup Triggered!")
alertcondition(shortSignal, title="XAG Scalp SELL Alert", message="XAG/USD Bearish Scalp Setup Triggered!")