hi,

the way you set it up it shoudl not be possible. However, what can happen is 
that the backtester finds exits for the next day and immediatelly fills them 
with new positions. So you need to make sure that you first exit your positions 
and tell the backtester to enter only on the next bar. This is usually the 
problem.  There are several ways to achieve this. Maybe you will get a more 
satisfactory result when you set settradedelays(1,1,1,1). 

I use setttradedelays(0,0,0,0) but I make sure that the trade is entered 1 bar 
after the signal (same with the exits),

Ed




  ----- Original Message ----- 
  From: Michael White 
  To: [email protected] 
  Sent: Friday, August 24, 2007 11:37 AM
  Subject: [amibroker] How do I backtest placing a restricted number of limit 
orders each night?


  Can anyone help me model the following scenario?

  - Assume a portfolio is allowed to consist of some fixed number
  of "slots" with equity equally divided among them (e.g. 10 slots at
  10% of equity).
  - Check for setup criteria at close of each day.
  - Place next day limit buy orders for as many unfilled slots as are
  currently available (e.g. if already have 2 fills after day 1, then
  there are only 10 - 2 = 8 slots remaining for day 2, etc.).
  - Buy orders are prioritized by a calculated value.

  My problem is that if I receive a setup for more symbols than I have 
  available slots (e.g. receive 20 setups but only have 8 available 
  slots), my script will try to fill all 8 slots from the 20 
  candidates, and the portfolio manager will correctly prevent me from 
  having more positions than allowed (e.g. no more than 10).

  However, in reality, I will only have placed as many limit orders as 
  I have available slots (e.g. 8 limit orders when 8 available slots, 
  not limit orders for all 20 candidates, since I only have funds to 
  cover placing 8 orders).

  What is happening is that my script is filling orders that I would 
  not have placed! I need a way to indicate that despite 20 setups, 
  only 8 limit orders were placed.

  Following is some script snippets.

  /*
  * Assume an initial purse and brokerage fees ($0.01/share)
  */
  SetOption("InitialEquity", 50000);
  SetOption("CommissionMode", 3);
  SetOption("CommissionAmount", 0.01);

  /*
  * Carry fixed number of positions, dividing 100% of Equity between
  * them (based on previous bar's closing).
  */
  PositionSize = -100/10; // Each position is 10% of equity

  SetOption("MaxOpenPositions", 10); // No more than 10 positions
  SetOption("UsePrevBarEquityForPosSizing", True);

  /*
  * We recognize the sale signal at the close of a bar and execute the
  * sale at the open of the next one, delay sale by 1 day.
  */
  SetTradeDelays(0, 1, 0, 0);

  /*
  * Trigger a Buy signal when previous bar meets the setup
  * requirements AND this bar's Low has dropped to less than a fixed
  * percentage below the previous bar's close. This emulates having
  * placed a limit order the night before after having seen the signal
  * on that day's close.
  */
  setup = ... // Some position entry logic.
  PositionScore = ... // Some prioritization logic.

  BuyPrice = Ref(Close, -1) * 0.95;
  Buy = Ref(setup, -1) AND Low <= BuyPrice; // Problem here!!!

  Sell = ... // Some sell logic.

  As indicated in my earlier comments. The problem is that in reality I 
  will not actually have placed orders for all candidates, but rather 
  only for as many as there are available slots (e.g. 8). However, the 
  script will attempt to fill the available slots based on all 
  candidates (e.g. 20).

  How can I restrict the Buy assignment to only apply to the top X of Y 
  candidates based on priority (e.g. top 8 of 20 in example above).

  Thanks in advance.



   

Reply via email to