Hello QuantConnect team! 

I have an issue with the OnEndOfAlgorithm method. It often executes before my system finishes trading, which creates errors when crucial variables are not yet assigned.

What is going on? And how can I make a function that will always execute at the end of my algorithm?

Thanks!