Dear Community,

I have an algo running and would like to determine when and how the Portfolio[].Invested flag is updated.

If I open a position in SPY, theĀ self.Portfolio["SPY"].Invested is set to TRUE, as expected. And in reverse when the the position is closed (by the algo) the flag is set to FALSE. However if I close the position by other means (outside the algo) this flag remains TRUE, even though the position does not exist anymore in my broker account.

How should I set this is in a way that outside orders are reflected by the portfolio object immediately?