San Luis Obispo, CA USA
Experience: Master
Platform: TradeStation
Trading: ES
Posts: 1 since Jul 2013
Thanks Given: 0
Thanks Received: 1
|
The Center of Gravity indicator topic came up during my webinar last week, and I did a poor job of explaining it. My COG indicator does not change over history. Once it is computed, that value is "sticky". Perhaps an analogy of a teeter-totter is best used to understand it. Rising prices drive the balance point up, and falling prices drive the balance point down. The center of gravity is the balance point of the teeter-totter. Here is the EasyLanguage code in case something has been lost in translation over the years: (don't forget that EasyLanguage uses the argument of the Cosine in degrees. You need to convert 360 to 2*Pi in other languages.
John Ehlers
Inputs:
Length(10);
Vars:
alpha1(0),
HP(0),
a1(0),
b1(0),
c1(0),
c2(0),
c3(0),
Filt(0),
HighestC(0),
LowestC(0),
count(0),
Num(0),
Denom(0),
CG(0);
//Highpass filter cyclic components whose periods are shorter than 48 bars
alpha1 = (Cosine(.707*360 / 48) + Sine (.707*360 / 48) - 1) / Cosine(.707*360 / 48);
HP = (1 - alpha1 / 2)*(1 - alpha1 / 2)*(Close - 2*Close[1] + Close[2]) + 2*(1 - alpha1)*HP[1] - (1 - alpha1)*(1 - alpha1)*HP[2];
//Smooth with a Super Smoother Filter from equation 3-3
a1 = expvalue(-1.414*3.14159 / Length);
b1 = 2*a1*Cosine(1.414*180 / Length);
c2 = b1;
c3 = -a1*a1;
c1 = 1 - c2 - c3;
Filt = c1*(Close + Close[1]) / 2 + c2*Filt[1] + c3*Filt[2];
Num = 0;
Denom = 0;
For count = 0 to Length - 1 begin
Num = Num + (1 + count)*(Filt[count]);
Denom = Denom + (Filt[count]);
End;
If Denom <> 0 then CG = -Num/Denom + Length / 2 + .5;
Plot1(CG, "CG");
Plot2(0);
|