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

[amibroker] Re: looping question FIXED



PureBytes Links

Trading Reference Links

Hi,

I said screw the scripting and did the code below... works perfect.

I was under the impression that to loop you had to do VBscript or 
Jscript... still learning.

Here is what works:
==========================================================

numerator=0; period=10;

for( i=1; i<period; i++ )
	{
		numerator=numerator + ((i+1)*Ref(Close,-i));
	}

numerator=numerator+Close;

denominator=period*MA(Close,period);

cog=IIf(denominator!=0,-numerator/denominator,0);
cogyest=Ref(cog,-1);

******************************************************************

--- In amibroker@xxxxxxxxxxxxxxx, "jwilsonp2a" <jimnwilson@xxxx> 
wrote:
> Hi,
> 
> Still trying to implement Ehler's Center of Gravity indicator. 
This 
> requires summing the last n closing prices, with weights of 1..n 
on 
> each price. I got it to work perfectly for today, but can't get it 
> to work for yesterday or any day before. I need to iterate from n 
> days back to the day of the bar in the backtest. I tried using 
> barindex(), but putting that into the script doesn't work. Here is 
> the code that works on today's bar only. What do I need to do to 
get 
> this to work on all other bars? Driving me nuts! Thanks in advance.
> =========================================================
> EnableScript("jscript"); bar_index=BarIndex();
> 
> <%
> 
> Close=VBArray(AFL("close")).toArray();
> 
> bar_index_inscript=AFL("bar_index"); /*this gives error if I try 
to 
> use in the loop below*/
> 
> numerator=0; period=10;
> 
> for( i=0; i<period; i++ )
> {
> numerator=numerator + ((i+1)*Close[Close.length - i - 1]);
> }
> 
> AFL("i")=i;
> AFL("numerator")=numerator;
> AFL("period")=period;
> AFL("closelength")=Close.length;
> 
> %>
> 
> denominator=period*MA(Close,period);
> cog=IIf(denominator!=0,-numerator/denominator,0);
> cogyest=Ref(cog,-1);


------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for your HP, Epson, Canon or Lexmark
Printer at MyInks.com. Free s/h on orders $50 or more to the US & Canada.
http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/mOAaAA/3exGAA/qnsNAA/GHeqlB/TM
---------------------------------------------------------------------~->

Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx 
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/