Below is the formula of the %R indicator calculation, which is very similar to the Stochastic Oscillator formula:
%R = -(MAX (HIGH (i - n)) - CLOSE (i)) / (MAX (HIGH (i - n)) - MIN (LOW (i - n))) * 100
Where:
CLOSE (i) — today's closing price;
MAX (HIGH (i - n)) — the highest maximum over a number (n) of previous periods;
MIN (LOW (i - n)) — the lowest minimum over a number (n) of previous periods.