OPEN-SOURCE SCRIPT

The center of gravity oscillator

Today i propose a more efficient estimation of the center of gravity oscillator, this estimation will only use one convolution, while the original and other estimations use 2. I will also explain everything about the center of gravity oscillator, because even if its name can be imposing its actually super easy to understand.

The CG oscillator is a bandpass filter, in short it filter high frequencies components as well as low frequency ones, this is why the oscillator is both smooth (no high frequencies) as well as detrended (no low frequencies), and therefore the oscillator focus exclusively on the cycles.

Its calculation is simple, its just a linearly weighted moving average minus a simple moving average

If you are familiar with moving averages you'll know that the wma is more reactive than the sma, this is because more recent values have higher weights, and since subtracting a low-pass filter with another one conserve the smoothness while removing low-frequency components, we end up with a bandpass filter, yay!

Elhers explain the idea behind this title with a pretty blurry analogy, so i'll try to give a visual explanation, we said earlier that the center of gravity was simply : wma - sma, ok lets look at their respective impulse responses,

Those are basically the weights of each filters, also called filter coefficients, lets denote the coefficients of the wma as

The coefficients of the wma are therefore centered around 0, but actually there is more to that than a simple title explanation, basically

At this point we could simply get the oscillator by using

Both are symmetrical to each others, and cross at a point, denoted center of linearity. The difference of each responses is :

Using it as coefficients would give us a bandpass filter who would look exactly like the Cg oscillator, this would be calculated as follows in our convolution :

Lets compare our estimate with the CG oscillator,

I this post i explained the calculation of the CG oscillator and proposed an efficient estimation of it by using an original approach. The CG oscillator isn't something complicated to use nor calculate, and is in fact closely related to the rolling covariance between the price and a linear function, so if you want to use the crosses between the center of gravity and 0 you can just use :

The proposed indicator can also use other weightings instead of a linear one, each impulses responses would remain symmetrical.

Check out the indicators we are making at luxalgo: tradingview.com/u/LuxAlgo/

No verdadeiro espírito do TradingView, o autor desse script o publicou como código aberto, para que os traders possam compreendê-lo e analisá-lo. Parabéns ao autor! Você pode usá-lo gratuitamente, mas a reutilização desse código em publicações é regida pelas Regras da Casa. Você pode favoritá-lo para usá-lo em um gráfico.

As informações e publicações não devem ser e não constituem conselhos ou recomendações financeiras, de investimento, de negociação ou de qualquer outro tipo, fornecidas ou endossadas pela TradingView. Leia mais em Termos de uso.