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

[amibroker] Re: Could someone comment on how this loop is executed (Basic)


  • Date: Tue, 16 Feb 2010 21:34:11 -0000
  • From: "Mike" <sfclimbers@xxxxxxxxx>
  • Subject: [amibroker] Re: Could someone comment on how this loop is executed (Basic)

PureBytes Links

Trading Reference Links



Hi,

Unlike C, you can almost always accomplish your task by avoiding loops! Refer to http://www.amibroker.com/guide/h_understandafl.html for an explanation of how AFL works.

EMA1 = EMA(C, 10);
EMA2 =
EMA(C, 200);

Buycross =
Cross(EMA1, EMA2);
Counter =
Cum(Buycross);
Triples =
Cross(Counter % 3 == 0, 0);

Plot(EMA1,"EMA10", colorRed,styleLine);
Plot(EMA2,"EMA20",colorBlue,styleLine);
Plot(Triples, "Triples", colorGreen, styleOwnScale | styleHistogram);

Mike

--- In amibroker@xxxxxxxxxxxxxxx, "m.kuschel31" <m.kuschel31@xxx> wrote:
>
> Hi,
>
> I'm used to programming C during my years in university, but it's been a while and by all means, I'm not an expert. I've been seriously working on this for a couple of days and I cannot get a grip on it. I went through the tutorials, references, etc.
>
> What I am trying to accomplish is rather simple:
>
> Count the number of EMA crossovers (upcross in this case), create an array that's 1 at multiples of 3 corssovers(so to say after each 3rd crossover array=1), otherwise the array is 0.
>
> Well, it goes like this:
>
> EMA1=EMA(C,10);
> EMA2=EMA(C,200);
> Plot(EMA1,"EMA10", colorRed,styleLine);
> Plot(EMA2,"EMA20",colorBlue,styleLine);
>
> Buycross[0]=0;
> exit[0]=0;
>
> threshold=3;
> multiplier=1;
>
> Buycross= Cross(EMA1,EMA2);
> Counter=Cum(Buycross); //<== Here the crossover are counted with CUM
>
> // start loop
> for(i=0; i<BarCount;i++)
> {
> if (Counter[i]==threshold*multiplier)
> {
> multiplier++ AND exit[i]=1; // "AND"-statement?!?!
> }
> }
>
> printf("buycross:\n");
> WriteVal(Buycross,1);
> printf("counter:\n");
> WriteVal(Counter,1);
> printf("multiplier:\n");
> WriteVal(multiplier,1);
> printf("exit:\n");
> WriteVal(exit,1);
>
> Counter here is an array, as opposed to the 2nd example. Looks strange, but works.
>
>
> Fine you might say, he did his job, so what's he asking for?
>
> I only achieved this by some means of trial and error and I don't understand, why I have to add "AND" in the loop.So to say, I don't understand what I did. Ok, check this:
>
> EMA1=EMA(C,10);
> EMA2=EMA(C,200);
> Plot(EMA1,"EMA10", colorRed,styleLine);
> Plot(EMA2,"EMA20",colorBlue,styleLine);
>
> Buycross[0]=0;
> exit[0]=0;
> COUNTER=0; //<==== Integer, variable
> threshold=3;
> multiplier=1;
>
> Buycross= Cross(EMA1,EMA2);
>
>
> // start loop
> for(i=0; i<BarCount;i++)
> {
> if (buycross[i]==0)
> {
> counter++; //<=== simple increment
> }
> if (Counter==threshold*multiplier)
> {
> multiplier++; //<=== The two statements without AND
> exit[i]=1; //<=== don't seem to work
> }
> }
>
> printf("buycross:\n");
> WriteVal(Buycross,1);
> printf("counter:\n");
> WriteVal(Counter,1);
> printf("multiplier:\n");
> WriteVal(multiplier,1);
> printf("exit:\n");
> WriteVal(exit,1);
>
> Eventhough my varible "counter" is initialized, the loop would simply not do the increment. Like this, I cannot loop the process of crossover counting. "counter" goes from 2 to 5, sometimes it's doing nothing or even DEcreases. BTW, I'm checking every value of my OHLCV array from the interpretation window.
> Also, the 2 statements would not be executed properly without the AND. I finally accomplished my task in the first code but I do not understand how AFL treats the variables / arrays in a loop. I believe I am not the first one to experience this problem and I would appreciate any kind of help or explanation. I just know that the 2nd code in C would rather work.
>
> I considered varget, global varibale, but the problem didn't seem to get resolved. What am I missing? Where should I look to read up on this?
>
>
> Thanks,
>
> Matthias
>


__._,_.___


**** 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/





Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___