Your plot for EMA is only 20 NOT the 200 as initialilzed. Regards
On 13 February 2010 05:13, m.kuschel31 <[email protected]> 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 > > > -- Gordon Pelletier 24 Diamond Rd Pearl Beach NSW 2256 email [email protected] (02) 43424164 0407990787
