Duplicate: Position sizing and ranking question

Hello all,

I have a question regarding the following output in the backtest engine:

image

As you can see the symbol AIG is not traded because of insufficient funds (this is expected). Because of the ranking used (ROC on close of 200d), the AIG symbol is selected first. The next signal is from the symbol ADI (rank is 0 because ROC is negative, this is an extra coded line). However from the backtest result the trade for ADI is NOT entered. What's the reason for this (there is sufficient funds available to take this trade)?

Note: signal is triggered on 4/05/2001, entry expected on 7/5/2001.

ADI missing:
image

AIG and ADI have buy signals, AIG has higher rank than ADI:
image

Code:

//inputs capital
capital=10000;
RoundLotSize=1;

//inputs entry
volumed=50000000;
volumel=20;
minp=5;
mavs=Optimize( "MOV-F", 25, 25, 100, 25 );
mavl=Optimize( "MOV-S", 50, 50, 400, 50 );
spal=Optimize( "SPY-L", 100, 100, 400, 100 );
Exclude=(mavs>=mavl);

//ranking
rankl=199;

//exits
atrl=20;
stopn=Optimize( "# ATR stop", 5, 0, 10, 1 ); //#ATR
trailstop=Optimize( "trailstop (%)", 25, 0, 40, 5 ); //%
profitexit=0; //%
timeexit=0; //d

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

SetOption("MaxOpenPositions", 10 );
SetOption("MinPosValue", 0 );
SetOption("InitialEquity", capital); 
SetOption( "AllowSameBarExit", true);
SetOption("ActivateStopsImmediately", True );
SetOption("UsePrevBarEquityForPosSizing", true); 

spyc=Foreign("SPY", "C");
smaspy=MA(spyc,spal);
Movs=MA(Close,mavs);
Movl=MA(Close,mavl);
Volvg=MA(Volume,volumel);
voldol=Volvg*Close;
atravg=MA(ATR(1),atrl);
stopx=atravg*stopn;
stopxb=Ref(stopx,-1);
StaticVarSet( Name() + "stopx",  stopxb );

//ranking
rank=IIf(ROC(Close,rankl)<0,0,ROC(Close,rankl));
PositionScore=rank;

Buy=(Close>minp AND voldol>volumed AND spyc>smaspy AND movs>movl AND IsNull(rank)==false);
Sell=0;

//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;
}

//exits
if(stopn>0)
{
  ApplyStop( 0, 2, Ref(stopx,-1), 1 );
}
if(trailstop>0)
{
  ApplyStop( 2, stopModePercent, trailstop, 1);
}

This question has already been answered here: Entry signals after a skipped signal seem to be ignored?

2 Likes

I have missed that subject in my search on the forums. Exactly what I was looking for. Thank you! Now I need to find a way around it.

Duplicate of: