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

Re: [amibroker] Re: plotshapes problem



PureBytes Links

Trading Reference Links




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
<FONT 
color=#800000> 
<FONT 
color=#800000> 
<FONT 
color=#800000> 
<FONT 
color=#800000>procedure ttt(<FONT 
color=#000000>Buy,<FONT 
color=#000000>BuyPrice,<FONT 
color=#000000>Open,<FONT 
color=#000000>High,<FONT 
color=#000000>Low,<FONT 
color=#000000>Close<FONT face="Courier New" 
color=#000000 size=2>,nbar) { <FONT face="Courier New" 
color=#008000 size=2>/* Jul 2004 */<FONT 
face="Courier New"> <FONT 
color=#800000>global <FONT 
color=#000000>Sell<FONT 
size=2>; <FONT 
color=#800000>global <FONT 
color=#000000>SellPrice<FONT 
face="Courier New">; <FONT 
color=#800000>global<FONT 
size=2> BuyAdjusted; <FONT 
color=#800000>global<FONT 
size=2> BuyPriceAdjusted; <FONT 
color=#008000>// initialise arrays <FONT 
color=#000000><FONT 
color=#000000>SellPrice = <FONT 
color=#000000>BuyPrice; <FONT 
color=#000000>SellPrice = <FONT 
color=#ff00ff>0<FONT 
color=#000000>; Sell<FONT 
color=#000000> = Buy<FONT 
color=#000000>; Sell<FONT 
color=#000000> = 0<FONT 
face="Courier New">; BuyAdjusted = 
Buy; BuyAdjusted = 
0<FONT 
size=2>; BuyPriceAdjusted = <FONT 
color=#000000>BuyPrice; BuyPriceAdjusted = 
0<FONT 
size=2>; <FONT 
color=#800000>for (i = <FONT 
color=#ff00ff>0; i < <FONT 
color=#000000>BarCount<FONT 
size=2>; i++) {    <FONT 
color=#008000>// <FONT 
face="Courier New" size=2>   <FONT 
face="Courier New">if<FONT 
color=#000000> (Buy<FONT 
color=#000000>[ i ] == 1<FONT 
face="Courier New">) {     
     
      // buy at 
open <FONT face="Courier New" 
size=2>      BuyAdjusted[ i ] = 
1<FONT 
face="Courier New">; 
      BuyPriceAdjusted[ i ] = <FONT 
color=#000000>Open<FONT 
size=2>[ i ];        
      // find a 
sell position + sellprice <FONT 
face="Courier New" 
size=2>      <FONT 
face="Courier New">for<FONT 
color=#000000> (j = i; j < <FONT 
color=#000000>BarCount<FONT 
size=2>; j++) {      
         <FONT 
color=#008000>// nbar stop exit at the open <FONT 
color=#000000><FONT face="Courier New" 
size=2>         <FONT 
face="Courier New" color=#800000 size=2>if<FONT 
face="Courier New"> ((j - i) == nbar) { 
                   
            <FONT 
color=#000000>Sell[ j ] = <FONT 
color=#ff00ff>5<FONT 
color=#000000>; 
            <FONT 
color=#000000>SellPrice[ j ] = <FONT 
color=#000000>Close<FONT 
size=2>[ j ]; 
             
            <FONT 
color=#008000>// enter i-loop starting from the last sell 
<FONT face="Courier New" 
size=2>            i 
= j; 
                 
            <FONT 
face="Courier New" color=#008000 size=2>// escape from loop <FONT 
color=#000000><FONT face="Courier New" 
size=2>            j 
= <FONT face="Courier New" color=#000000 
size=2>BarCount<FONT 
color=#000000>; 
             
         } 
           
      } 
          } 
                 
} } // end procedure 
<FONT 
face="Courier New" color=#008000 size=2>// initial settings for portfolio 
trading (also see Settings window) <FONT 
face="Courier New">SetBarsRequired<FONT 
color=#000000>(10000<FONT 
color=#000000>,10000<FONT 
face="Courier New">); <FONT 
color=#0000ff>SetOption(<FONT 
color=#ff00ff>"MaxOpenPositions", <FONT 
color=#ff00ff>250<FONT 
size=2> ); <FONT 
color=#000000>PositionSize = -<FONT 
color=#ff00ff>15<FONT 
color=#000000>; SetTradeDelays<FONT 
color=#000000>(1<FONT 
color=#000000>,1<FONT 
color=#000000>,1<FONT 
color=#000000>,1<FONT 
face="Courier New">); <FONT 
color=#0000ff>SetOption(<FONT 
color=#ff00ff>"AllowSameBarExit",<FONT 
color=#000000>True<FONT 
size=2>); <FONT 
color=#0000ff>SetOption(<FONT 
color=#ff00ff>"AllowPositionShrinking",<FONT 
color=#000000>True<FONT 
size=2> ); <FONT 
color=#0000ff>SetOption(<FONT 
color=#ff00ff>"ActivateStopsImmediately",<FONT 
color=#000000>True<FONT 
size=2> ); // initial 
settings of the variables <FONT 
face="Courier New" size=2>nb = <FONT face="Courier New" 
color=#ff00ff size=2>1<FONT 
color=#000000>; tt = NumDownBars = <FONT 
color=#0000ff>BarsSince( <FONT 
color=#000000>C >= <FONT 
color=#0000ff>Ref(<FONT 
color=#000000>C,-<FONT 
color=#ff00ff>1<FONT 
color=#000000>) ); Buy<FONT 
color=#000000> = tt >= 3<FONT 
face="Courier New">; <FONT 
color=#008000>// build in the trade delay <FONT 
color=#000000><FONT 
color=#000000>Buy = <FONT 
color=#0000ff>Ref(<FONT 
color=#000000>Buy,-<FONT 
color=#ff00ff>1<FONT 
color=#000000>); BuyPrice<FONT 
color=#000000> = <FONT 
color=#000000>Open<FONT 
size=2>; // calculate 
sell positions <FONT 
face="Courier New" size=2>ttt(<FONT 
size=2>Buy,<FONT 
color=#000000>BuyPrice,<FONT 
color=#000000>Open,<FONT 
color=#000000>High,<FONT 
color=#000000>Low,<FONT 
color=#000000>Close<FONT 
size=2>,nb); <FONT 
color=#000000>Buy<FONT 
size=2> = BuyAdjusted; <FONT 
color=#000000>BuyPrice<FONT 
size=2> = BuyPriceAdjusted; <FONT 
color=#008000>// move back the arrays<FONT 
face="Courier New"> <FONT 
color=#000000>Buy = <FONT 
color=#0000ff>Ref(<FONT 
color=#000000>Buy,<FONT 
color=#ff00ff>1<FONT 
color=#000000>); Sell<FONT 
color=#000000> = Ref<FONT 
color=#000000>(Sell<FONT 
color=#000000>,1<FONT 
face="Courier New">); <FONT 
color=#0000ff>Plot(<FONT 
color=#000000>C,<FONT 
color=#ff00ff>"C",<FONT 
color=#ff00ff>1,<FONT 
color=#ff00ff>64<FONT 
color=#000000>); PlotShapes<FONT 
color=#000000>(shapeUpArrow<FONT 
color=#000000>*Buy<FONT 
color=#000000>,colorWhite<FONT 
color=#000000>, layer = 0, 
yposition = BuyPrice<FONT 
color=#000000>, offset = 0<FONT 
face="Courier New"> ); <FONT 
color=#0000ff>PlotShapes(<FONT 
color=#000000>shapeDownArrow*<FONT 
color=#000000>Sell,<FONT 
color=#000000>colorYellow, layer = 
0, yposition = 
SellPrice, offset = 
0<FONT 
size=2> ); <FONT 
color=#000000>Title=<FONT 
color=#0000ff>Name()+ ", 
O: "+WriteVal<FONT 
color=#000000>(O)+ 
", H: "+<FONT 
color=#0000ff>WriteVal(<FONT 
color=#000000>H)+ <FONT 
color=#ff00ff>", L: "+<FONT 
color=#0000ff>WriteVal(<FONT 
color=#000000>L)+ <FONT 
color=#ff00ff>", C: "+<FONT 
color=#0000ff>WriteVal(<FONT 
color=#000000>C<FONT 
size=2>); <FONT 
color=#000000>PositionScore = tt * 
(50-<FONT 
color=#0000ff>StochK(<FONT 
color=#ff00ff>8<FONT 
color=#000000>)); Filter<FONT 
color=#000000> = 1<FONT 
face="Courier New">; <FONT 
color=#0000ff>AddColumn(<FONT 
color=#000000>Buy,<FONT 
color=#ff00ff>"Buy"<FONT 
size=2>); <FONT 
color=#0000ff>AddColumn(<FONT 
color=#000000>Sell,<FONT 
color=#ff00ff>"Sell"<FONT 
size=2>); <FONT 
color=#0000ff>AddColumn(<FONT 
color=#000000>PositionScore,<FONT 
color=#ff00ff>"PositionScore"<FONT 
size=2>); 

