Hello people,
I stumbled up an interesting observation while testing a portfolio backtest.
- A position is sold on the end of the day (in this case on 5/9/2003);
- 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(possize==0)
{
SetPositionSize(1,spsShares);
}
else
{
if (stopn==0)
{
psc=-1*maxcapitalalloc;
}
else
{
psc=iif(possize * close/(stopx)>maxcapitalalloc,-1*maxcapitalalloc,-1*possize * close/(stopx));
}
PositionSize = psc;
}