# Schaff Trend Cycle

### Description

This study calculates and displays a Schaff Trend Cycle of the data specified by the Input Data Input.

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 Inputs Length, Short Cycle Length, Long Cycle Length, and Multiplier be denoted as $$n$$, $$n_S$$, $$n_L$$, and $$v$$, respectively. We begin by comuting the MACD, denoted as $$MACD_t(X,n_F,n_S)$$.

Note: The default Moving Average Type used in calculating the MACD is the Exponential Moving Average, but depending on the setting of the Input Moving Average Type, this could be replaced with a Linear Regression Moving Average, a Simple Moving Average, a Weighted Moving Average, a Wilders Moving Average, a Simple Moving Average - Skip Zeros, or a Smoothed Moving Average.

For this study, we use variants of the Fast %K and Fast %D that differ slightly from those found in KD - Fast. We define these functions for a generic random variable below.

For a random variable $$Z$$, the versions of Fast %K and Fast %D used in this study are denoted as $$Fast\% K_t(Z,n)$$ and $$Fast\% D_t(Z,n,v)$$, and they are computed as follows.

$$Fast\% K_t(Z,n)$$ is computed using the Moving Maximum and Moving Minimum functions.

$$\displaystyle{Fast\% K_t(Z,n) = \left\{ \begin{matrix} \frac{Z_t - \min_t(Z,n)}{\max_t(Z,n) - \min_t(Z,n)} & \max_t(Z,n) - \min_t(Z,n) > 0 \\ \frac{Z_{t - 1} - \min_{t - 1}(Z,n)}{\max_{t - 1}(Z,n) - \min_{t - 1}(Z,n)} & \max_t(Z,n) - \min_t(Z,n) \leq 0 \end{matrix}\right .}$$

$$Fast\% D_t(Z,n,v)$$ is computed using a unique averaging procedure.

$$\displaystyle{Fast\% D_t(Z,n,v) = \left\{ \begin{matrix} Fast\% K_t(Z,n) & t = 0 \\ Fast\% D_{t - 1}(Z,n,v) + v \cdot (Z_t - Fast\% D_{t - 1}(Z,n,v)) & t > 0 \end{matrix}\right .}$$

We use these functions to compute Fast %K and Fast %D for the MACD. That is, we compute Fast %K and Fast %D with $$Z = MACD(X,n_S,n_L)$$, as shown below.

$$Fast\% K_t(MACD(X,n_S,n_L),n)$$
$$Fast\% D_t(MACD(X,n_S,n_L),n,v)$$

Next we compute Fast %K of $$Fast\% D_t(MACD(X,n_S,n_L),n,v)$$, as shown below.

$$Fast\% K_t(Fast\% D_t(MACD(X,n_S,n_L),n,v),n)$$

Finally, we compute the Schaff Trend Cycle, which is denoted as $$STC_t(X,n_S,n_L,n,v)$$. This function is the Fast %D of $$Fast\% D_t(MACD(X,n_S,n_L),n,v)$$, as shown below.

$$STC_t(X,n_S,n_L,n,v) = Fast\% D_t(Fast\% D_t(MACD(X,n_S,n_L),n,v),n,v)$$