As described in the previous section, the default for
This also means that you should load data newest-first. For example:
// The 1.2349 value in array #0 should be the most recent value, not the oldest value
myEma.LoadData([1.2349, 1.2368, 1.2392, 1.2347, … ]);
However, if you prefer, all
You do this by setting
// Create a calculation with oldestFirst turned on
var myEma = new FXB.ta.EMA({period: 20, oldestFirst: true});
// Data should now be loaded oldest-first, not newest-first
myEma.LoadData([ …, …, …, 1.2347, 1.2392, 1.2368, 1.2349]);
// Because of oldestFirst, GetCurrentValue() is now equivalent to GetValue(length-1),
// not to GetValue(0)
var currentValue = myEma.GetCurrentValue();
At the risk of creating considerable potential confusion and bugs for yourself, it's possible to load data newest-first (because that is how the framework provides it by default) and then to change the indexing to oldest-first before reading the results:
var myEma = new FXB.ta.EMA({period: 20});
// oldestFirst is not yet turned on, and data should be loaded newest-first
myEma.LoadData([1.2349, 1.2368, 1.2392, 1.2347, … ]);
// Turn on oldestFirst, after loading
myEma.oldestFirst = true;
// Because of oldestFirst, the current latest item is in #length-1
var currentValue = myEma.GetValue(myEma.length - 1);
// And GetCurrentValue() is now equivalent to GetValue(length-1), not to GetValue(0)
var alsoCurrentValue = myEma.GetCurrentValue();