Average Directional Movement Index (ADX)
The Average Directional Movement Index (ADX) is a technical analysis indicator used to determine the strength of a trend.
A reading of 25 or higher indicates a strong trend, while readings below 20 indicate a weak trend.
ADX is calculated by measuring the difference between +DI and -DI, two components of the Directional Movement Index (DX).
The ADX is used by traders to determine when a trend is strong enough to enter or exit a trade.
Calculation
It is derived as the smoothed moving average of the directional movement index (DX)
see here, i. e.
$$ \textrm{ADX}_k = SMA_k[ | \textrm{DX} | ]. $$
Average True Range (ATR)
Average True Range (ATR) is a technical indicator used to measure market volatility.
It is calculated by taking the highest of the following three values: the current high minus the current low,
the absolute value of the current high minus the previous close,
or the absolute value of the current low minus the previous close.
ATR is typically used to identify potential entry and exit points in the stock market, as well as to measure the strength of a trend.
Calculation
The above can be simplified to
\( {TR}_k \) at time \( k \) given by
$$TR_k = \max (\textrm{high}_k, \textrm{close}_{k-1}) - \min (\textrm{low}_k, \textrm{close}_{k-1}). $$
The average true range \(ATR\) is then defined as the
smoothed moving average of \(AT\), i.e.
$$ ATR_k = SMA_k [TR]. $$
Bollinger Bands
Bollinger Bands are a technical analysis tool developed by John Bollinger in the 1980s.
They consist of a set of three curves drawn in relation to price which are used to indicate the volatility of a security.
The middle band is a moving average (MA) of the security's price, while the upper and lower bands are typically two standard deviations away from the MA.
The width of the bands can be used to indicate whether prices are high or low on a relative basis.
Calculation
The middle band \(MB\) is defined as a moving average, i.e.
$$ MB = MA. $$
The upper band \(UB\) and lower band \(LB\) are then defined as
$$ UB_k = MA_k + c \sigma_k $$
$$ LB_k = MA_k - c \sigma_k $$
where \(c\) is the factor of deviation and \(\sigma_k\) is the standard deviation at time \( k \).
The bollinger bands %b is defined as the oscillator which shows where the price is compared to the upper and lower band, i.e.
$$ b_k = \frac{P_k - LB_k}{UB_k - LB_k}. $$
The bollinger bands width is the distance between the upper and lower band, i.e.
$$ W_k = UB_k - LB_k. $$
Candlestick Patterns
Candlestick patterns are a type of chart pattern used in technical analysis to predict future price movements of a financial instrument.
They are created by plotting the open, high, low, and close of a security or currency, and are composed of one or more candlesticks.
Candlestick patterns can be used to identify potential reversals in a security’s price direction, and can also be used to confirm other technical indicators.
Calculation
A candle stick consists if three parts: The real body \(B\), upper shadow \(US\) and lower shadow \(LS\) that are derived from the open, high, low and close prices (OHLC):
$$ B = \max \{O, C\} - \min \{O, C\},$$
$$ US = H - \max \{O, C\},$$
$$ LS = \min \{O, C\} - L.$$
Commodity Channel Index
The commodity channel index (CCI) is an oscillator originally introduced by Donald Lambert in 1980.
Since its introduction, the indicator has grown in popularity and is now a very common tool for traders in identifying cyclical trends not only in commodities but also equities and currencies.
The CCI can be adjusted to the timeframe of the market traded on by changing the averaging period.
Calculation
The price used for the CCI is usually the "Typical price". Given a moving average \(MA \) (usually a simple moving average) and the mean absolute deviation \(MD \) the CCI at time \( k \) is given by
$$ CCI_k = \frac{1}{c} \frac{P_k - MA_k}{MD_k} $$
where \( c \) is the scale factor (usually 0.015).
Directional Movement Index (DX)
The Average directional movement index is an indicator that shows the strength of a trend.
Calculation
It is derived from the positive and negative directional indicator by
$$ \textrm{DX}_k = \frac{\textrm{DI+}_k - \textrm{DI-}_k}{| \textrm{DI+}_k + \textrm{DI-}_k |}. $$
Directional Indicator Plus (DI+)
The positive directional indicator (DI+) is the averaged directional movement normed by the ATR.
Calculation
We first calculate the movement of the price lows and price highs at time \(k \) by
$$ PH_k = \textrm{high}_k - \textrm{high}_{k-1}, PL_k = \textrm{low}_{k-1} - \textrm{low}_{k}. $$
Then the positive and negative directional movements \(DM+\) and \(DM-\) are defined by
$$ \textrm{DM+}_k = \begin{cases} PH_k & , PH_k > 0 \textrm{ and } PH_k \geq PL_k \\
0 & , \textrm{otherwise } \end{cases} $$
$$ \textrm{DM-}_k = \begin{cases} PL_k & , PL_k > 0 \textrm{ and } PL_k \geq PH_k \\
0 & , \textrm{otherwise. } \end{cases} $$
The \( \textrm{DI+} \) is then defined as the smoothed moving average of \( \textrm{DM+} \), i.e.
$$ \frac{\textrm{DI+}_k = 100 * SMA[DM+]}{ATR}. $$
Directional Indicator Minus (DI-)
The negative directional indicator (DI-) is the averaged directional movement normed by the ATR.
Calculation
We first calculate the movement of the price lows and price highs at time \(k \) by
$$ PH_k = \textrm{high}_k - \textrm{high}_{k-1}, PL_k = \textrm{low}_{k-1} - \textrm{low}_{k}. $$
Then the positive and negative directional movements \(DM+\) and \(DM-\) are defined by
$$ \textrm{DM+}_k = \begin{cases} PH_k & , PH_k > 0 \textrm{ and } PH_k \geq PL_k \\
0 & , \textrm{otherwise } \end{cases} $$
$$ \textrm{DM-}_k = \begin{cases} PL_k & , PL_k > 0 \textrm{ and } PL_k \geq PH_k \\
0 & , \textrm{otherwise. } \end{cases} $$
The \( \textrm{DI-} \) is then defined as the smoothed moving average of \( \textrm{DM-} \), i.e.
$$ \frac{\textrm{DI-}_k = 100 * SMA[DM-]}{ATR}. $$
Envelopes
Envelopes consist of two curves, one upper and one lower band. First a moving average (MA) is used. The upper and lower band then are
derived by taking a scale factor that is added or subtracted from the MA.
Calculation
Given an \( MA \)
and a scale factor \( c \), the upper band \( UB \) and lower band \( LB \) are defined as
$$ UB_k = (1+c) * MA_k, $$
$$ LB_k = (1-c) * MA_k. $$
The Envelopes % is the oscillator, defined as
$$ E = \frac{P - LB}{UB - LB}. $$
Lines (Trend/Resistance/Support)
The lines are generated by the local maxima and minima of the price. If the line of the local minima is horizonital it is usually called a
support line. If the line of the local maxima is horizontal it is usually called resistance line. If the angle of the line is big it is usually
called a trendline.
Calculation
For a number of candles \( n \) a price level is called a local maximum if the price is above the n previous and n following prices, i.e.
\( P_k \) is called a local maximum if
$$ P_k = \max \{P_{k-n}, P_{k-n+1}, ..., P_k, P_{k+1}, ..., P_{k+n} \} $$
and it is called a local minimum if
$$ P_k = \min \{P_{k-n}, P_{k-n+1}, ..., P_k, P_{k+1}, ..., P_{k+n} \}. $$
Given the number of maxima and minima \( m \), the upper line \(UL \) is defined as the linear function which approximates the last \( m \)
maxima in the best way, i.e. it minimizes the distance to the maxima in the sense of squared deviation. This means given last \( m \) maxima
\(M_{t_1}, ... ,M_{t_m} \) the line \( UL(t) \) minimizes
$$ \sum_{i = 1}^m | UL(t_i) - M_{t_i} |^2. $$
The same is done for the minima to get the lower line \(LL\). The oscillator is given by
$$ OL = \frac{P - LL}{UL - LL}. $$
Note that the \{OL \} can be lower than zero or above one if the price is below the \(LL\) or above the \(UL \).
MACD
Moving Average Convergence Divergence (MACD) is a trend-following momentum indicator that shows the relationship between two moving averages of prices.
The MACD is used to identify trends.
The MACD signal line is the moving average of the MACD.
When the MACD line crosses above the signal line, it is considered a bullish signal, indicating that the price of the security is likely to increase.
Conversely, when the MACD line crosses below the signal line, it is a bearish signal, indicating that the price is likely to decrease.
Calculation
Given two moving averages \(MA_1\) and \(MA_2\) the \(MACD\) is
$$ MACD = MA_1 - MA_2. $$
The signal line \(S\) is defined as the moving average of the \(MACD\):
$$ S = MA[MACD]. $$
Maximum and Minimum
The maximum and minimum are the local extreme points of the price movement. You can choose between the last extreme points or the relevant extreme points.
The relevant maximum is the last maximum which is bigger than the current price. Analog the relevant minimum is the last minimum which is smaller than the
current price.
Calculation
For a number of candles \( n \) a price level is called a local maximum if the price is above the n previous and n following prices, i.e.
\( P_k \) is called a local maximum if
$$ P_k = \max \{P_{k-n}, P_{k-n+1}, ..., P_k, P_{k+1}, ..., P_{k+n} \} $$
and it is called a local minimum if
$$ P_k = \min \{P_{k-n}, P_{k-n+1}, ..., P_k, P_{k+1}, ..., P_{k+n} \}. $$
Given the maximum \( MAX \) and the minimum \(MIN \) the oscillator is
$$ OL = \frac{P - MIN}{MAX - MIN}. $$
The time since Max/Min is the number of candles between the Max/min and the current price.
Mean Absolute Deviation
Mean absolute deviation is a measure of how spread out a set of data is.
Calculation
Given a moving average \(MA\) then the mean absolute deviation \(MD\) with periodic length \(n\) at time \(k\) is
$$ MD_k = \frac{1}{n} \sum_{i=0}^{n-1} | MA_k - P_{k-i}. | $$
Moving Average
In statistics, a moving average (also known as a rolling average or running average) is a calculation to analyze data points by creating a series of averages of different subsets of the full data set.
Given a series of numbers and a fixed subset size, the first element of the moving average is obtained by taking the average of the initial fixed subset of the number series.
Then, the subset is modified by "shifting forward"; that is, excluding the first number of the series and including the next value in the subset.
A moving average is commonly used with time series data to smooth out short-term fluctuations and highlight longer-term trends or cycles [see Wikipedia].
There are three different types of moving averages supported on this site: simple, exponential, and smoothed.
Calculation
To define the moving average, you need to set the price type and the periodic length. The initial moving average is always calculated as the simple moving average, given by the formula.
$$ MA_{0} = \frac{1}{n} * \sum_{k = -n + 1}^0 p_k $$
where \(MA_{0}\) is the initial moving average. So for example if you choose the daily chart and set 2020-01-01 as the starting point of your backtesting, the initial moving average will be calculated as the simple
moving average of the 2020-01-01 given by the formula above.
In the continuing time series the simple moving average at time \(k\) is given by
$$ SMA_{k} = MA_{k-1} + \frac{1}{n} (p_{k} - p_{k-n}). $$
The exponential moving average at time \(k\) is calculated by
$$ EMA_k = \alpha p_k + (1-\alpha) EMA_{k-1} $$
where \( \alpha = 2 / (1 + n) \) is the smoothing factor.
The smoothing moving average is calculated by
$$ SMMA_k = \alpha p_k + (1-\alpha) SMMA_{k-1} $$
where \( \alpha = 1 / n \) is the smoothing factor.
In the backtester you can choose between different kinds of conditions. For the definition you always need to set the price type, the average time and the periodic length (if you choose
a coniditon with two averages you need to define both).
In the condition area you can for example define the distance between a moving average
and the current price (
Distance Moving Average to Price) where you need to set the interval the solution of the equation \( p - MA \) has to be in. So for example if you set
Price Close, 4, 10 and Pips that means the current close price has to be at least 4 and at most 10 pips above the moving average. If you only set one of the two interval values then that is
the only bound. FOr example if you choose Price Close, 10, , Pips then the condition is satisfied if the price is at least 10 pips above the moving average.
Standard Deviation
Standard deviation is a measure of how much variation or dispersion exists from the average (mean) of a set of data.
It is calculated by taking the square root of the variance, which is the average of the squared differences from the mean.
A larger standard deviation indicates that the data points are spread out over a wider range of values, while a smaller standard deviation indicates that the data points tend to be closer to the mean.
Calculation
The standard deviation \( \sigma \) at time \( k \) is defined as
$$ \sigma_k = \sqrt{\frac{1}{n} \sum_{i = k-n+1}^{k} (p_i - MA_k)^2}. $$
Stochastic Oscillator
The stochastic oscillator is a momentum indicator that uses support and resistance levels. The idea is to look back at the last \( n \) prices,
to determine the highest and lowest value in this time series and to compare the current price to this highest and lowest value. To smooth the results it is
possible to average this values.
Calculation
Formally, the signal at time \( i \) is defined as
$$ S_i = 100 * \frac{p_i - L_k}{H_k - L_k}, $$
where \( L_k \) is the lowest value of the last \( k \) periods and \( H_k \) is the highest value of the last \( k \) periods.
Note that in the definition you can choose whether the highest and lowest values should be determined by using the closing prices or the high/low prices. The stochastic oscillator is then
given by
$$ SO_i = MA_i $$
where \( MA_i \) is the moving average of the \( S \) values at time \( i \) with the periodic length \( \%D \) that you define in the definition.
In contrast to the general idea you can also specify the type of moving average that you want to use.
Relative Strength Index (RSI)
The RSI is classified as a momentum oscillator, measuring the velocity and magnitude of price movements. Momentum is the rate of the rise or fall in price.
The relative strength RS is given as the ratio of higher closes to lower closes, with closes here meaning averages of absolute values of price changes.
The RSI computes momentum as the ratio of higher closes to overall closes: stocks which have had more or stronger positive changes have a higher RSI
than stocks which have had more or stronger negative
changes [
see wikipedia].
Calculation
The updward change \( U \) and the downward change \( D \) at time \( k \) are defined as
$$ U_k = \max \{p_k - p_{k-1}, 0 \} $$
$$ D_k = \max \{p_{k-1} - p_k, 0 \}. $$
Then the moving averages of \( U_k \) and \( D_k \) are calculated. Note that in the definition you can set the type of the average and the periodic length (usually a smoothing moving average is used).
This leads to the relativ stength \( RS \) given by
$$ RS_k = \frac{MA_{U_k}}{MA_{D_k}}. $$
The relative strength index \( RSI_k \) is then given by
$$ RSI_k = 100 - \frac{100}{1 + RS_k}. $$