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

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


  • Date: Tue, 16 Feb 2010 16:17:53 -0500
  • From: "Steve Dugas" <sjdugas@xxxxxxxxxxx>
  • Subject: Re: [amibroker] Could someone comment on how this loop is executed (Basic)

PureBytes Links

Trading Reference Links

Hi - untested but you can try something like this...

emaCross = Cross( EMA1, EMA2 );
cumCross = Cum( emaCross );
thirdCross = emaCross AND ( cumCross % 3 == 0 );

Steve

----- Original Message ----- 
From: "m.kuschel31" <m.kuschel31@xxxxxxxxx>
To: <amibroker@xxxxxxxxxxxxxxx>
Sent: Friday, February 12, 2010 1:13 PM
Subject: [amibroker] Could someone comment on how this loop is executed 
(Basic)


> 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/
>
> Yahoo! Groups Links
>
>
>
> 




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

**** 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:
    amibroker-digest@xxxxxxxxxxxxxxx 
    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/