Daily Range Percentage Tracker with Alerts
A trader needs to know whether today's price movement is typical or exceptional. The Daily Range Percentage Tracker measures the daily high-low range as a percentage of the close price, plots its moving average, and raises alerts when the current range deviates significantly from the norm. This helps scalpers, day traders and swing traders quickly spot volatility spikes or compression without recalculating by hand.
//@version=6
indicator("Daily Range % Tracker with Alerts", overlay=false)
// Input parameters
periodLength = input.int(20, title="ATR Period", minval=2, maxval=200)
smaLength = input.int(20, title="Range SMA Period", minval=2, maxval=200)
alertThreshold = input.float(1.5, title="Alert Multiplier (sigma above avg)", minval=0.5, maxval=5.0, step=0.1)
showBands = input.bool(true, title="Show Upper/Lower Bands")
// Calculate daily range as percentage of close
dailyHigh = high
dailyLow = low
dailyClose = close
rangePoints = dailyHigh - dailyLow
rangePercent = (rangePoints / dailyClose) * 100
// Calculate ATR-based reference (optional alternate calculation)
atrValue = ta.atr(periodLength)
atrPercent = (atrValue / dailyClose) * 100
// Moving average of range percentage
rangeMA = ta.sma(rangePercent, smaLength)
// Standard deviation of range percentage (for bands)
rangeStdDev = ta.stdev(rangePercent, smaLength)
// Upper and lower bands for alert threshold
upperBand = rangeMA + (rangeStdDev * alertThreshold)
lowerBand = math.max(0, rangeMA - (rangeStdDev * alertThreshold))
// Alert conditions
highRangeAlert = rangePercent > upperBand
lowRangeAlert = rangePercent < lowerBand
// Plots
plot(rangePercent, title="Current Range %", color=color.blue, linewidth=2)
plot(rangeMA, title="Range MA", color=color.orange, linewidth=2)
plot(rangeMA + rangeStdDev, title="Mean + 1σ", color=color.gray, linewidth=1, style=plot.style_dashed)
plot(math.max(0, rangeMA - rangeStdDev), title="Mean - 1σ", color=color.gray, linewidth=1, style=plot.style_dashed)
// Conditional band plots for alert thresholds
bandColor = rangePercent > upperBand ? color.new(color.red, 40) : rangePercent < lowerBand ? color.new(color.green, 40) : color.new(color.gray, 80)
bgcolor(showBands ? bandColor : na)
// Alert function calls
alertcondition(highRangeAlert, title="High Range Alert", message="Daily range exceeds {0}% threshold", tooltip="Current: " + str.tostring(rangePercent, "#.##") + "% | Threshold: " + str.tostring(upperBand, "#.##") + "%")
alertcondition(lowRangeAlert, title="Low Range Alert", message="Daily range below {0}% threshold", tooltip="Current: " + str.tostring(rangePercent, "#.##") + "% | Threshold: " + str.tostring(lowerBand, "#.##") + "%")
How the code works
The indicator calculates the daily range (high minus low) and expresses it as a percentage of the closing price, making range sizes comparable across instruments at different price levels. Line 12 computes this directly: (high, low) / close * 100.
The script then applies a simple moving average (SMA) to the range percentage over the user-specified period (default 20 bars), smoothing out noise to reveal the typical range. This moving average becomes the centerline for normal behavior.
Standard deviation of the range percentage is calculated around the SMA. The deviation measures how much individual daily ranges typically deviate from the average. Multiplying the standard deviation by the alert threshold parameter (default 1.5 sigma) creates dynamic upper and lower bands that tighten during low-volatility periods and widen during high-volatility ones.
The alerts trigger whenever the current day's range percentage crosses these bands. High range alerts fire when the range exceeds the upper band; low range alerts fire when compression drops below the lower band. Both conditions are calculated once per bar close.
The background color shifts based on alert state: red tint when range is abnormally high, green when abnormally low, and gray when normal, providing immediate visual feedback without looking at exact numbers.
Reading it on a chart
The blue line shows today's actual range percentage; the orange line shows the rolling average of typical ranges for the instrument. When blue is well above orange, volatility is picking up relative to normal. When blue drops below the average, the market is consolidating. The dashed gray lines mark one standard deviation above and below the mean, showing the range of normal variation.
A trader watching for breakout setups looks for the blue line to spike through the upper band, signaling that sellers (or buyers) have pushed price further than usual. Scalpers watching for range-bound trades look for the blue line to drop below the lower band, suggesting the market is tightening for a potential squeezing move. The colored background reinforces the state: red zones are expansion, green zones are compression.
Alerts fire at the bar close, so a trader can be notified immediately if today closes with an unusually wide or narrow range, even without watching the chart in real time. The alert tooltip includes the current range percentage and the band threshold, avoiding guesswork.
Limitations
The indicator measures historical range variation and assumes past volatility patterns predict future behavior. Markets that undergo structural shifts in volatility, earnings announcements, economic data releases, or sudden liquidity drains, can render the average and bands stale within seconds. The SMA responds slowly to regime changes; a sharp spike in volatility may not widen the band until many bars after the move begins.
Standard deviation assumes a normal distribution of ranges, which does not hold in real markets; extreme range events (flash crashes, limit moves) occur far more frequently than a normal distribution would predict. The alert threshold multiplier is arbitrary. A 1.5 sigma setting works for some instruments and timeframes but may produce too many false alerts on stocks with naturally high variance or too few on stable currencies. Traders must tune this parameter for their market.
The indicator does not distinguish between intraday spikes that reverse within the day and true trending moves. A large range early in the session might collapse by close, yet still trigger a "high range" alert. The percentage basis masks absolute move magnitude: a 2% range on a 500-point index is very different from a 2% range on a 50-point stock, yet both alert identically.
Finally, the script calculates ranges on a fixed daily timeframe. Intrabar traders using 5- or 15-minute charts will see smoothed historical daily ranges that do not capture intraday volatility variation within that day. Using this indicator on sub-daily timeframes requires manual interpretation of the historical context.
Key definitions
ATR (Average True Range): A technical indicator that measures market volatility by calculating the average of "true ranges" over a specified period, where true range accounts for gaps. [1]
Range Percentage: The daily high-low spread expressed as a percentage of the closing price, allowing comparison of price movement magnitude across different price levels and instruments.
Standard Deviation: A statistical measure of dispersion that quantifies how far individual data points (in this case, daily range percentages) deviate from their mean; wider bands indicate more historical variability.
Sigma: In statistical notation, sigma (σ) refers to standard deviation; "1.5 sigma" means 1.5 times the standard deviation.
Regime Change: A sudden structural shift in market behavior, such as a spike in correlation, volatility, or liquidity, that invalidates assumptions built on recent history.
Scalp: A trading style that seeks small profits from brief holding periods, typically minutes to minutes within a single day, relying on tight stop losses and quick exits.
References
- Wilder, J.W., "New Concepts in Technical Trading Systems," Trend Research Ltd (1978).
- CME Group, "Volatility Measurement and Trading," Especially section on ATR and historical volatility. Https://www.cmegroup.com/education/
- Investopedia, "Average True Range (ATR)," https://www.investopedia.com/terms/a/atr.asp
- Brownlee, J., "A Gentle Introduction to Probability Distribution," Machine Learning Mastery (2019). Https://machinelearningmastery.com/
- SEC Office of Investor Education, "Volatility Basics," https://www.sec.gov/investor/
Educational research on historical data only. Not investment advice, not a signal, and never a performance promise. Past results do not predict future performance. Every reference is link-verified before publication and every paper is re-audited weekly against the library's editorial standard.
Last reviewed by the PropLedger research pipeline: 2026-09-27. Educational research on historical data, not financial advice.
Keep reading
Pivot Points: Floor Trader vs. Camarilla Comparison
Free open-source Pine Script indicator: pivot points: floor trader vs Camarilla comparison. Full code and a plain-English walkthrough.
Trend Day vs Range Day Classifier
Free open-source Pine Script indicator: trend day vs range day classifier (early session heuristics). Full code and a plain-English walkthrough.
Consecutive Close Counter with Streak Statistics
Free open-source Pine Script indicator: consecutive close counter with streak statistics table. Full code and a plain-English walkthrough.