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

RE: [amibroker] Static Variables



PureBytes Links

Trading Reference Links




John,
 
apparently it makes no difference. I am used to 
doing it this way because I used to program with IDL. I thought that certain 
arrays are known arrays to AFL like Buy, Sell etc and do not need to be 
initialised. However, I thought that if I only use BuyAdjusted = 0; that 
Amibroker would think it is not an array. Apparently not.
 
But the way I do it is not wrong however it is 
indeed unnecessary ... have to get used to the fact that AFL is an array 
oriented language.
 
thanks,
 
Ed  
<BLOCKQUOTE 
>
  ----- Original Message ----- 
  <DIV 
  >From: 
  john gibb 
  
  To: <A title=amibroker@xxxxxxxxxxxxxxx 
  href="">amibroker@xxxxxxxxxxxxxxx 
  Sent: Sunday, August 08, 2004 10:39 
  PM
  Subject: Re: [amibroker] while/for loop 
  compiler error 3 question
  
  Hi Ed,
   
  What problem might you encounter if you 
  simply do:
   
      BuyAdusted=0;
   
  ?
   
  instead of:
   
  
      BuyAdusted=Buy; 
      
  BuyAdusted=0;
   
  thanks,
   
  -john
  <BLOCKQUOTE dir=ltr 
  >
    ----- Original Message ----- 
    <DIV 
    >From: 
    ed nl 
    To: <A title=amibroker@xxxxxxxxxxxxxxx 
    href="">amibroker@xxxxxxxxxxxxxxx 
    Sent: Sunday, August 08, 2004 10:20 
    AM
    Subject: Re: [amibroker] while/for loop 
    compiler error 3 question
    
    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
    <BLOCKQUOTE 
    >
      ----- Original Message ----- 
      <DIV 
      >From: 
      john 
      gibb 
      To: <A 
      title=amibroker@xxxxxxxxxxxxxxx 
      href="">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 = <FONT 
      color=#000000>Buy; BuyAdjusted = 
      0<FONT 
      color=#000000 size=2>; 
      <FONT color=#000000 
      size=2> 
      <FONT 
      face=Arial>-john
      
      <BLOCKQUOTE dir=ltr 
      >
        ----- Original Message ----- 
        <DIV 
        >From: 
        ed nl 

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