# Stochastic RSI

This staudy calculates and displays the Stochastic RSI for Close (Last) Price data. The RSI is used in the calculation.

Let $$C$$ be a random variable denoting the Close Price, and let $$C_t$$ be the value of the Close Price at Index $$t$$. Then the RSI of $$C$$ with RSI Length $$n_{RSI}$$ at Index $$t$$ is denoted as $$RSI_t(C,n_{RSI})$$, and it is calculated in terms of a Simple Moving Average for $$t \geq n_{RSI} - 1$$.

Note: Depending on the setting of the Input Average Type, the Simple Moving Averages in the calculations of $$RS_t\left(X,n_{RSI}\right)$$ and $$\overline{RSI}_t(RSI(X,n_{RSI}),n)$$ could be replaced with Exponential Moving Averages, Linear Regression Moving Averages, Weighted Moving Averages, Wilders Moving Averages, Simple Moving Averages - Skip Zeros, or Smoothed Moving Averages. The types of all three Moving Averages in the calculation are determined by this one Input.

Let the RSI HighestLowest Length Input be denoted as $$n_{HL}$$. We denote the Stochastic RSI for the given Inputs at Index $$t$$ as $$RSI^{(Stoch)}_t\left(n_{RSI},n_{HL}\right)$$, and we compute it for $$t \geq n_{RSI} + n_{HL} - 1$$ in terms of the Moving Maximum and the Moving Minimum of $$RSI_t(C,n_{RSI})$$ over the last $$n_{HL}$$ bars as follows.

$$\displaystyle{RSI^{(Stoch)}_t\left(n_{RSI},n_{HL}\right) = \left\{ \begin{matrix} \frac{RSI_t(C,n_{RSI}) - \mathrm{min}_t\{RSI_t(C,n_{RSI}),n_{HL})\}}{\mathrm{max}_t\{RSI_t(C,n_{RSI}),n_{HL})\} - \mathrm{min}_t\{RSI_t(C,n_{RSI}),n_{HL})\}} & \mathrm{max}_t\{RSI_t(C,n_{RSI}),n_{HL})\} - \mathrm{min}_t\{RSI_t(C,n_{RSI}),n_{HL}) \neq 0 \\ RSI^{(Stoch)}_{t - 1}\left(n_{RSI},n_{HL}\right) & \mathrm{max}_t\{RSI_t(C,n_{RSI}),n_{HL})\} - \mathrm{min}_t\{RSI_t(C,n_{RSI}),n_{HL}) = 0 \end{matrix}\right .}$$