The
However, the library also provides a way of creating moving-average calculations where the type of moving average is supplied as a variable, using the
var maType = "ema";
var parameters = {period: 30, member: "typical"};
// Create a type of moving average via the maType variable.
// Ends up being equivalent to: someMA = new FXB.ta.EMA(parameters);
var someMA = FXB.ta.CreateMovingAverage("ema", parameters);
Some calculations in the
// Change the bands calculation to use a Hull MA instead of the default SMA
var bands = new FXB.ta.Bands({period: 20, deviations: 2, maType: "hull"});
The types of moving average are as follows. Each has both a numeric and a textual ID, and you can use either:
| Numeric | Textual | FXB.ta. | Description |
| 0 | sma | SMA | Simple moving average |
| 1 | ema | EMA | Exponential moving average |
| 4 | vma | VMA | Variable moving average |
| 5 | vidya | VIDYA | Volatility Index Dynamic Average |
| 7 | wma | WMA | Weighted moving average |
| 8 | smma | SMMA | Smoothed moving average |
| 9 | hull | HullMA | Hull moving average |
| 10 | lsma | LSMA | Least-squares moving average |
| 11 | alma | ALMA | Arnaud Legoux moving average |
| 12 | dema | DEMA | Double exponential moving average |
| 13 | tema | TEMA | Triple exponential moving average |
| 14 | smaofsma | SMAofSMA | Simple moving average of a simple moving average |
| 15 | emaofema | EMAofEMA | Exponential moving average of an exponential moving average |
| 16 | mcginley | McGinleyMA | McGinley dynamic moving average |
| 17 | ama | AMA | Adaptive moving average |
Giving another version of the example above, you can create a least-squares moving average in two ways:
var ma = new FXB.ta.LSMA({period: 20});
…
var ma = FXB.ta.CreateMovingAverage(10, {period: 20}); // 10 = "lsma" = FXB.ta.LSMA()
All moving averages need a
Some of the types of moving average also require other parameters, though these have standard defaults and you may not want to change them or specify them explicitly:
| Moving average | Extra parameters |
| ALMA | Uses |
| AMA | Uses |
| SMAofSMA | Uses a |
| EMAofEMA | Same as |
| VIDYA | Uses a |
These extra parameters can be added to the ID of a moving average when creating an instance of the calculation via a variable. For example, the ID "alma:0.9:5" (or "11:0.9:5") means "ALMA, with an offset of 0.9 and sigma of 5". Similarly, "ama:5:15" (or "17:5:15") means "AMA, with a fast period of 5 and slow period of 15".