Back to TS code links
    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 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);
Var{Inputs}:Length(8),SCGdelimiter(80);
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;
Value2 = 2*(Value2 - .5);
Plot1 (Value2, "CG",blue);
Plot2(.96*(Value2[1] + .02), "Trigger",green);
Plot3(0, "Ref"); Plot4(SCGdelimiter*+.01,"delimiter",green); Plot5(SCGdelimiter*-.01,"delimiter",green);
{
//// 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");
}