Avg_MA
Download scriptOverview
This script is a custom technical analysis tool designed for the MetaTrader 5 trading platform. Its primary purpose is to calculate and display an "Average of Moving Averages." Instead of showing you a single trend line, it looks at multiple different moving averages simultaneously and calculates their collective mean to provide a smoothed, consolidated view of market momentum.
Core Logic & Functionality
1. Multi-Layered Calculation The script does not just look at the current price. It builds a sequence of moving averages based on user-defined parameters:
- Dynamic Periods: You can specify a starting period (e.g., 5) and a count (e.g., 5). The script will then automatically calculate a series of moving averages, increasing the time window for each subsequent average based on an "increment" setting.
- Customizable Methods: For every average in the sequence, the user can choose different mathematical models, including Simple (SMA), Exponential (EMA), Smoothed (SMMA), and Linear Weighted (LWMA) averages.
2. Flexible Price Sources The tool is highly versatile regarding which data points it uses to determine these averages. Rather than being restricted to just the "Closing Price," the logic allows the user to choose from:
- Open, High, Low, or Close prices.
- Median prices (the midpoint between high and low).
- Typical prices (an average of high, low, and close).
- Weighted prices (a specific calculation favoring the closing price).
3. Data Handling & Organization
- Dynamic Object Management: The script uses a structured approach to create "objects." Each moving average in your sequence is treated as an independent entity with its own settings for timeframe, period, and calculation method.
- Buffer Mapping: It effectively organizes the data into hidden "calculation buffers" and visible "plot buffers." This ensures that while the complex math happens behind the scenes, the final result is presented clearly on your chart as a single, clean line.
How it Works in Practice
When you load this tool onto a chart, the following sequence occurs:
- Initialization: The script identifies your chosen starting period and the number of averages you want to combine.
- Sequence Building: It generates a list of moving average models (e.g., SMA 5, SMA 10, SMA 15, etc., depending on your step settings).
- Real-Time Processing: On every new price tick, the script pulls the required historical data for all those different models at once.
- Final Averaging: It sums up the results of all those individual moving averages and divides them by the total count to produce the final "Average MA" line shown on your screen.
Summary for the User
This tool is ideal for traders who want to filter out "noise." By averaging multiple moving averages together, it creates a more stable trend indicator that reacts less impulsively to minor price fluctuations while still capturing the broader directional movement of the market.
ÿþ/ / + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
/ / | A v g _ M A . m q 5 |
/ / | C o p y r i g h t 2 0 1 8 , M e t a Q u o t e s S o f t w a r e C o r p . |
/ / | h t t p s : / / m q l 5 . c o m |
/ / + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
# p r o p e r t y c o p y r i g h t "