Issues with Positionscore

I have some issues with position score. I coded a simple system to buy the top 10 from current S&P 500 index constituents just for testing purposes based on the highest 252 day ROC and hold until the end of the year. The code is below

SetOption("InitialEquity", 100000 );
SetOption("AllowSameBarExit", False);
RoundLotSize = 1; 
posqty = Optimize("PosQty", 10, 1, 20, 1 );
SetOption("MaxOpenPositions", posqty);
PositionSize = -100/posqty; 
isLastOfyear = year() != Ref(year(),1);
Buy= islastOfyear;
PositionScore = ROC(252);

For the backtest range shown, I get the same stocks for 2020 and 2022, two stock for 2021, and four stocks for 2023 as shown below. There is no ranking.

I am definitively doing something wrong but I tried a few things and I cannot find it. I used debug already.

Any help? Thanks.

Use "DETAILED LOG" mode. To get better understanding of what is happening in your code and how functions work, use advice given here: How do I debug my formula?

Thanks Tomasz. I looked at the detailed log. I appreciate your quick reply. I already found one error, It should be

PositionScore = ROC(C,252);

Yet, even after the correction, I get this:

Two trades for 2021 and four for 2023.

I probably miss something here.

It is good that you looked at the detailed log, but we haven't seen it here yet. You are overestimating our mind reading capabilities.

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