DinexSpace Moving Averages Library
- 라이브러리
- 버전: 1.0
DinexSpace Moving Averages Library is a library for MetaTrader 5 (MT5) that calculates moving averages for your indicator or Expert Advisor, one value at a time. Eight kinds are included: SMA, EMA, WMA, SMMA, HMA, DEMA, TEMA and KAMA. You push each new value and read the latest average, without a pass over the whole history and without creating indicator handles.
How it works
- Call DxMaCreate with the kind and the period. You get a handle.
- Call DxMaPush for each new value (for example the close of each new bar).
- Read the latest average with DxMaValue. Until there are enough values the function returns EMPTY_VALUE; DxMaWarmup tells you how many values each kind needs.
- Or give a whole array to DxMaSeries and get the series back.
What you get
- Eight kinds in one set of calls: SMA, EMA, WMA, SMMA (also called RMA), HMA, DEMA, TEMA and KAMA.
- One value at a time: each new value updates the average in constant time.
- Batch call: an array in, the whole series out, with EMPTY_VALUE before the warm-up count.
- Checked: the example EA compares every output with a separate whole-array calculation and, for SMA, EMA, LWMA and SMMA, with the built-in iMA.
- Stable numbers: values with a large offset keep their precision, and sums are recalculated exactly from time to time.
- Status codes with plain-English texts: bad kind, bad period, bad value, no instance available.
- Light: each program has its own instances. No DLLs, no web requests, no Sleep.
How to use it
- Copy DinexMovingAverages.ex5 to MQL5\Libraries.
- Add the import block with the functions you use (shown in the images and in the example EA).
- Create an average, push each new value, read the result.
Definitions (n = period)
- SMA: mean of the last n values. WMA: weights 1 to n, the newest value has weight n.
- EMA: alpha = 2 / (n + 1). The first output, after n values, is the simple mean of those n values; then e = e + alpha x (x − e). SMMA: the same with alpha = 1 / n. Because of the start, EMA and SMMA differ from iMA on the first bars and converge to it.
- HMA: WMA over the square root of n (rounded down) of 2 x WMA(n / 2) − WMA(n); n / 2 is rounded down too.
- DEMA: 2 x E1 − E2. TEMA: 3 x E1 − 3 x E2 + E3. Each EMA is taken over the one before.
- KAMA: Kaufman adaptive average. Efficiency ratio over n values, fast and slow periods (default 2 and 30). The first output is the value that completes n + 1 values.
Example EA (included in the description images)
On every new bar the example pushes the close price into 16 averages and into 8 averages of a series with a large offset, and at the end compares every output with a separate calculation and with iMA. It prints the number of checks and the number of failed checks.
Notes
- The library works on the numbers you give it. It reads no market data, gives no entries or exits and does not predict any move.
- Up to 256 instances, period up to 10 000 (HMA and KAMA from 2).
Requirements
- MetaTrader 5, any symbol and timeframe.
