WiseTrader Toolbox

VariablePeriodRSI

Background

The Relative Strength Index (RSI) is one of the best-known momentum oscillators. Over a look-back window it compares the size of recent gains with recent losses and scales the result to run from 0 to 100, which traders use to flag overbought and oversold conditions and momentum divergences.

A standard RSI uses one fixed look-back. VariablePeriodRSI takes a period for each bar instead, so the window can adapt to the market. As a result the calculation is not identical to the RSI built into AmiBroker, which uses an exponential approach that refines the indicator over time; the adaptive-period approach is useful because the number of periods can be adjusted based on volume, volatility, cycles and other factors. The per-bar periods most often come from an adaptor such as the DominantCycle.

Included formula

The toolbox ships a ready-made Adaptive Smoothed RSI indicator built on this function, so you can use it without writing any code. In AmiBroker open the Charts window, expand the WiseTraderToolbox group and drag Adaptive Smoothed RSI onto a chart.

It plots the RSI in its own pane below price, with optional overbought/oversold threshold lines and a signal line. A built-in system marks buys and sells — you choose whether they come from the signal-line crossovers or from the RSI crossing the thresholds — and the same formula can be run as an Exploration from the Analysis window to scan a watchlist for the latest signal. The Adaptor you pick produces the per-bar period this function needs, an optional Smoother cleans up the input first, and the colours, thresholds and bounds are all adjustable.

The exported function

If you would rather build your own formula, the toolbox exports the calculation as a single AFL function you can call directly — it is the engine inside that indicator.

VariablePeriodRSI(Price, Periods)
ParameterDescription
Price The price array the indicator should be calculated on.
Periods An array (or value) containing the period to use for the RSI calculation at each bar. Most often this is fed from an adaptor such as the DominantCycle.
periods = DominantCycle( Close );
myRSI = VariablePeriodRSI( Close, periods );
Plot( myRSI, "Adaptive RSI", colorRed );