Close position at buy price if stock stopped trading

Hello, I have a code that backtests for a portfolio of stocks. Some of the stocks that my code buys later get delisted before the sell signal, which leads to a problem where the delisted stock is kept in the portfolio until the end of the backtest. The question is if it is possible to write a code that sells a stock if it gets delisted (i.e. there is no more data) at buy price?

I would greatly appreciate your help with this matter.

Before posting, search for existing threads. Your question is already answered:

1 Like

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