Indicators/probuilder · probacktest · proorder · proscreener

Variation

Variation in ProBuilder returns the percentage change of a price series between the previous bar and the current bar. Syntax, formula and worked examples.

Syntax

probuilder
Variation(price)

Parameters

NameTypeDefaultDescription
priceprice sourcenoneSeries whose one-bar percentage change is returned. Accepts close, open, high, low or any custom variable.

Formula

code
Variation = 100 * (price - price[1]) / price[1]

The result is a signed percentage: positive when the series is higher than on the previous bar, negative when lower, zero when unchanged.

How it works

On each bar, the function compares the current value of the given series with its value one bar earlier and expresses the difference as a percentage of the earlier value. It is the single-bar special case of a rate of change; ROC generalises the same idea to an N bar lookback.

Because the output is a percentage, it is directly comparable across instruments with different price levels, which raw differences are not. A 2 percent daily move means the same thing on an index at 18000 and a stock at 40. This makes Variation a natural building block for screeners that rank markets by daily movement, and for volatility work: the standard deviation of one-bar variations is a simple realised volatility estimate.

The series is noisy by construction, every bar produces a new independent reading. Smoothing it with a moving average, or banding it with a standard deviation channel as in the first example, separates ordinary fluctuations from statistically unusual moves.

Examples

Example 1, Variation with an adaptive threshold band (Indicator)

probuilder
// One-bar percentage change of the high price
var = Variation(high)
// Smooth the changes, then build a 3 standard deviation band around them
averagingvar = 3 * STD[20](exponentialaverage[20](var))
RETURN var, averagingvar

Plots the bar-to-bar percentage change of the highs together with a threshold equal to three standard deviations of its smoothed values. Bars where var exceeds the band mark abnormally large moves.

Example 2, Daily movers scan (ProScreener)

probuilder
chg = Variation(close)
SCREENER[ABS(chg) > 3] (chg AS "Change %")

Returns instruments whose close moved more than 3 percent in either direction on the current bar, with the signed change shown as the ranking column.

Example 3, Momentum entry with a change filter (ProBacktest)

probuilder
// Enter on a strong up bar, exit on a meaningful down bar
chg = Variation(close)

IF NOT ONMARKET AND chg > 1.5 THEN
  BUY 1 CONTRACT AT MARKET
ENDIF
IF ONMARKET AND chg < -1 THEN
  SELL AT MARKET
ENDIF

The system buys after a bar that gained more than 1.5 percent and closes the position after any bar that lost more than 1 percent, a minimal example of percentage-change based logic.

Interpretation

Positive values indicate the series rose over the last bar, negative values that it fell; the magnitude measures how sharply. There are no universal thresholds, what counts as a large one-bar change depends on the instrument and timeframe. A practical approach is statistical: compare the current reading against the recent distribution of readings, for example flagging values beyond two or three standard deviations. Clusters of large absolute variations indicate a high-volatility regime, long runs of small values indicate consolidation.

Common errors and gotchas

  • One bar only. Variation always compares against the immediately previous bar. For a change over N bars use ROC[N](price) or compute 100 * (close - close[N]) / close[N] explicitly.
  • Timeframe dependence. The function measures change per bar of the current chart. On a 5-minute chart the values are naturally far smaller than on a daily chart, thresholds do not transfer between timeframes.
  • Division base is the previous bar. A 10 percent drop followed by a 10 percent rise does not return to the starting price. Summing variations over many bars only approximates the total move.
  • First bar is undefined. The calculation needs price[1], which does not exist on the first bar of loaded history. Ignore the earliest reading.
  • ROC, rate of change over an arbitrary N bar lookback.
  • Momentum, absolute price difference over N bars.
  • STD, standard deviation, used to band variation readings.
  • ExponentialAverage, smoothing for the noisy raw series.
  • Average, simple moving average alternative for smoothing.
  • VolumeROC, the same rate of change idea applied to volume.
  • HistoricVolatility, statistical volatility from price returns.
  • Volatility, Chaikin Volatility built on the high-low spread.