5.2.2Creating and initialising technical analysis calculations

You set up a technical analysis calculation by creating an instance of the corresponding class in the FXB.ta library. For example:

// Create an exponential moving average

var myEma = new FXB.ta.EMA({period: 20});

// Create an RSI calculation

var myRSI = new FXB.ta.RSI({period: 14});

All calculations require initialisation with parameters, such as a period value, and these are described below in relation to each individual calculation. (All parameters have defaults, but you will generally want to set them explicitly.)

You can include a data[] array in the initialisation of a calculation. This is simply a shortcut for creating the calculation and then calling LoadData() with the array:

var myEma = new FXB.ta.EMA({period: 20, data: [ … ]};

Parameters can be changed after a calculation has been created (rather than replacing the existing object with a new instance of the class). But changes do not take effect until/unless you completely re-load new data into the calculation. For example:

// Create EMA with period=20

var myEma = new FXB.ta.EMA({period: 20});

// Load data

myEma.LoadData( … );

// Change period parameter. Does not have any immediate effect.

myEma.period = 14;

// Values in the calculation do not change until after LoadData() is called again

myEma.LoadData( … );