XR-Squared indicator uses linear regression to determine the presence or absence of a market trend.
XR-Squared line itself together with two levels for trend and flat market are displayed on a chart. Indicator values are set in the range from 0 to 100. When the indicator falls below 30, the market is considered to be flat, and when the indicator rises above 70, a trend is considered to be present. With the development of a trend the XR-Squared line rises from the non-trend up to trend levels. When the market reaches a top and retracement starts, the indicator falls again.
The higher the value of XR-squared, the more likely that a new trend is statistically important. Depending on the period, critical power level of a trend decreases.
Input parameters:
//+-----------------------------------+ //| Indicator input parameters      | //+-----------------------------------+ input int XPeriod=14;                  // Indicator period input Smooth_Method RMethod=MODE_JJMA; // Smoothing method input int RPeriod=3;                   // Smoothing period input int RPhase=100;                  // Smoothing parameter input Smooth_Method SignMethod=MODE_SMA; // Smoothing method input int SignPeriod=14;                // Signal line smoothing period input int SignPhase=15;                  // Smoothing parameter input Applied_price_ IPC=PRICE_CLOSE;   // Applied price input int Shift=0;                      // Horizontal shift of the indicator in bars
This indicator allows to change smoothing method:
- SMA – simple moving average;
- EMA – exponential moving average;
- SMMA – smoothed moving average;
- LWMA – linear weighted moving average;
- JJMA – JMA adaptive average;
- JurX – ultralinear smoothing;
- ParMA – parabolic smoothing;
- T3 – Tillson’s multiple exponential smoothing;
- VIDYA – smoothing with the use of Tushar Chande’s algorithm;
- AMA – smoothing with the use of Perry Kaufman’s algorithm.
It should be noted that Phase type parameters for different smoothing algorithms have completely different meaning. For JMA it is an external Phase variable changing from -100 to +100. For T3 it is a smoothing ratio multiplied by 100 for better visualization, for VIDYA it is a CMO oscillator period and for AMA it is a slow EMA period. In other algorithms these parameters do not affect smoothing. For AMA fast EMA period is a fixed value and is equal to 2 by default. The ratio of raising to the power is also equal to 2 for AMA.
The indicator uses SmoothAlgorithms.mqh library classes (must be copied to the terminal_data_folder\MQL5\Include). The use of the classes was thoroughly described in the article “Averaging Price Series for Intermediate Calculations Without Using Additional Buffers”.