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

[amibroker] Need Help With Looping Code



PureBytes Links

Trading Reference Links

Ok, first off, I apparently don't have the first clue about how to right code that loops through an AB database. I am pretty fluent with looping through MS Access databases using VBA but when it comes to AB I am completely lost.

So in my endeavor to educate myself on the ins and outs of looping in AB I decided to try creating a very simple 50 period moving average using a for loop. My results are below but it does not work. 

I am defeated and at my wits end. Despite all this time and effort I have gained absolutely nothing which helps understand what is happening at each bar during a loop beyond measuring a single value for a single bar. What I am trying to understand is how to accumulate values over a period of bars and output the accumulated value for each and plot it on a chart.

Seems simple enough, add the closes of 50 consecutive bars, store the result in a variable and divide that variable by 50. I can either do this for all bars or one bar but have not been able to figure out how to do it for EVERY bar.

Thanks for taking the time to look at this.

  Pete  :-)
//Code Begin@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Cnt[0] = 0;
SumOfClose[0] = 0;
for( i = 1; i < BarCount; i++ )
{
	if(Cnt[i] < 50)//check if counter is less than 50
	{
	//if counter less than 50 add current bar's 
	//close to the previous running total
	SumOfClose[i] = (SumOfClose[i-1] + C[i]);
	//increment counter by + 1 each bar
	Cnt = Cnt + 1;
	}
		if(Cnt[i] == 50)//check if counter is equal to 50
		{
			//if counter = 50 than compute 
			//the 50 period MA
			MAline[i] = SumOfClose[i]/50;
			//reset counter to zero
			Cnt = 0;
		}
}
//plot the result
Plot(MAline, "MA 50", colorBlue, styleLine);
//Code End@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@



------------------------------------

**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to 
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

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