Welcome Forex EA downloads & MT4/MT5 auto-trading resources — EAs, Gold EAs, quant tools and real-world automation.
Sign In Sign Up

Focus JF Ehlers - MetaTrader 5 Scripts | Trading Script Downloads - MT4/MT5 Resources

author EAcpu | 3 reads | 0 comments |

Center of Gravity J. F. Ehlers - indicator for MetaTrader 5

Center of Gravity J. F. Ehlers - indicator for MetaTrader 5

Center of Gravity J. F. Ehlers - indicator for MetaTrader 5

Center of Gravity J. F. Ehlers - indicator for MetaTrader 5

Center of Gravity J. F. Ehlers - indicator for MetaTrader 5

Center of Gravity J. F. Ehlers - indicator for MetaTrader 5

The center of gravity has virtually zero lag and allows for precise definition of turning points. This indicator is the result of Eller's research on adaptive filters.

The Center of Gravity indicator identifies major pivot points with virtually no lag.

The idea of ​​calculating the center of gravity emerged from studies of the hysteresis of different filters with finite impulse responses (FIR) in terms of the relative amplitudes of the filter coefficients. SMA ( Simple Moving Average ) is a FIR filter in which all coefficients have one and the same value. Therefore, the center of gravity of the SMA is exactly the center of the filter. WMA ( Weighted Moving Average ) is a FIR filter where the last price changes are weighted by the filter length and so on.

The weighted values ​​are the coefficients of the filter. The coefficients of a WMA filter can be represented as the outline of a triangle. The center of gravity is located at 1/3 of the base length of the triangle. Therefore, the WMA center of gravity moves to the right relative to the SMA center of gravity of the same length, which gives us a smaller lag. For all examples using FIR filters, the sum of the products of the coefficients and the price must be divided by the sum of the coefficients to preserve the original price.

The most famous of this type of FIR filters is the Ehlers filter, which can be expressed in the following way:

Center of Gravity J. F. Ehlers - indicator for MetaTrader 5

To quote from the article:

"The coefficients of the Ehlers filter can be almost any variability measure. I looked at momentum, signal-to-noise ratio, volatility, and even stochastics and RSI values ​​as filter coefficients. The most adaptable set of coefficients comes from the video edge detection filter, which is the sum of the squares of the difference of each price from every previous price. Regardless, the result of using different filter coefficients is to make the filter adaptive by moving the CG of the coefficients.

When I was debugging the code for the adaptive FIR filter, I noticed that the CG itself moved in the exact opposite direction of the price fluctuations. When prices rise, CG moves to the right; when prices fall, CG moves to the left. Measured as distance from the nearest price, CG decreases when prices rise and increases when prices fall. All I had to do was invert the sign of CG to get a smooth oscillator that was in phase with the price movements and had essentially zero lag. "

The center of gravity is calculated using the Ehlers filter using the following formula:

Center of Gravity J. F. Ehlers - indicator for MetaTrader 5

In this indicator, the Period_ parameter sets the period for which the indicator is calculated, and the AppliedPrice parameter sets the price type according to which the indicator is calculated - this way we get the main line of the indicator (continuously changing color).

For the signal line (blue dotted line), the SmoothPeriod parameter sets the period of the smoothed main indicator line, and the SmoothType parameter indicates the smoothing type. The explanation of parameter values ​​is given in the form of comments in the indicator code.

The indicator uses the СMoving_Average class of the SmoothAlgorithms.mqh library. How to use this class is described in detail in the article "Average price series for intermediate calculations without using additional buffers" .

The indicator was first implemented in MQL4 and published in the code base on February 20, 2007.

Center of Gravity J. F. Ehlers - indicator for MetaTrader 5


Attachment download

📎 centerofgravity.mq5 (7.99 KB)

📎 smoothalgorithms.mqh (133.8 KB)

Source: MQL5 #442

Verification code Refresh