I have a very strong suspicion that the RemoveDrawObject() method is faulty. If a user includes the RemoveDrawObject() method in their code without first checking whether the object is null then this will cause NinjaTrader to crash intermittently. In addition, I suspect that you must also go a step further and check whether the object is the intended type (ex., "is DrawingTools.Line") or the platform will still crash. This is a problem that I noted goes back to NinjaTrader version 7 and I have shied away from calling the RemoveDrawObject() method as a result. I guess I figured that NinjaTrader would've discovered and fixed the problem by now. However, I'm now bringing it to the attention of the development team and hopefully someone could look into it.
I think the below code from your user documentation works but I'm not 100% sure.
if (DrawObjects["someTag"] != null && DrawObjects["someTag"] is DrawingTools.Line) { RemoveDrawObject("someTag") }
Comment