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

Re: [amibroker] while/for loop compiler error 3 question



PureBytes Links

Trading Reference Links


Ed,
 
I enjoyed reading through your code, but was confused as to why you initialized the following arrays twice.  Can't they all be set to zero from the start?
 
Thanks,
Gary
 
// initialise arrays SellPrice = BuyPrice; SellPrice = 0; Sell = Buy; Sell = 0; BuyAdjusted = Buy; BuyAdjusted = 0; BuyPriceAdjusted = <FONT
 color=#000000>BuyPrice; BuyPriceAdjusted = 0; ed nl <ed2000nl@xxxxxxx> wrote:




hi,
 
the error you get is because you use whole arrays in the loop. So your exitcondition is probably defined as an array. For instance if you define:
 
exitCondition = StochK(8) > 90; 
 
then exitCondition is an array and in the loop you have to specify the element using exitCondition[ i ]
 
For your second question I add an example. You see that I have a j-loop within the i-loop. To exit the j-loop is put j = BarCount. Before I do that I change i to the value I want it to be. So the answer is yes one can change i within the loop.
 
rgds, Ed
 
 
procedure ttt(Buy,BuyPrice,Open,High,Low,Close,nbar) { /* Jul 2004 */ global Sell; global <FONT
 color=#000000>SellPrice; global BuyAdjusted; global BuyPriceAdjusted; // initialise arrays SellPrice = BuyPrice; SellPrice = 0; Sell = Buy;
 Sell = 0; BuyAdjusted = Buy; BuyAdjusted = 0; BuyPriceAdjusted = BuyPrice; BuyPriceAdjusted = 0; for (i = 0; i < BarCount; i++) {    // <FONT face="Courier
 New" size=2>   if (Buy[ i ] == 1) {                // buy at open       BuyAdjusted[ i ] = 1;       BuyPriceAdjusted[ i ] = Open[ i ];              <FONT
 color=#008000>// find a sell position + sellprice       for (j = i; j < BarCount; j++) {               // nbar stop exit at the open          if ((j - i) == nbar) {                   
             Sell[ j ] = 5;             SellPrice[ j ] = Close[ j ];                          // enter i-loop starting from the last sell             i = j;
                              // escape from loop             j = BarCount;                       }                  }           }                  } } // end procedure
 

OK, this compiler/interpreter behaviour is confusing me:here is a part of my code that is generating compile Error 3, "for, while, if statement can only use boolean or numeric variables" etc.
The strange part is that the for loop is ok but the while generates this error as shown AND also if I comment the (exitCond == False) part and uncomment the (n < BarCount) part. (error goes away if I change BarCount to 10, e.g., with (exitCond == False) commented out).2nd Question has to do with being able to change i in the middle of the for loop, as I do in the last statement. Is this possible or will i continue from where it left off????for (i = Length+1; i < BarCount; i++){                exitCond = False;                n = i;                inTrade = False;              while ((exitCond == False))// AND (n <
 BarCount))                {                   n = n + 1;                }//while              i = n;}// forCheck AmiBroker web page at:http://www.amibroker.com/Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html 
		Do you Yahoo!?
Express yourself with Y! Messenger! Free. <a
href="">Download now.


Check AmiBroker web page at:
http://www.amibroker.com/

Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html








Yahoo! Groups Sponsor


  ADVERTISEMENT 












Yahoo! Groups Links
To visit your group on the web, go to:http://groups.yahoo.com/group/amibroker/ 
To unsubscribe from this group, send an email to:amibroker-unsubscribe@xxxxxxxxxxxxxxx 
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.