Indicators/probuilder · probacktest · proorder · proscreener

HistoricVolatility

HistoricVolatility[N](price) in ProBuilder returns annualized historical volatility, the realized variability of log price changes over the last N bars.

Syntax

probuilder
HistoricVolatility[N](price)

Parameters

NameTypeDefaultDescription
NintegernoneNumber of bars in the measurement window, commonly 10, 20, or 100.
priceprice sourcecloseSeries measured, for example close, open, high, or low.

Formula

code
r = LOG(price / price[1])          // logarithmic bar-to-bar return
HistoricVolatility = dispersion of r over N bars, annualized, in percent

The calculation takes the bar-to-bar changes of the series, applies the natural (Napierian) logarithm to stabilize their variance, measures their dispersion over the N-bar window, and scales the result to an annualized percentage.

How it works

Historical, or realized, volatility answers a simple question: how variable have this instrument's returns actually been over the recent past. Log returns are used instead of raw differences because they make up and down moves symmetric and comparable across price levels. Their dispersion over the window is then extrapolated to a yearly figure so that readings from different timeframes share a common unit, percent per year.

The result is backward looking and factual, computed entirely from observed prices. This distinguishes it from implied volatility, which is extracted from option premiums and reflects the market's expectation of future movement. The two often diverge, and the gap between them is itself traded in options markets.

Within strategies, historical volatility serves as a regime measure. Comparing the current reading against its own long-term average classifies the market as calm or turbulent, which can gate entries, scale position sizes, or switch between strategy variants.

Examples

Example 1, Volatility regime with directional bias (Indicator)

probuilder
// 10-period historical volatility of the close
i1 = HistoricVolatility[10](close)

// Long-term average of the volatility itself
i2 = average[100](i1)

// Short-term price average for direction
i3 = average[10](close)

// Signals: elevated volatility plus price position give the bias
IF (i1 > i2 AND Close < i3) THEN
  bearish = -1
  bullish = 0
ELSIF (i1 > i2 AND Close > i3) THEN
  bearish = 0
  bullish = 1
ELSE
  bearish = 0
  bullish = 0
ENDIF

RETURN bearish, bullish

Flags bullish or bearish conditions only when 10-period volatility exceeds its 100-period average, then uses price against a short average for direction. Quiet markets return no signal.

Example 2, Low-volatility compression screener (ProScreener)

probuilder
hv    = HistoricVolatility[20](close)
hvAvg = Average[100](hv)
// Current volatility well below its own long-term norm
SCREENER[hv < hvAvg * 0.5](hv AS "Hist Vol 20")

Returns instruments whose 20-bar realized volatility is less than half its 100-bar average, a compression condition that often precedes range expansion.

Example 3, Volatility gate for a breakout system (ProBacktest)

probuilder
// Trade breakouts only while realized volatility is not extreme
hv     = HistoricVolatility[20](close)
hvCap  = Average[100](hv) * 2
level  = Highest[20](high)[1]

IF NOT LongOnMarket THEN
  IF hv < hvCap AND close > level THEN
    BUY 1 CONTRACT AT MARKET
  ENDIF
ELSE
  IF close < Average[20](close) THEN
    SELL AT MARKET
  ENDIF
ENDIF

Blocks new breakout entries whenever 20-bar volatility exceeds twice its long-term average, avoiding entries into disorderly conditions.

Interpretation

ReadingMeaning
Low and fallingQuiet regime, ranges compress. Breakout traders watch for expansion, option sellers see cheap movement.
RisingMovement is picking up, often around news, breakouts, or trend accelerations.
High and elevatedTurbulent regime, wider stops and smaller positions are typical adjustments.

Volatility is direction-neutral: a crash and a vertical rally both raise it. It also clusters, volatile periods tend to follow volatile periods, and mean-reverts over longer horizons, extremes in either direction tend to normalize. Comparing the current value with the instrument's own history is more informative than any fixed threshold, because normal levels differ widely between markets.

Common errors and gotchas

  • Confusing historical with implied volatility. HistoricVolatility reports what already happened in the price series. Option-derived expectations of future movement are a different quantity and can diverge substantially.
  • Reading direction into the value. High volatility does not mean falling prices, even though the two often coincide in equities. The measure is symmetric with respect to direction.
  • Fixed thresholds across instruments. An annualized 20 percent is calm for a cryptocurrency and extreme for a bond future. Normalize against the instrument's own volatility history, as in the examples.
  • Window too short. Very small N values make the estimate jumpy and dominated by single bars. Stability improves markedly from around 20 bars upward.
  • Volatility, related built-in volatility measure.
  • STD, standard deviation of a series over N bars.
  • AverageTrueRange, range-based volatility in price units.
  • BollingerBandWidth, band width as a volatility proxy.
  • TR, true range of a single bar.
  • LOG, natural logarithm used on the price changes.
  • Average, used to build volatility-of-volatility baselines.
  • MassIndex, range-expansion indicator.