I am struggling a bit with one aspect though - set up and tear down. There's obviously a lot to set up when the strategy is first loaded, then when it starts to run over historical data there's a whole load of data structures built up and a significant internal state to be maintained.
Unfortunately when I "reload ninjascript" or switch timeframes or instruments without closing the chart or deleting the strategy it reloads with remnants of the previous state and sometimes the instance hangs around for quite some time throwing up errors when I access the strategy dialog for example. I don't ever want anything to be re-used, I want everything to be destroyed and re-made every time.
I wrote the attached strategy to print out the object hashcode, managed thread id and a bunch of other info for every state transition. Objects which are supposed to be "terminated" seem to come back to life and oddly it seems like the previous instance of a strategy is fired-up to start the new one. Is it spawning instances of itself?
Just when I think I've terminated one strategy it comes back to life and tries to access its resources again and starts throwing up loads of errors. It seems like "terminated" for a Ninja Strategy actually does not mean terminated, more like asleep?. If I am super aggressive with my disposal of resources (in the terminated state) I can't get it started again - loads of NullReference exceptions.
If I'm relaxed about it - I end up with hangover state from the previous run. Sometimes Even with no strategies listed in the strategy window I start getting null reference exceptions thrown from the strategy - just opening the strategy window throws up a ton of errors because there's a half-dead zombie instance hanging around.
Is there any way I can do a clean set up and tear down a strategy every time? When the strategy stops I want the object garbage collected and to disappear forever. I don't want it trying to access its past corrupted state, or printing out errors when it tries to do so I don't want it to try to launch new instances of itself - I want it gone, forever - whats the best way to ensure this?
Comment