5.2.1Calculation input: bar-based versus value-based calculations

Technical analysis calculations fall into two categories:

"Bar-based" calculations which can only be used with candle data, because they need multiple properties from each candle such as both the high and the low. Examples include ATR and the Stochastic Oscillator.

"Value-based" calculations which can be used with any array of values. For example, all types of moving average can be calculated on candle data, using a specific single value from each candle such as its close or high, but can also be calculated on any series of numbers.

For example, ATR must be calculated from candle data (where each item includes an o, h, l, and c):

var atr = new FXB.ta.ATR({period: 14});

atr.LoadData([{o:1.2342, h: 1.2347, l: 12341, c: 1.2343}, … ]);

Whereas a moving average can be calculated from any array of numbers, as well as on candle data:

// Calculate a moving average of a series of numbers

var ma1 = new FXB.ta.EMA({period: 5});

ma1.LoadData([2, 3, 14, 7, 5, 10, 12, 20, 13, 4, 8]);

// Calculate a moving average of the high of a series of candles

var ma2 = new FXB.ta.EMA({period: 10, member: "h"});

ma2.LoadData([{o:1.2342, h: 1.2347, l: 1.2341, c: 1.2343}, … ]);

This also means that a value-based calculation can be applied to any other technical analysis calculation. For example, you can calculate ATR, and then take the output and calculate Bollinger® Bands on those ATR results:

// Calculate ATR from candle data

var atr = new FXB.ta.ATR({period: 14});

atr.LoadData([{o:1.2342, h: 1.2347, l: 12341, c: 1.2343}, … ]);

// Calculate Bollinger Bands on the ATR results

var bands = new FXB.ta.Bands({period: 20});

bands.LoadData(atr.GetValueArray());