# Stochastic - Percentile

This study calculates and displays the percentile rank of the data specified by the Input Data Input. The ranking is done over a moving window whose size is specified by the Length Input. This study also calculates and displays a moving average of the percentile rank. This indicator was developed by Peter Worden, and is sometimes referred to as a Worden Stochastic.

Let $$X$$ be a random variable denoting the Input Data, and let $$X_t$$ be the value of the Input Data at Index $$t$$. Let the Input Length be denoted as $$n$$.

At Index $$t$$, the $$n$$ values $$X_{t - n + 1},...,X_t$$ of the Input Data are arranged in ascending order and ranked from lowest to highest, starting with a Rank of $$0$$ and going up to a Rank of $$n - 1$$. The Rank of the most recent value of $$X$$ at Index $$t$$ for the given Length is denoted as $$R_t(X,n)$$.

We denote the value of the Stochastic - Percentile at Index $$t$$ for the given Inputs as $$SP_t(X,n)$$, and we compute it for $$t \geq n - 1$$ as follows.

$$SP_t(X,n) = 100\cdot\displaystyle{\frac{R_t(X,n)}{n - 1}}$$ $$\displaystyle{SP_t(X,n) = \left\{\begin{matrix} 0 & t = 0 \\ 100\cdot\frac{R_t(X,t)}{t} & 0 < t < n - 1 \end{matrix}\right .}$$

Let the Moving Average Length Input be denoted as $$n_{MA}$$. Then we denote the Moving Average of Stochastic - Percentile at Index $$t$$ for the given Inputs as $$\overline{SP}_t(X,n,n_{MA})$$, and we compute it in terms of a Simple Moving Average for $$t \geq n - 1$$ as follows.

$$\overline{SP}_t(X,n,n_{MA}) = SMA_t(SP(X,n),n_{MA})$$

In addition to the graphs of $$SP_t(X,n)$$ and $$\overline{SP}_t(X,n,n_{MA})$$, this study also displays two horizontal lines whose levels are determined by the Inputs Line 1 Value and Line 2 Value.