A candle store lets you set a list of any technical analysis calculations from the FXB.ta library, and have these automatically updated when the candle data changes.
For example, you can initialise the candle store with a moving average and ATR. These calculations then automatically update whenever candles are loaded into the store (and before any event handlers are called):
var myCandleStore = new FXB.CandleStore({
// Automatically add a moving average and ATR
ta: [
new FXB.ta.EMA({period: 20, member: "h"}), // EMA of high (.h) price
new FXB.ta.ATR({period: 14}) // ATR
],
… further initialisation settings
You can set up technical analysis calculations in two ways. You can provide a
var myCandleStore = new FXB.CandleStore({
// Single TA object
ta: new FXB.ta.EMA({period: 20, member: "h"}), // EMA of high (.h) price
Or, at any time after creation of the store, you can use the
myCandleStore.AddTA(new FXB.ta.RSI({period: 30}));
myCandleStore.AddTA(new FXB.ta.Stochastic({kPeriod: 5, dPeriod: 3, slowing: 3}));
Instead of providing an instance of the analysis class, such as
myCandleStore.AddTA({indicatorType: "Stochastic", kPeriod: 5, dPeriod: 3, slowing: 3});
// Has the same effect as…
myCandleStore.AddTA(new FXB.ta.Stochastic({kPeriod: 5, dPeriod: 3, slowing: 3}));
You can subsequently read the calculations using the candle store's
var currentRSI = myCandleStore.ta[0].GetCurrentValue();
var currentStochastic = myCandleStore.ta[1].GetCurrentValue();
You can add calculations, using
As a service to make your code easier to read, there is a further way of addressing technical analysis calculations. When creating a calculation you can include an
myCandleStore.AddTA(new FXB.ta.EMA({period: 20, alias: "ema20"}));
You can then refer to calculations via their alias using a
// Calculations can always be addressed via their numeric index, in order of creation…
var currentEma = myCandleStore.ta[1].GetCurrentValue();
// But the code becomes more readable if the access is given a name rather than a number…
var currentEma = myCandleStore.$ta("ema20").GetCurrentValue();