OPEN-SOURCE SCRIPT

Center Of Linearity - A More Efficient Alternative To Elhers CG

Introduction

The center of gravity oscillator (CG) is one of the oscillators presented in Elhers book "cybernetic analysis for stocks and futures". This oscillator can be described as a bandpass filter centered around 0, its simplicity is ridiculous yet this indicator managed to get a pretty great popularity, this might be due to Elhers saying that he has substantial advantages over conventional oscillators used in technical analysis.

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 Center Of Gravity Oscillator

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 wma - sma, this is not what is showcased in its book, but the result is just the same, the only thing that change is the scale, this is why some estimates have a weird scale that is not centered around 0, the output is technically the same but the scale isn't, however the scale of an oscillator isn't a big deal as long as the oscillator is centered around 0 and we don't plan to use it as input for overlay indicators.

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!

Why "Center" Of Gravity ?

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 a and the coefficients of the moving average as b. So whats the meaning behind center of gravity ? We basically want to "center" the weights of the wma, this can be done with a - b

快照

The coefficients of the wma are therefore centered around 0, but actually there is more to that than a simple title explanation, basically a - b = c, where c are the coefficients of the center of gravity bandpass filter, therefore if we where to apply convolution to the price with c, we would get the center of gravity oscillator. Thats the thing with FIR filters, we can use convolution for describing a lot of FIR systems, and the difference between two impulse responses of two low-pass filters (here wma, sma) give us the coefficients of a bandpass filter.

The Center Of Linearity

At this point we could simply get the oscillator by using length/2 - i as coefficient, however in order to propose a more interesting variation i decided to go with a less efficient but more original approach, the center of linearity. Imagine two convolutions :

a = i*src[length-i] and b = i*src[i-1]

a only has a reversed index length-i, and is therefore describe a simple wma. Both convolutions give the following impulse responses :

快照

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 :

i*src[length-i]-i*src[i-1]) = i*(src[length-i]-src[i-1])

Lets compare our estimate with the CG oscillator,

快照

Conclusion

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 : correlation(close,bar_index,length) instead, thats basically the same.

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


Centered OscillatorscenterofgravityCOGelhersOscillators

开源脚本

本着真正的TradingView精神,此脚本的作者已将其开源,以便交易者可以理解和验证它。向作者致敬!您可以免费使用它,但在出版物中重复使用此代码受网站规则约束。 您可以收藏它以在图表上使用。

想在图表上使用此脚本?


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

免责声明