Executed trades do not correspond with their position score

Dear all,
I do not understand the trade execution of the following code which I ran against this tickers XLB, XLE, XLF, XLI, XLK, XLP, XLU, XLV, XLY and data from yahoo finance.

// Check if Data Periodicity is set to "Daily"
if(Interval() != inDaily && Status("actionex") != actionExEditVerifyFormula)
	Error("Perdiodicity not set to 'Daily'");

maxPos = 1;

lenGainsMonths = 3;
lenGains = 21 * lenGainsMonths;

entryDelay = exitDelay = EquityForPosSize = 1;
// 0 = Same Bar on Close, 1 = Next Bar at Open

// Setting overwrittes parameters from GUI
SetOption("InitialEquity",1000);               
SetOption("CommissionMode",3);
// 1 = % of trade, 2 = $ per trade, 3 = $ per share              
SetOption("CommissionAmount",0.00); 

SetOption("AllowSameBarExit", False);
// Same Bar, Same Symbol Signal Conflict

SetOption("MaxOpenPositions",maxPos);                                   
SetTradeDelays(entryDelay,exitDelay,entryDelay,exitDelay);
// SetTradeDelays( buydelay, selldelay, shortdelay, coverdelay )
SetOption("UsePrevBarEquityForPosSizing",EquityForPosSize);


// All positions sized equally
SetPositionSize(1,spsShares);
//SetPositionSize(100/maxPos,spsPercentOfEquity);


//**************************************************
//	Phase 1 Beginn

Buy = Sell = Short = Cover = 0;
BuyPrice = ShortPrice = IIf(entryDelay==0,C,O);
SellPrice = CoverPrice = IIf(exitDelay==0,C,O);

// Perform Ranking
doRanking = Nz(TimeFrameExpand(1,inMonthly,expandPoint));	

// Position Scoring
SectorGain = ROC(C,lenGains);

//PositionScore = mtRandomA();
PositionScore = 1000 + SectorGain;

// Enter and Exit Signals
// Trade execution controlled by SetTradeDelays
Buy = 	doRanking AND
		maxPos > 0 AND
		SectorGain > 0;			

Sell =	doRanking;

// Explorations
if (Status("action") == actionExplore)
{
	Filter = doRanking;

	AddColumn(doRanking, "Ranking");	
	AddColumn(SectorGain, "Sector Gain("+lenGainsMonths+")");
	AddColumn(PositionScore, "PositionScore");
	AddColumn(IIf(Buy,1,Null), "Buy", 1.0);
	AddColumn(IIf(Sell,1,Null), "Sell", 1.0);
	
	SetSortColumns(2,-5);
}		

Why is there a buy of XLK (1008.13) on 01.03.2019 although it has not the highest position score? I would expect to see a buy of XLI (1008.68). There is the same situation on 01.04.2019 where XLI (1017.34) is bought instead of XLK (1020.25).

AB-Forum

Thanks in advance!

I suggest you change your Reporting Format from Trade List to Detailed Log in the Analysis Settings window. There you can confirm the PositionScore values that are being used by the backtester.

Use forum search.
Explorer is not backtester.
Settradedelays is backtester function.

Thanks @mradtke @fxshrat for pointing me to the right info. My "issue" was the definition of trade delays which were set to SetTradeDelays(1,1,1,1). With SetTradeDelays(1,0,1,0) it works as intended.

AB-Forum_02

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