NT Folks, I'd like to get your insight into the workspace errors that can cause and correct, "Object reference not set to an instance of an object."
It's not uncommon I get this error when activating this strategy, and the strategy fails to activate.
In the output window, I get error:
Strategy 'Base1': Error on calling 'OnStateChange' method: Object reference not set to an instance of an object.
Well, I've reduced my OnStateChange to debug statements only:
protected override void OnStateChange() {
if (State == State.SetDefaults) {
Print("At time " + Time[0] + " Statement 5");
} else if (State == State.DataLoaded) {
Print("At time " + Time[0] + " Statement 6");
} else if (State == State.Configure) {
Print("At time " + Time[0] + " Statement 7"); }
}
No object is being referenced within OnStateChange. I've found I'm able to <sometimes> correct this error by:
- Waiting. Sometimes if I wait 15 minutes, to the next day, if I then activate the exact same strategy and parameters, then the strategy activates.
- Resetting NT. If I close down NT and restart it, then the strategy may activate.
- Making a copy of the strategy. If I copy the strategy to a new name, and then load up into the same chart and parameters, then the strategy may activate.
- Within the chart, if I reload all Ninjascript, or reload all historical data, then this issue may be corrected.
From a prior support discussion on this issue:
the advice is to restart the workspaces, and maybe repair the database.
It really seems like this error is caused more by the state of NT, than a coding issue. I really dislike the Restart NT solutions. As I'm running and tracking hundreds of strategies during the day, resetting NT is a major issue. Resetting zeros out strategy realized/unrealized amounts, making it difficult to track strategy performance during the day and over the course of the week.
Therefore, it seems like this boils down to two issues:
- Do you have any direction for a code solution?
- Since this error seems to be NT state driven (internal), can you log an enhancement request to dig into this issue and resolve?
Thanks for your help,
Comment