# Stochastic Function

This study calculates and displays a Stochastic Function and Trigger Line for the data given by the Input Data Input. This study is an ACSIL implementation of the Stochastic functions described Chapter 8 of the book Cybernetic Analysis for Stocks and Futures by John Ehlers.

Let $$X$$ be a random variable denoting the Input Data, and let the Length Input be denoted as $$n$$.

Note: This study is not meant to be applied to Price Data. It is meant to be applied to an oscillator.

To apply the Stochastic Function, take the following steps.

• Add the desired oscillator study to a chart.
• Add the Stochastic Function study to a chart.
• Select the Stochastic Function study in the Studies to Graph section of the Chart Studies window and click Settings.
• In the Study Settings window for the Stochastic Function, go to Based On and select the oscillator.
• For the Input Value of the Input Data, select the Subgraph corresponding to the oscillator.
• In the Study Settings window, click OK.
• In the Chart Studies window, click OK.

We begin by computing the Stochastic Ratio of the Input Data, $$StochRat_t(X,n)$$.

Then we compute a smoothed Stochastic Ratio, denoted as $$StochRat_t^{(S)}(X,n)$$, which we compute as follows.

$$\displaystyle{StochRat_t^{(S)}(X,n) = \frac{1}{10}\sum_{j = 1}^4 j \cdot StochRat_{t - 4 + j}(X,n)}$$

We then compute the Stochastic Function for the oscillator, denoted as $$X^{(Stoch)}_t(n)$$, as follows.

$$X^{(Stoch)}_t(n) = 2\left(StochRat_t^{(S)}(X(n),n) - 0.5\right)$$

The Trigger Line for this Indicator is given below.

$$Trig^{(SX)}_t(X,n) = 0.96\left(X^{(Stoch)}_{t - 1}(n) + 0.02\right)$$