That's more than enough bars. The doc says [1] is the prior candle. This is in real-time data mode, not loading historical data.
Print("EMA(20).Count: " + EMA(20).Count);
Print($"EMA(20)[0]: {EMA(20)[0]}");
double emaStart0 = EMA(20)[0];
Print($"EMA(20)[1]: ...");
double emaStart1 = EMA(20)[1];
Print($"EMA(20)[1] WORKED!!!");
And, the output:
EMA(20).Count: 5472
EMA(20)[0]: 20995.25
EMA(20)[1]: ...
Unhandled exception: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index.
NOTE: EMA(20)[1] works in OnBarUpdate. It throws the above exception in a mouse handler. Yet, the EMA is globally accessible data. Why???
The mouse handler:
protected void MouseClicked(object sender, MouseButtonEventArgs e)
{
// paste above in here
}
Then, add this to OnStateChanged:
else if (State == State.Historical)
{
if (ChartControl != null)
{
ChartControl.MouseLeftButtonDown += MouseClicked;
}
}
Comment