# SuperTrend

This study calculates and displays the SuperTrend Indicator.

Let $$X$$ and $$C$$ be random variables denoting the Input Data and Close Price, respectively, and let $$X_t$$ and $$C_t$$ be their values at Index $$t$$. Let the Inputs ATR Period and ATR Multiplier be denoted as $$n$$ and $$k$$, respectively.

We begin by computing Top Band - Basic and Bottom Band - Basic, whose values at Index $$t$$ are denoted as $$TBB_t^{(ST)}(X,n,k)$$ and $$BBB_t^{(ST)}(X,n,k)$$, respectively. We compute them in terms of the Average True Range as follows.

$$TBB_t^{(ST)}(X,n,k) = X_t + k \cdot ATR(n)$$
$$BBB_t^{(ST)}(X,n,k) = X_t - k \cdot ATR(n)$$

The moving average type is determined by the ATR Moving Average Type Input.

We then calculate the Top Band, $$TB_t^{(ST)}(X,n,k)$$ and Bottom Band, $$BB_t^{(ST)}(X,n,k)$$, as follows.

$$TB_t^{(ST)}(X,n,k) = \left\{ \begin{matrix} TBB_t^{(ST)}(X,n,k) & TBB_t^{(ST)}(X,n,k) < TB_{t - 1}^{(ST)}(X,n,k) \space or \space C_{t - 1} > TB_{t - 1}^{(ST)}(X,n,k) \\ TB_{t - 1}^{(ST)}(X,n,k) & TBB_t^{(ST)}(X,n,k) \geq TB_{t - 1}^{(ST)}(X,n,k) \space or \space C_{t - 1} \leq TB_{t - 1}^{(ST)}(X,n,k) \end{matrix}\right .$$

Finally, we denote the SuperTrend at Index $$t$$ as $$ST_t(X,n,k)$$, and we compute it as follows.

For $$t = 0$$, $$ST_0(X,n,k) = TB_0^{(ST)}(X,n,k)$$. For $$t > 0$$, we have the following. $$ST_t(X,n,k) = \left\{ \begin{matrix} TB_t^{(ST)}(X,n,k) & (ST_{t - 1}(X,n,k) = TB_{t - 1}^{(ST)}(X,n,k) \space and \space C_t < TB_t^{(ST)}(X,n,k)) \space or \space (ST_{t - 1}(X,n,k) = BB_{t - 1}^{(ST)}(X,n,k) \space and \space C_t < BB_t^{(ST)}(X,n,k)) \\ BB_{t - 1}^{(ST)}(X,n,k) & (ST_{t - 1}(X,n,k) = TB_{t - 1}^{(ST)}(X,n,k) \space and \space C_t > TB_t^{(ST)}(X,n,k)) \space or \space (ST_{t - 1}(X,n,k) = BB_{t - 1}^{(ST)}(X,n,k) \space and \space C_t > BB_t^{(ST)}(X,n,k)) \\ ST_{t - 1}(X,n,k) & Otherwise \end{matrix}\right .$$