Some trades do not show up on portfolio backtest that are visible on chart and single stock backtest

We have a portfolio backtest strategy with entry and exit signals on hourly bars. The strategy also uses a third-party indicator which is a score (1-99) for each stock on each day. These were imported into our database using the schema: "Symbol_Score" and accessed in the code as:

ThisSymbol = Name();
SetForeign(ThisSymbol + "_Score", True, False);
Score = Close;
RestorePriceArrays();

If we filter using inputs set to 1-49, a strategy entry is only taken if the stock's score reading on that day is between 1 and 49. If the inputs are set to 1-99, then the indicator filter is ignored and all strategy trades are taken. However, I'm experiencing a number of issues:

1.) When I run a backtest with the indicator inputs set to 1-49, then another backtest with the inputs set to 50-99, and combine the trades from those two backtests, I get many more trades than the backtest with indicator inputs set to 1-99. They should have the same number of trades. However, there are extra trades that are showing up in the 1-49 and 50-99 tests; and these additional trades are correct so they should be in the 1-99 tradelist too but are not.

2.) These extra trades show up in my trades list when I run the 1-99 backtest on the symbol only. Whereas they do not when I run the test on my basket of stocks.

3.) These extra trades correctly appear on charts. However, for some reason they do not show up when I run the 1-99 backtest on a basket of symbols.

Any insight into this would be appreciated.

1 Like

@vjsworld I don't know what is causing this and without being able to test your code it is hard to debug, but a couple of possible areas to look at.

Make sure your portfolio test has enough cash or margin to take all your trades. Also make sure you have enabled the number of positions in the SetOptions, define your MaxPositions and then,

SetOption("MaxOpenPositions", MaxPositions);

And enable position size shrinkage,

SetOption("AllowPositionShrinking", True);

If those don't help then I hope someone else can chime in.

2 Likes

I agree with @portfoliobuilder. The most likely cause of the difference is that you are unable to take all the trade signals in the 1-99 test, either due to capital restrictions or max positions.

Thank you @portfoliobuilder and @mradtke! This fixed it.