As described above, calculations can be either bar-based or value-based. For bar-based calculations, what you pass to
An array of candles: objects containing an
An object containing a
For example, to load an array of candle objects:
myATR.LoadData([{o:1.2342, h: 1.2347, l: 12341, c: 1.2343}, … ]);
Or, to load in a
myATR.LoadData({
valueCount: 500, // Compulsory: number of items in the arrays
barData: {
open: [1.2342, 1.2340, 1.2345, …],
high: [ …],
low: [ … ],
close: [ … ],
volume: [ … ] // Volume is optional, and defaults to zero if omitted
}
});
Similarly, in a bar-based calculation, what you pass to
// When the current candle changes, use UpdateCurrent() with the single current candle object
myATR.UpdateCurrent({o:1.2342, h: 1.2347, l: 12340, c: 1.2340});
With a
// In UpdateCurrent(), only the first entry in each array is used
myATR.UpdateCurrent({
barData: {
open: [1.2342, …],
high: [ …],
low: [ … ],
close: [ … ],
volume: [ … ] // Volume is optional, and defaults to zero if omitted
}
});
However, there is a further refinement.
UDI.onCalculate = function(data, output) {
// Create an ATR calculation if we don't already have one
if (!UDI.$myATR) UDI.$myATR = new FXB.ta.ATR({period: 14});
// Pass the data into the ATR calculation.
// If data.
UDI.$myATR.LoadData(data);
…
};