All calculations have a primary output value, but some calculations produce other secondary values as well. For example, the Stochastic Oscillator generates not only a primary value but also a "signal" value (typically represented on a chart as a dotted or dashed line).
All classes in the
| Function | Description |
| GetValueArray() | Returns an array of all the primary output values |
| GetValue(idx) | Returns a single output value, using a zero-based index. By default, calculations are indexed newest-first, and #0 is the current, latest value of the calculation. Returns null if the index is not valid (< 0 or >= length). |
| GetCurrentValue() | Shortcut for |
| GetLength() | Get the number of output values. Should always match the number of items in the array passed to |
| length | Length property; alternative and equivalent to |
| HasData() | Shortcut for checking whether a calculation has been initialised. Equivalent to |
| hasData | Has-data property; alternative and equivalent to |
For example, testing whether two moving averages have crossed over since the previous bar:
// Create two moving averages for different periods and load the same data into them
var ma1 = new FXB.ta.EMA({period: 20});
var ma2 = new FXB.ta.EMA({period: 50});
ma1.Load(myDataArray);
ma2.Load(myDataArray);
// Compare the moving averages in the current bar versus the previous bar
if (ma1.GetValue(0) > ma2.GetValue(0) && ma1.GetValue(1) < ma2.GetValue(1)) {
// MA 1 has crossed above MA 2 during current bar (is now > and was <)
} else if (ma1.GetValue(0) < ma2.GetValue(0) && ma1.GetValue(1) > ma2.GetValue(1)) {
// MA 1 has crossed below MA 2 during current bar (is now < and was >)
} else {
// (No cross)
}
As described above, the number of output values will always be the same as the number of input values in the array passed to
For calculations which produce more than one output, the details are described below in relation to each calculation. But there is some standard functionality where a secondary value is returned via
| Function | Description |
| GetSignalArray() | Returns an array of all the secondary, "signal" output values |
| GetSignalValue(idx) | Returns a single signal value, using a zero-based index |
| GetCurrentSignalValue() | Equivalent to |
Some calculations then have further functions for retrieving their output. For example, the Keltner and Bollinger band calculations have