The
A simple example of
// Subtract arr2 from arr1
var arr1 = [2, 4, 7, 8];
var arr2 = [5, 3, 7, 2];
var res = FXB.ta.ArrayCombine("subtract", arr1, arr2); // Returns [-3, 1, 0, 6]
Valid operations to perform on the arrays are
Each "array" parameter can in fact be one of three things:
A simple array of values, as in the example above
A list of candles plus the value to use from each candle
A single fixed value
You define a candle input as follows - an object containing a
{
member: "median", // Value to use from each candle, including derived properties
candles: [{o:1.2342, h: 1.2347, l: 12341, c: 1.2343}, …] // Array of candle data
}
For example, you can calculate the range - the difference between high and low - of an array of candles as follows:
// Array of candles to calculate from
var arrCandles = [{o:1.2342, h: 1.2347, l: 12341, c: 1.2343}, …];
// Subtract the low of each candle from the high of each candle - uses the same arrCandles
// for both parameters, but different members
var ranges = FXB.ta.ArrayCombine(
"subtract",
{member: "h", candles: arrCandles},
{member: "l", candles: arrCandles}
);
An input parameter can also be a
var arr1 = [2, 4, 7, 8];
var res = FXB.ta.ArrayCombine("multiply", arr1, {fixedValue: 2}); // Returns [4, 8, 14, 16]
Putting these examples together, you can do something such as calculating a moving average, calculating ATR, doubling the value of the ATR, and adding that to the moving average - which creates the upper band of a Keltner channel. For example:
// Calculate a moving average and ATR on an array of candles
var candles = [{o:1.2342, h: 1.2347, l: 12341, c: 1.2343}, …];
var ma = new FXB.ta.EMA({period: 20, data: candles});
var atr = new FXB.ta.ATR({period: 10, data: candles});
// Calculate double the ATR, using ArrayCombine()
var arrDoubleATR = FXB.ta.ArrayCombine("multiply", atr.GetValueArray(), {fixedValue: 2});
// Add double the ATR to the moving average, using ArrayCombine()
var arrKeltnerUpper = FXB.ta.ArrayCombine("add", ma.GetValueArray(), arrDoubleATR);