To improve speed, I am trying to avoid re-instantiation my custom indicator. I built a method inside my custom indicator called ResetMyIndicator() which my strategy calls during State.DataLoaded. Inside the ResetMyIndicator() I reset various variables and I also instantiate that native indicators. However, when I run my strategy in Optimization, I get the following error:
Strategy 'MyStragetyName': Error on calling 'OnStateChange' method: Object reference not set to an instance of an object.
System.NullReferenceException: 'Object reference not set to an instance of an object.'
{
if (cacheSwing != null)
for (int idx = 0; idx < cacheSwing.Length; idx++)
if (cacheSwing[idx] != null && cacheSwing[idx].Strength == strength && cacheSwing[idx].EqualsInput(input))
return cacheSwing[idx];
return CacheIndicator<Swing>(new Swing(){ Strength = strength }, input, ref cacheSwing);
}
public void ResetMyIndicator(){
mySwing = Swing(strength: 10);
// other variable resets not shown
}

Comment