expanded the code on the short side:


waitPeriod = 10; 
triggerPercentage = 1; 

SetupLong = ExRemSpan(C < BBandBot(C, 20, 2), waitPeriod); 
SetupPriceLong = ValueWhen(SetupLong,H) * triggerPercentage; 
Buy = Cross(H, SetupPriceLong) && BarsSince(SetupLong) < waitPeriod; 
BuyPrice = SetupPriceLong; 

SetupShort = ExRemSpan(C > BBandTop(C, 20, 2), waitPeriod); 
SetupPriceShort = ValueWhen(SetupShort,L) * triggerPercentage; 
Short = Cross(SetupPriceShort, L) && BarsSince(SetupShort) < waitPeriod; 
ShortPrice = SetupPriceShort; 

SetChartOptions(0, chartShowDates); 
GraphXSpace = 5; 
Plot(C,"C",1,64); 
Plot(BBandBot(C,20,2),"",colorGold,1); 
Plot(BBandTop(C,20,2),"",colorGold,1); 

Plot(IIf(BarsSince(setuplong) < 
waitPeriod,SetupPriceLong,Null),"",colorLightBlue,1); 
Plot(IIf(BarsSince(setupShort) < 
waitPeriod,SetupPriceShort,Null),"",colorLightOrange,1); 

PlotShapes(IIf(SetupLong,shapeSmallCircle,0),colorYellow, layer = 0, yposition 
= L, offset = 0 ); 
PlotShapes(IIf(Buy,shapeUpTriangle,0),colorLightBlue, layer = 0, yposition = 
BuyPrice, offset = 0 ); 

PlotShapes(IIf(SetupShort,shapeSmallCircle,0),colorYellow, layer = 0, yposition 
= H, offset = 0 ); 
PlotShapes(IIf(Short,shapeDownTriangle,0),colorLightOrange, layer = 0, 
yposition = ShortPrice, offset = 0 );







  ----- Original Message ----- 
  From: Edward Pottasch 
  To: [email protected] 
  Sent: Friday, June 15, 2007 1:43 PM
  Subject: Re: [amibroker] Re: Looping - our previous discussion



  indeed very nice coding GP. This does more or less the same as my code:

  waitPeriod = 10; 
  triggerPercentage = 1; 
  Setup = ExRemSpan(C < BBandBot(C, 20, 2), waitPeriod-1); 
  SetupPrice = ValueWhen(Setup,H) * triggerPercentage; 
  Buy = Cross(H, SetupPrice) && BarsSince(Setup) < waitPeriod; 
  BuyPrice = SetupPrice; 

  SetChartOptions(0, chartShowDates); 
  GraphXSpace = 5; 
  Plot(C,"C",1,64); 
  Plot(BBandBot(C,20,2),"",colorGold,1); 
  Plot(SetupPrice,"",colorLightBlue,1); 
  PlotShapes(IIf(Setup,shapeSmallCircle,0),colorYellow, layer = 0, yposition = 
L, offset = 0 ); 
  PlotShapes(IIf(Buy,shapeUpTriangle,0),colorWhite, layer = 0, yposition = 
BuyPrice, offset = 0 ) 


  except that I needed to add one element to my code (see below). Also my code 
does not trigger multiple signals within 1 waiting period. I think your code is 
the better way to do it.


  rgds,  Ed




  procedure setup_proc(Setup, MaxWaitPeriod) { 

  global SetupAdjusted; 
  global SetupPrice; 

  SetupPrice = Null; 
  SetupAdjusted = Setup; 

  for (i = 0; i < BarCount; i++) { 

     //printf("II: " + i + "\n" ); 

     if (SetupAdjusted[ i ]) { 
      
        SetupPrice[ i ] = H[ i ]; 

        for (j = i + 1; j < BarCount; j++) { 
         
           //printf("JJ: " + j + "\n" ); 
         
           if (H[ j ] < H[ i ] AND (j - (i + 1) ) <= MaxWaitPeriod) { 
            
              SetupAdjusted[ j ] = 0; 
              SetupPrice[ j ] = H[ i ]; 
               
           } else if (H[ j ] < H[ i ] AND (j - (i + 1) ) >= MaxWaitPeriod) { 
            
              SetupAdjusted[ j ] = 0; 
              SetupPrice[ j ] = H[ i ];       
              i = j; 
              break;                            
               
           } else if (H[ j ] >= H[ i ]) { 
            
              SetupPrice[ j ] = H[ i ]; 
              i = j; 
              break;          
                                          
           } else if (j == BarCount - 1) { 
            
              break; 
            
           }             
            
        } 

     } 

  } 

  } 



  SetBarsRequired(10000,10000); 

  //per = Param( "Period", 20, 2, 100 ); 
  per = 20; 

  SetupPrice = Null; 
  MaxWaitPeriod = 10; 

  Setup = C < BBandBot(C,per,2); 

  setup_proc(Setup, MaxWaitPeriod); 
  Setup = SetupAdjusted; 

  Buy = Cross(H,SetupPrice) AND !IsNull(SetupPrice); 
  BuyPrice = IIf(O > SetupPrice,O,SetupPrice); 

  SetChartOptions(0, chartShowDates); 
  GraphXSpace = 5; 
  Plot(C,"C",1,64); 
  Plot(BBandBot(C,per,2),"",colorGold,1); 
  Plot(SetupPrice,"",colorLightBlue,1); 
  PlotShapes(IIf(Setup,shapeSmallCircle,0),colorYellow, layer = 0, yposition = 
L, offset = 0 ); 
  PlotShapes(IIf(Buy,shapeUpTriangle,0),colorWhite, layer = 0, yposition = 
BuyPrice, offset = 0 )  




    ----- Original Message ----- 
    From: gp_sydney 
    To: [email protected] 
    Sent: Friday, June 15, 2007 1:00 PM
    Subject: [amibroker] Re: Looping - our previous discussion


    Ed,

    I can't get your attachements. They show at the bottom of the message
    but also say "not stored", and there's nothing to get. Any idea why
    that might be (it seems to be the same for all messages with
    attachments here)?

    I looked back at the original discussion, and from what it seems like
    the objective is to me, I think the whole thing can be done like this:

    Setup = ExRemSpan(C < BBandBot(C, 20, 2), waitPeriod-1);
    SetupPrice = ValueWhen(Setup,H) * triggerPercentage;
    Buy = Cross(H, SetupPrice) && BarsSince(Setup) < waitPeriod;

    All that loop code can be replaced by the ExRemSpan array function.

    Also, in that original loop code, there are a couple of problems.
    Firstly, it skips a bar at the end of each inner loop, because the
    statement i=j sets i to the next bar, but then the for loop's i++
    statement increments it straight away. It should be i=j-1. Secondly,
    it won't run to the end of the array. The outer loop's condition
    should be i < BarCount but then the inner loop needs to add "AND j <
    BarCount" to its condition to avoid over-running the array.

    Regards,
    GP




   

Reply via email to