Puzzle with 'positionscore' in explore versus backtest mode

Dear All:

My backtesting shows puzzling results when applying 'positionscore' to select which stocks should be traded tomorrow in case we have more signals than allowable open positions.

The code processes signals at the end of the day for entry at the open in the next morning:

Buy = Rule1 AND Rule2 AND Rule3;      
BuyPrice = Open;
PositionScore = 100-RSI(3);                  
SetTradeDelays(1,0,0,0);

Each evening, we run explore to select which tickers should be traded tomorrow:

filter = Buy;  
AddColumn(PositionScore,"PositionScore");  
AddColumn(Close, "Close");

As an example, we ran “explore” on 2025-01-31 and received the following buy signals (the top 3 tickers, given 'maxpos = 3'):

So next morning, we bought these 3 tickers. The back test running the next trading day (2025-02-03) then correctly shows:

So far, so good. We now run “explore” to receive the buying signals for the next day, and get this:

We now expect to see exactly the same 3 tickers in tomorrow’s backtest. However, this is what we see as we run the backtest:

It should have bought WSM, SNX, and RL. But it bought SNX, RL and... JBL? JBL should not appear here!

But it gets more puzzling if we run the same code to backtest 2025-02-04 only:

It has now picked the correct tickers.

The implication for my trading is troublesome, as I would be unable to trade exactly what has been backtested.

Any ideas on how to solve this puzzle would be greatly appreciated!

Kind regards and thank you in advance.

@ceph1971 this was discussed multiple time in the forum and I happened to me too in the past.

Anyway, please see this past thread to understand how to solve it. Or this other one or simply search the forum for “positionscore delay”

1 Like

As @beppe wrote you, exploration is not backtest and if you are using SetTradeDelays you are DELAYING trade in BACKTEST, but not in exploration because exploration shows raw data. In exploration you have to apply DELAYS if you want to see actual data and ALWAYS, I MEAN ALWAYS use "Detailed log".

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?

1 Like

Thank you, Beppe and Tomasz.
Problem solved.

1 Like

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