MetaTrader5
Mastering the Center of Gravity Indicator for MetaTrader 5
Author: Rosh
If you're looking to sharpen your trading game, the Center of Gravity (CoG) indicator is a tool you won't want to overlook. This nifty indicator boasts zero lag, helping you pinpoint turning points with remarkable precision. Developed from J.F. Ehlers' research into adaptive filters, it's designed to give you an edge in your trading strategy.
The Center of Gravity makes it easy to identify key pivot points almost instantly, eliminating the frustration of lagging indicators.
Understanding the Center of Gravity
The concept of calculating a center of gravity stems from analyzing lags in various finite impulse response (FIR) filters, specifically in relation to the relative amplitude of their coefficients. Take the Simple Moving Average (SMA), for instance; it's a basic FIR filter where all coefficients hold the same value, making the center of gravity perfectly centered within the filter.
On the other hand, the Weighted Moving Average (WMA) is a bit more complex, as it weighs the latest price changes according to the filter's length. This creates a different dynamic.
How It Works
In terms of weighting, think of the coefficients of WMA filters as the contours of a triangle. The center of gravity rests at one-third the length of the triangle's base, which shifts the WMA's center of gravity to the right compared to that of the SMA. This results in reduced lag, allowing for quicker responses to price movements.
To maintain original price values, the sum of the products of the coefficients and the price must be divided by the sum of the coefficients. One of the most recognized FIR filters is Ehlers' filter, which can be represented as follows:
A Quick Quote from Ehlers:"The coefficients of the Ehlers Filter can be almost any measure of variability. I have looked at momentum, signal to noise ratio, volatility, and even Stochastics and RSI values as filter coefficients. One of the most adaptive sets of coefficients arose from video edge detection filters, using the sum of the square of the differences between each price and its previous price. I noticed that the CG moved in exact opposition to price swings, providing a smoothed oscillator with essentially zero lag when inverted."
Calculating the Center of Gravity
The Center of Gravity is computed similarly to Ehlers' filter, using a specific formula:
In this indicator, the Period_ parameter sets the calculation period, while the AppliedPrice parameter determines the price type that forms the main indicator line (which will change color).
For the signal line (the blue dotted line), the SmoothPeriod parameter controls the smoothing of the main line, and the SmoothType parameter specifies the smoothing method. You’ll find interpretations of these parameters in the comments within the indicator code.
This indicator utilizes the CMoving_Average class from the SmoothAlgorithms.mqh library, which is detailed in the article "Averaging Price Series for Intermediate Calculations Without Using Additional Buffers".
The CoG indicator was first implemented in MQL4 and made its debut in CodeBase on February 20, 2007.
2011.08.18