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

[amibroker] Re: RSI - Support Resistance - GRAHAM



PureBytes Links

Trading Reference Links


Ah Hah !  Thanks John for clarifying my question, and Ed for giving such a great explaination.
 
For those of us who didn't grow up as programmers, these added steps related to initializing the array are less than intuitive.
 
Thanks again,
Garyed nl <ed2000nl@xxxxxxx> wrote:


O, but this has a reason. First I make an array BuyAdjusted:
 
1) BuyAdjusted = Buy;
 
and then I make sure that I only have zeros in this array
 
2) BuyAdjusted = 0;
 
so now I have an array BuyAdjusted that has the same length as Buy and it is filled with zeros only,
 
rgds, Ed

----- Original Message ----- 
From: john gibb 
To: amibroker@xxxxxxxxxxxxxxx 
Sent: Sunday, August 08, 2004 7:14 PM
Subject: Re: [amibroker] while/for loop compiler error 3 question

Hi Ed,
 
Here is an example of the double initialization I think Gary refers to:
 
    BuyAdjusted = Buy; BuyAdjusted = 0; 
 
-john


----- Original Message ----- 
From: ed nl 
To: amibroker@xxxxxxxxxxxxxxx 
Sent: Sunday, August 08, 2004 9:42 AM
Subject: Re: [amibroker] while/for loop compiler error 3 question

hi Gary,
 
I'm not sure what you mean that I initialize these arrays twice. Please show me where. The reason I initialize the arrays is to make sure the arrays exist and have the same length as the Buy array and are filled with only zeros. 
 
I add the rest of the program which is a LONG only test program for a N-Bar stop procedure included in a system (instead of the Applystop).
 
Could be I initialised them twice so I like to see how to avoid that, but this way I know for sure the arrays exist and that they are empty.
 
regards, Ed
 
 
 
procedure ttt(Buy,BuyPrice,Open,High,Low,Close,nbar) { /* Jul 2004 */ global Sell; global
 SellPrice; global BuyAdjusted; global BuyPriceAdjusted; // initialise arrays SellPrice = BuyPrice; SellPrice = 0; Sell = Buy<FONT
 color=#000000>; 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 ];       
       // 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 <FONT face="Courier New"
 size=2>            i = j;                              // escape from loop             j = BarCount;                       }                  }           }
                  } } // end procedure // initial settings for portfolio trading (also see Settings window) SetBarsRequired(10000,10000); SetOption("MaxOpenPositions", 250 ); PositionSize =
 -15; SetTradeDelays(1,1,1,1); SetOption("AllowSameBarExit",True); SetOption("AllowPositionShrinking",True );
 SetOption("ActivateStopsImmediately",True ); // initial settings of the variables nb = 1; tt = NumDownBars = BarsSince( C >= Ref(C,-1) ); <FONT
 color=#000000>Buy = tt >= 3; // build in the trade delay Buy = Ref(Buy,-1); BuyPrice = Open; // calculate sell positions ttt(<FONT face="Courier
 New">Buy,BuyPrice,Open,High,Low,Close,nb); Buy = BuyAdjusted; BuyPrice = BuyPriceAdjusted; // move back the arrays Buy = <FONT
 color=#0000ff>Ref(Buy,1); Sell = Ref(Sell,1); Plot(C,"C",1,64); PlotShapes(<FONT
 color=#000000>shapeUpArrow*Buy,colorWhite, layer = 0, yposition = BuyPrice, offset = 0 ); PlotShapes(shapeDownArrow*Sell,colorYellow, layer = 0, yposition = SellPrice, offset = 0<FONT
 size=2> ); Title=Name()+ ", O: "+WriteVal(O)+ ", H: "+WriteVal(H)+ ", L: "+WriteVal(L)+ ", C: "+WriteVal(C); <FONT
 color=#000000>PositionScore = tt * (50-StochK(8)); Filter = 1; AddColumn(Buy,"Buy"); AddColumn(Sell,"Sell");
 AddColumn(PositionScore,"PositionScore"); 

----- Original Message ----- 
From: Gary A. Serkhoshian 
To: amibroker@xxxxxxxxxxxxxxx 
Sent: Sunday, August 08, 2004 4:31 PM
Subject: Re: [amibroker] while/for loop compiler error 3 question

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 ];       
       // 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 <FONT face="Courier New"
 size=2>            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. Download now. Check AmiBroker web page at:http://www.amibroker.com/Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html Check AmiBroker web page at:http://www.amibroker.com/Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html Check AmiBroker web page at:http://www.amibroker.com/Check group FAQ at: <A
 href="">http://groups.yahoo.com/group/amibroker/files/groupfaq.html Check AmiBroker web page at:http://www.amibroker.com/Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html 
		Do you Yahoo!?
New and Improved Yahoo! Mail - 100MB free storage!


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.