Back to TS code links
    Fisher Stochastic CG Oscillator from John Ehlers
Back to Ehlers links


Anyone using information or codes on these pages does so at their own risk - no guarantees of stability or profitability are claimed. These codes are all for testing purposes only.

//// Ehlers Fisher Stochastic CG (Center of Gravity) indicator/oscillator
//// From 'Cybernetic Analysis for Stocks and Futures' by John Ehlers
//// code compiled by dn

Inputs: Price((H+L)/2),
Length(8);
Vars: count(0),
Num(0),
Denom(0),
CG(0),
MaxCG(0),
MinCG(0);
Num = 0;
Denom = 0;
For count = 0 to Length - 1 begin
Num = Num + (1 + count)*(Price[count]);
Denom = Denom + (Price[count]);
End;
If Denom <> 0 then CG = -Num/Denom + (Length + 1) / 2;
MaxCG = Highest(CG, Length);
MinCG = Lowest(CG, Length);
If MaxCG <> MinCG then Value1 = (CG - MinCG) / (MaxCG - MinCG);
Value2 = (4*Value1 + 3*Value1[1] + 2*Value1[2] + Value1[3]) / 10;

Value3 = .5*Log((1+1.98*(Value2-.5))/(1-1.98*(Value2-.5)));

Plot1 (Value3, "CG");
Plot2(Value3[1], "Trigger");
Plot3(0, "Ref");

{
//// Stochastic CG Oscillator coded by mmillar, July 2004 - same results displayed as above code
//This uses the function _Oscillators coded by mmillar
// Price - price input such as (H+L)/2 or Close
// Length - used by the both the CG and Stochastic calculations
Inputs: Price((H+L)/2), Length(8);
Vars: oResult1(0), oResult2(0);
value1=_Oscillators(6, Price, Length, 0, 1, 0, 1, oResult1, oResult2);
Plot1(oResult1, "StocCG");
Plot2(oResult2, "Trigger");
}
{
The Fisher Stochastic CG indicator/oscillator is similar to the Stochastic CG Oscillator but with sharper reversals and occasionally earlier signals
}