Strategy 'Trender': Error on calling 'OnStateChange' method: Object reference not set to an instance of an object.
I've looked through the code in case maybe I made an editing error. It compiles fine. If I pull the Strategy out of the folder and put it back there is no error messages. When I open the Strategies panel it prints this.
After the failure my strategy name is no longer in the Available list in the Strategies panel.
Update 1:
I have taken all the strategies out of the strategy folder so only a few stock files exist. So there is no indicator or strategy file anywhere that references this. When I start and open the Strategies panel on a chart it still displays that message. And there are strategy names in the Available list that no longer exist in the folder. I have repaired the database and reset the database but nothing is clearing it.
Whatever is going on is stuck in the Strategies panel. It won't let go of something there.
Update 2:
I removed every file in NT8 that looked like it could be safely removed and recreated. Something triggered a compile of the assemblies during bootup and I got this message:
ERROR: Unable to compile custom assembly. Original version has been restored. You need to recompile your custom NinjaScript files.
I saw a bunch of trace errors around a 3rd party tool. It looks like something triggered a compile, something failed and something got restored. I am not seeing the original strategy issues and the Available list is now correct. So it looks like this issue got resolved but now I'm not sure about the 3rd party tool.
I think I'll remove the assemblies and re-import that tool. Then I can put my strategy back and see if it applies to the chart.
Update 3:
I uninstalled NT8 and installed from scratch. The only thing I'm adding are a couple 3rd party assemblies, a minimal workspace and my strategy code. I've been writing code in this environment for a week now, so I know the 3rd party tools are not the problem. It is something in my strategy code.
I'm getting the same message "Object reference not set to an instance of an object.". So maybe the object reference is something like this?
in State.DataLoaded: myFastMA = ZLEMA(Sensitivity);
I don't have much in the State.* areas, all pretty normal stuff.
Update 4:
I narrowed this down to a single Print statement. I was putting print statements all over to track the execution order. I had this:
protected override void OnStateChange()
{
Print(string.Empty);
Print("------------------------------------------------------------------------------------------------------------------");
Print("Entering OnStateChange \t\tState = " + State + "\t\t\t\t" + Time[0].DayOfWeek + "\t\t" + Time[0].ToString()); // time from chart
if (State == State.SetDefaults)
{
The culprit was the Print line with "Time[0].DayOfWeek". When I take this reference out it is ok.
I looked up Trading Hours man page and now see this:
Warning: The properties in this class should NOT be accessed within the OnStateChange() method before the State has reached State.DataLoaded
Wow! What a boondoggle this was. I burned a half day chasing this down.
Comment