hi 

I fabricated something that doesn't make use of the barssince function since I 
didn't get it to work in a hurry. Code below does the following:

I calculates the positionScore on the close at a thursday then it enters a 
trade at the open on a friday and closes this trade on the open on a thrursday 
at least 22 bars after entry,

(you will need the latest version of Amibroker for this because of the break 
function).

rgds, ed



SetBarsRequired(10000,10000); 
SetOption("MaxOpenPositions", 1 ); 
PositionSize = -100; 
SetTradeDelays(0,0,0,0); 
PositionScore = IIf( Ref(ROC(C,15),-1) > 0, Ref(ROC(C,15),-1), 0); 

procedure sell_proc(Buy,Sellday) { 

global Sell; 
global SellPrice; 
SellPrice = 0; 
Sell = 0; 

// sell delay in bars 
selldelay = 22; 

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

   if (Buy[ i ]) 
   { 
    
      for (j = i + selldelay; j < BarCount; j++) 
      { 
    
         if (Sellday[ j ]) 
         { 
          
            Sell[ j ] = 1; 
             
            i = j; 
            break; 
             
         } 
          
      } 
    
   } 

} 

} 


Buy = DayOfWeek() == 5; 
BuyPrice = O; 

sell_proc(Buy,DayOfWeek() == 4); 
SellPrice = O; 

SetChartOptions(0, chartShowDates); 
GraphXSpace = 5; 
Plot(C,"C",1,64); 

PlotShapes(IIf(Buy,shapeUpArrow,0),colorWhite, layer = 0, yposition = BuyPrice, 
offset = 0 ); 





  ----- Original Message ----- 
  From: samu_trading 
  To: [email protected] 
  Sent: Sunday, October 14, 2007 7:44 AM
  Subject: [amibroker] Code Question: buy best performing ticker of last 15 days


  How could I code this for backtesting in AB?

  Buy on Friday the ticker symbol with the best performance of the last 
  15 trading days.

  Sell 5 weeks later

  Thanks, Samantha



   

Reply via email to