DinexSpace Rolling Statistics Library
- librerie
- Versione: 1.0
DinexSpace Rolling Statistics Library is a library for MetaTrader 5 (MT5) that keeps rolling statistics of a series of numbers for your indicator or Expert Advisor: mean, standard deviation, z-score, percent rank, correlation and autocorrelation. You push one value at a time and read the result, without writing the window code yourself.
How it works
- Call DxRsCreate with the window length. You get a handle.
- Call DxRsPush for each new value (for example the close of each new bar).
- Read the statistic you need with the handle. When something cannot be calculated, the function returns EMPTY_VALUE and DxRsLastError tells why.
What you get
- Mean, variance and standard deviation of the last N values, updated one value at a time.
- Z-score and percent rank of the newest value in the window.
- Correlation of two series (pair instance) and autocorrelation of one series at the lag you choose.
- Min, max and the value that was pushed N steps ago.
- Stable numbers: values with a large offset keep their precision, and the window is recomputed exactly from time to time.
- Status codes with plain-English texts: not enough values, zero variance, bad lag, value not a number.
- Light: each program has its own instances. No DLLs, no web requests, no Sleep.
How to use it
- Copy DinexRollingStats.ex5 to MQL5\Libraries.
- Add the import block with the functions you use (shown in the images and in the example EA).
- Create a window, push each new value, read the statistic.
Example EA (included in the description images)
On every new bar the example pushes the close price into several windows and compares each statistic with a direct two-pass calculation on the same values. At the end it prints the number of checks and the number of failed checks.
Notes
- The sample standard deviation divides by N − 1. Percent rank is the number of values below the newest one, divided by N − 1.
- Min, max, percent rank and autocorrelation read the whole window; the other statistics are updated in constant time.
- The library describes numbers you give it. It gives no entries or exits and does not predict any move.
Requirements
- MetaTrader 5, any symbol and timeframe.
