NinjaTrader restores the values for anything it wants to be persistent between construction and Initialize(). That makes perfect sense -- just think of Initialize() as Part 2 of the constructor. NinjaTrader obviously cannot restore any values before the actual constructor, so it does so right after the constructor and then calls "Constructor Part 2" -- Initialize(). Fine so far.
What I do not understand is why NinjaTrader also restores the values again, right after Initialize(). Could someone please explain the logic? What is NinjaTrader trying to accomplish by restoring any persistent data again, after Initialize() has completed? As far as I can see, that means an indicator that changes anything persistent in Initialize() has to pay attention and also make the changes later. Note that any changes needed to set things up for the Indicators dialog cannot be deferred to OnStartup(), because
- NT requires that some things be done in Initialize(). For example, any attempt to Add() anything later on will cause NinjaTrader to throw an exception.
- OnStartup() cannot be used to initialize anything that will appear in the Indicators dialog, because OnStartup() is never called for an indicator instance used with the dialog.
In fact, due to the additional restoration NT does after Initialize() has completed, the indicator has to implement the ICustomTypeDescriptor interface and enforce the changes the indicator wants in GetProperties(). Otherwise the changes will be undone before the dialog gets to see them.
Please pardon me, but the logic of this escapes me, and seems sub-optimal. Please help me understand just why NinjaTrader restores persistent data after Initialize() has completed. As far as I can see things would be simpler and cleaner for the indicator if that were not so.
Thanks,
EV
Comment