Position sizing and capital available

Hello people,

I stumbled up an interesting observation while testing a portfolio backtest.

  1. A position is sold on the end of the day (in this case on 5/9/2003);
  2. A new buy signal is entered (enter position on the next day at open);

I noticed that I would not take the new position because of insufficient funds. I would expect that I have the funds available on the day that I got the signal and not have the insufficient funds error. Do I have to work around this with CTB or can it be done with setoption and setpositionsize?


Code for position size and options:

//position sizing
possize=2; //%
maxcapitalalloc=10; //%
systemalloc=100; //%

SetOption( "CommissionMode", 2 );
SetOption( "CommissionAmount", 5 );
SetOption("MaxOpenPositions", 100 );
SetOption("MinPosValue", 0 );
SetOption("InitialEquity", capital); 
SetOption( "AllowSameBarExit", true);
SetOption("ActivateStopsImmediately", True );
SetOption("UsePrevBarEquityForPosSizing", false); 
SetOption("AllowPositionShrinking", true); 

//Position sizing
	if (stopn==0)
		psc=iif(possize * close/(stopx)>maxcapitalalloc,-1*maxcapitalalloc,-1*possize * close/(stopx));
PositionSize = psc;

You are not showing entire code. So guessing games again.

If you want to retry entry on NEXT bar, you have to have:

  1. your Buy variable in STATE form (not impulse) - search the forum for more details
  2. Use different backtest mode, for example backtestRegularRaw http://www.amibroker.com/f?setbacktestmode

Highly recommended (essential) reading http://www.amibroker.com/guide/h_portfolio.html

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.