i believe you are supposed to do this with the custom backtester. I never 
managed to use this on any useful level but maybe this code will get you ahead. 
It looks at all bars and finds the signals for each bar and removes excess 
signals before the signals are processed. I did not include a ranking of the 
signals though ..  (see http://www.amibroker.com/guide/a_custombacktest.html  
for details .... ).


SetCustomBacktestProc(""); 

MaxBuys = 3; 

if( Status("action") == actionPortfolio ) { 

   bo = GetBacktesterObject(); 
   bo.PreProcess(); 
    
   for( i = 0; i < BarCount; i++ ) { 
    
    
      cntBuys = 0; 
    
      // look at new signals and exclude signals if they exceed maxBuys 
      for( sig = bo.GetFirstSignal(i); sig; sig = bo.GetNextSignal(i) ) { 
       
         // check for entry signal and long signal 
         if( sig.IsEntry() ) { 
          
            if( cntBuys > MaxBuys ) {   
             
               sig.PosSize = 0; 
                
            } else { 
             
               cntBuys = cntBuys + 1; 
                
             
            } 
             
             
         } 
          
       
      } 
       
      bo.ProcessTradeSignals( i ); 
   } 

   bo.PostProcess(); 

fclose( fh ); 
}





  ----- Original Message ----- 
  From: Keith McCombs 
  To: [email protected] 
  Sent: Tuesday, March 20, 2007 8:12 PM
  Subject: [amibroker] MaxBuys per bar in backtesting


  I would like to set a maximum buys per bar.

  I know about:
  MaxOpen = 10; 
  SetOption("MaxOpenPositions", MaxOpen);

  But is there any way to write the 'equivalent' of:
  MaxBuys = 3; 
  SetOption("MaxBuys", MaxBuys);

  TIA.
  -- Keith


   

Reply via email to