<BLOCKQUOTE 
>
  ----- Original Message ----- 
  <DIV 
  >From: 
  Gary 
  A. Serkhoshian 
  To: <A title=amibroker@xxxxxxxxxxxxxxx 
  href="">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<FONT 
  color=#000000> = BuyPrice<FONT 
  color=#000000>; SellPrice<FONT 
  color=#000000> = 0<FONT 
  size=2>; <FONT 
  color=#000000>Sell = <FONT 
  color=#000000>Buy; <FONT 
  color=#000000>Sell = <FONT 
  color=#ff00ff>0<FONT 
  face="Courier New">; BuyAdjusted = <FONT 
  color=#000000>Buy; BuyAdjusted = 
  0<FONT 
  face="Courier New">; BuyPriceAdjusted = 
  BuyPrice; 
  BuyPriceAdjusted = 0<FONT 
  size=2>; ed nl 
  <ed2000nl@xxxxxxx> wrote:
  <BLOCKQUOTE class=replbq 
  >
    
    

    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
     
     
    <FONT 
    color=#800000>procedure ttt(<FONT 
    color=#000000>Buy,<FONT 
    color=#000000>BuyPrice,<FONT 
    color=#000000>Open,<FONT 
    color=#000000>High,<FONT 
    color=#000000>Low,<FONT 
    color=#000000>Close<FONT face="Courier New" 
    color=#000000 size=2>,nbar) { <FONT face="Courier New" 
    color=#008000 size=2>/* Jul 2004 */<FONT 
    face="Courier New"> <FONT 
    color=#800000>global <FONT 
    color=#000000>Sell<FONT 
    size=2>; <FONT 
    color=#800000>global <FONT 
    color=#000000>SellPrice<FONT 
    face="Courier New">; <FONT 
    color=#800000>global<FONT 
    face="Courier New"> BuyAdjusted; 
    global<FONT 
    face="Courier New"> BuyPriceAdjusted; 
    // initialise arrays 
    <FONT 
    face="Courier New"><FONT 
    color=#000000>SellPrice = <FONT 
    color=#000000>BuyPrice; <FONT 
    color=#000000>SellPrice = <FONT 
    color=#ff00ff>0<FONT 
    size=2>; <FONT 
    color=#000000>Sell = <FONT 
    color=#000000>Buy; <FONT 
    color=#000000>Sell = <FONT 
    color=#ff00ff>0<FONT 
    size=2>; BuyAdjusted = <FONT 
    color=#000000>Buy; BuyAdjusted = 
    0<FONT 
    face="Courier New">; BuyPriceAdjusted = 
    BuyPrice; 
    BuyPriceAdjusted = 0<FONT 
    face="Courier New">; <FONT 
    color=#800000>for (i = <FONT 
    color=#ff00ff>0; i < <FONT 
    color=#000000>BarCount<FONT 
    face="Courier New">; i++) { 
       // 
    <FONT 
    face="Courier
 New" size=2>   <FONT 
    face="Courier New">if<FONT 
    color=#000000> (Buy<FONT 
    color=#000000>[ i ] == <FONT 
    color=#ff00ff>1<FONT 
    size=2>) {     
         
          // buy at 
    open <FONT face="Courier New" 
    size=2>      BuyAdjusted[ i ] = 
    1<FONT 
    face="Courier New">; 
          BuyPriceAdjusted[ i ] = <FONT 
    color=#000000>Open<FONT 
    size=2>[ i ];        
          // find a 
    sell position + sellprice <FONT 
    face="Courier New" 
    size=2>      <FONT 
    face="Courier New">for<FONT 
    color=#000000> (j = i; j < <FONT 
    color=#000000>BarCount<FONT 
    face="Courier New">; j++) { 
         
             <FONT 
    color=#008000>// nbar stop exit at the open <FONT 
    color=#000000><FONT face="Courier New" 
    size=2>         <FONT 
    face="Courier New" color=#800000 size=2>if<FONT 
    face="Courier New"> ((j - i) == nbar) { 
                       
                <FONT 
    color=#000000>Sell[ j ] = <FONT 
    color=#ff00ff>5<FONT 
    size=2>; 
                <FONT 
    color=#000000>SellPrice[ j ] = 
    Close<FONT 
    face="Courier New">[ j ]; 
                 
                <FONT 
    color=#008000>// enter i-loop starting from the last sell 
    <FONT face="Courier New" 
    size=2>            i 
    = j; 
                     
                <FONT 
    face="Courier New" color=#008000 size=2>// escape from loop <FONT 
    color=#000000><FONT face="Courier New" 
    size=2>            j 
    = <FONT face="Courier New" color=#000000 
    size=2>BarCount<FONT 
    color=#000000>; 
                 
             } 
               
          } 
              } 
                     
    } } // end procedure 
    
    <BLOCKQUOTE 
    >
      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:<A 
    href="">http://www.amibroker.com/Check 
    group FAQ at: <A 
    href="">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:<A 
  href="">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








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.