Moving Averages
Info
The Moving Averages is a Library for MetaTrader 5 that the movingaverages library is a part of standard package of metatrader 5 client terminal. The library contains functions for calculation of different types of moving averages.
Usage
This tool is typically used for enhancing chart analysis and decision making.
Platform
This Library works exclusively on MetaTrader 5 (both build 600+ and newer versions).
Setup
Place the downloaded file in MQL5/Libraries folder via File ? Open Data Folder in MetaTrader 5.
How to Install and Use Moving Averages
1. Storage: Place library files in the MQL/Libraries directory to ensure they are accessible to your projects.
2. Implementation: Include the library in your code using the #import directive, ensuring you match the exact function names and parameters.
3. Compilation: Ensure the library is present in the directory before you compile your main EA or script, as the compiler links them during this phase.
4. Management: Keep libraries organized in sub-folders if you manage many custom functions to maintain a clean project structure.
Frequently Asked Questions
Q: What is a library file used for? A: Libraries store reusable code modules, allowing you to centralize common logic used by multiple EAs or indicators.
Q: Is a library executable? A: No, libraries are non-executable files containing functions; they must be imported into an EA, indicator, or script to function.
Q: Can I update a library while the platform is running? A: You should compile your EA or script after updating a library to ensure the latest code changes are integrated.
What this tool does
The MovingAverages library is a part of Standard package of MetaTrader 5 client terminal.
Typical Use Case
This Library excels in automated trading and technical analysis on MetaTrader 5.
Compatible Platform & Setup
This Library works on MetaTrader 5. Place the file in the MQL5/Libraries folder and restart the terminal.
Description & Settings
Related: The Moving Average Class - another powerful library for MetaTrader 5 traders.
The MovingAverages library is a part of Standard package of MetaTrader 5 client terminal.
The library contains functions for calculation of different types of moving averages. Totally, there are 8 functions that can be divided into 2 groups of functions of the same type, each containing 4 of them.
Also recommended: Interpreter - behavioral design pattern - similar library with strong performance on MetaTrader 5.
The first group contains functions that receive an array and simply return a value of a moving average at a specified position:SimpleMA() - for calculating the value of a simple average;
ExponentialMA() - for calculating the value of an exponential average;
SmoothedMA() - for calculating the value of a smoothed average;
LinearWeightedMA() - for calculating the value of a linear-weighted average.
These functions are intended for obtaining the value of an average once for an array, and are not optimized for multiple calls. If you need to use a function from this group in a loop (to calculate values of an average and further write each calculated value into an array), you'll have to organize an optimal algorithm.
The second group of functions is intended for filling out the recipient array by values of a moving average based on the array of initial values:
SimpleMAOnBuffer() - fills out the output array buffer[] by values of a simple average from the price[] array;
ExponentialMAOnBuffer() - fills out the output array buffer[] by values of an exponential average from the price[] array;
SmoothedMAOnBuffer() - fills out the output array buffer[] by values of a smoothed average from the price[] array;
LinearWeightedMAOnBuffer() - fills out the output array buffer[] by values of a linear weighted average from the price[] array.
Functions://+------------------------------------------------------------------+ //| MovingAverages.mqh | //| Copyright 2009, MetaQuotes Software Corp. | //| | //+------------------------------------------------------------------+ #property copyright "2009, MetaQuotes Software Corp." #property link " //+------------------------------------------------------------------+ //| Simple Moving Average | //+------------------------------------------------------------------+ double SimpleMA(const int position,const int period,const double &price[]) //+------------------------------------------------------------------+ //| Exponential Moving Average | //+------------------------------------------------------------------+ double ExponentialMA(const int position,const int period,const double prev_value,const double &price[]) //+------------------------------------------------------------------+ //| Smoothed Moving Average | //+------------------------------------------------------------------+ double SmoothedMA(const int position,const int period,const double prev_value,const double &price[]) //+------------------------------------------------------------------+ //| Linear Weighted Moving Average | //+------------------------------------------------------------------+ double LinearWeightedMA(const int position,const int period,const double &price[]) //+------------------------------------------------------------------+ //| Simple moving average on price array | //+------------------------------------------------------------------+ int SimpleMAOnBuffer(const int rates_total,const int prev_calculated,const int begin, //+------------------------------------------------------------------+ //| Exponential moving average on price array | //+------------------------------------------------------------------+ int ExponentialMAOnBuffer(const int rates_total,const int prev_calculated,const int begin, const int period,const double& price[],double& buffer[]) //+------------------------------------------------------------------+ //| Smoothed moving average on price array | //+------------------------------------------------------------------+ int SmoothedMAOnBuffer(const int rates_total,const int prev_calculated,const int begin, const int period,const double& price[],double& buffer[]) //+------------------------------------------------------------------+ //| Linear Weighted moving average on price array | //+------------------------------------------------------------------+ int LinearWeightedMAOnBuffer(const int rates_total,const int prev_calculated,const int begin, const int period,const double& price[],double& buffer[])
Example:
For examples of its use see article "MQL5: Create Your Own Indicator"
You may also like: Regular Expressions in MQ L5 for working with regular expressions - excellent alternative for library users on MetaTrader 5.
⚠ Limitations & Risk Warning
- This tool is provided for educational and testing purposes only.
- Past performance does not guarantee future results.
- Trading involves substantial risk of loss. Use on a demo account first.
- Results may vary depending on market conditions, broker, and settings.
- We recommend thorough backtesting and forward testing before using with real funds.