How to include exiting trades on exit bar in the total open trade count?

In backtesting, by default, the exiting trade is not included in the total number of open trades on its exit bar. For example, I use daily data, on a particular day at open there is 5 open positions of which one is exiting during this day, in the backtest report this day will record 4 open trades. How can I make the exiting trade be counted on the exit bar so that there will be 5 open trades in the above example?

Thank you very much

If trade is exited (closed) it is no longer open so it obviously isn't counted as open trade.

If you want it to be counted as open you should not close it.

You can modify your sell rule NOT to generate exit on very last bar.

If you want to know how many trades were open at the start of the day, just look at the number of open trades for the previous day.

I need this because there is a one day delay for the fund to be available after exiting and other risk management reasons. So I think I will need to use customized backtesting?

Could anyone confirm that there is no easy way to change the internal logic

from:

Number_OpenTrades(bar) = Number_TradesOpenedEarlier - Number_TradesClosedOnBar(bar)

to:

Number_OpenTrades(bar) = Number_TradesOpenedEarlier - Number_TradesClosedOnBar(bar-1)

Thank you very much

If you need a one day delay for the cash from a sale to be available for new entries, you can use the SetOption() function with the “SettlementDelay” parameter.

As for “other risk management reasons”, no matter how the number of open trades is calculated you won’t have access to that number unless you write a CBT (Custom BackTest). You would need to be more specific about your goal if you desire a more specific solution.

I think this is what I was looking for. Thank you so much