[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Ehler' sCenter of Gravity - TASC, May, 2002



PureBytes Links

Trading Reference Links

Mohan, yes you got it right. Thanks
It works with any lookback period. Thanks also for
commenting the script - I learnt from it.

nand

--- In amibroker@xxxx, "into_stocks98" <yellayi@xxxx> wrote:
> Here is the way , I coded it. T is the lookback period.
> The formula is, for those that don't have the magazine, 
> CG = -Num/Denom; where
> Num = Sum of ( 1 + j ) * Price(j) for j = 0 to T
> Denom = Sum(Price,T); //AFL Formulation.
> I was thinking , this could be done in AFL with WMA function. But 
> doesn't quite look the way vbscript code looks.
> 
> 
> /*John Ehler's Center of Gravity Oscillator
> ** From S& C May 2002 
> **
> **/
> 
> EnableScript("VBScript");
> 
> Price = (H+L)/2;
> 
> T = 40;
> 
> <%
> 
> Price = AFL("Price")
> nSize = UBound( Price )
> 
> ' nLength is the Look back period
> 
> nLength = AFL("T") - 1
> 
> 'INITIALIZE THE ARRAYS
> 
> Num = Price ' need this for type definition
> Denom = Price
> 
> for i = 0 to nSize
> 
> Num( i ) = 0 
> Denom( i ) = 1 
> 
> next
> 
> ' CG Oscillator Calculation
> ' Start Calculating from the Look back period point
> 
> for i = nLength to nSize
> 
> ' Now Calculate the Num AND Denom Looking 
> ' back from the Current price point
> 
> for j = 0 to nLength
> 
> Num( i ) = Num( i ) + ( 1 + j ) * Price( i - j )
> Denom( i ) = Denom( i ) + Price ( i - j )
> 
> next
> next
> 
> 
> AFL("Num") = Num
> AFL("Denom") = Denom
> 
> %>
> 
> CG = IIf(Denom > 0,-Num/Denom,0);
> 
> Plot(CG,"CG",4,1);
> Plot(Ref(CG,-1),"",6,1);
> 
> 
> Mohan
> 
> --- In amibroker@xxxx, "nkis22" <nkishor@xxxx> wrote:
> > I tried coding John Ehler's Center of Gravity Indicator
> > as published in TASC,May, 02, page 21.
> > 
> > When you look back with "Ref" it works very well. However, how far
> > to look back is always an important issue. So, instead of coding 
> with
> > tons of Refs, I wanted this script to automate lookback thru
> > N (N=5 in this case). It works, but when I change this N to 10, 
15 
> or
> > any other number, the indicator doesn't change. Why? There may
> > be something wrong with the script. Can u help, please.
> > 
> > /*J.F.Ehler's Center of Gravity, TASC, 05/02*/
> > EnableScript("Vbscript");
> > top=0; bot=0
> > <%
> > N=5
> > price=AFL("Close")
> > toptot=0
> > bottot=0
> > for i = 1 to N
> > bottot=bottot+price(i)
> > toptot=toptot+(price(i) * N)
> > N=N-1
> > next
> > AFL.Var("top")=toptot
> > AFL.Var("bot")=bottot
> > %>
> > ntop=top+Close;
> > Cg=ntop/bot;
> > Graph0=Cg;Graph0Style=8;
> > Graph1=Cg-ref(cg,-1);
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > .