I have a short code as test of an indicator based on 5 minutes time frame and I want this indicator to be ploted on a tick chart.
When I plot this indicator on the chart, the plateforme freezees and I obtaine an error message: Object reference not set to an instance of an object.
Usually, the such message comes, that means there is a variable that is not initialized.
But I am not seeing a variable in my code that is not initialized. I would really appreciate if someone could point out where I am mistaking.
I have the following code:
private EMA EMA1;
…
else if (State == State.Configure)
{
AddDataSeries(Data.BarsPeriodType.Minute, 5);
}
else if (State == State.DataLoaded)
{
EMA1 = EMA(BarsArray[1], 21);
}
You’re crossing over logic. Your EMA is on the 5 minute series so it updates every 5 minutes, but you’re assigning it from the other series which can start running as soon as there’s 1 bar on the chart. So if there’s 1 bar on the primary series, there perhaps isn’t any bar on the secondary.
When I remove the line
Value[0] = EMA1[0];
and attach the indicator on the chart, as expected, there is no line on the chart.
The plateforme does not freeze again.
It’s like that because you have 2 series with different intervals.
If you had a 1m primary and a 5m secondary, drawing the line as you are. You’d would see only a change in value every 5 bars so you would see flat line > jump > flat line > jump.