iAOfunc
Download scriptThis script is a specialized tool designed for the MetaTrader platform to calculate a specific type of market momentum indicator known as the Awesome Oscillator (AO). Instead of relying on built-in system defaults, this script allows for a highly customizable calculation by breaking down the "momentum" of a price movement into its core mathematical components.
How the Logic Works
The primary purpose of this tool is to determine the difference in speed between two different moving averages. In technical analysis, a moving average helps smooth out price fluctuations to show a clearer trend. By comparing two different versions of these averages, the script identifies whether the market's momentum is accelerating or decelerating.
The core logic follows these steps:
- Dynamic Input Selection: The script is designed to be flexible. It can look at any specific financial instrument (like Gold, EUR/USD, or Bitcoin) and any timeframe (such as 1-minute charts or daily charts). If no specific symbol is selected, it automatically uses the chart you are currently viewing.
- Customizable Smoothing: The user can define exactly how the "Moving Average" is calculated—choosing between different smoothing methods and price types (such as opening prices, closing prices, or a mix of high/low prices).
- The Calculation Process: The script performs a two-part calculation:
- It calculates a "Short-Term" moving average based on a specific period you define.
- It calculates a "Long-Term" moving average based on a different, usually larger, period.
- The Final Result: The script subtracts the Long-Term average from the Short-Term average. This result gives you a single numerical value that represents the "momentum."
Practical Application
By using this logic, traders can see if the current price trend is gaining strength or losing steam. When the resulting value is positive and increasing, it suggests bullish momentum; when it is negative and decreasing, it suggests bearish momentum. Because this script allows you to manually set every variable—from the period lengths to the specific price types used—it provides a level of precision that standard, "out-of-the-box" indicators may lack.
//+------------------------------------------------------------------+
//| iAOfunc.mq4 |
//| Author: paladin80 |
//| E-mail: forevex@mail.ru |
//+------------------------------------------------------------------+
#property copyright "paladin80"
#property link "forevex@mail.ru"
#property library
//--------------------------------------------- iAOfunc() - start ------------------------------------------------------------
//+----------------------------------------------------------------------------+
//| Input parameters: |
//| Sy - Symbol. |
//| Tf - Timeframe. |
//| MA_mode - Applied MA method. |
//| Applied_price - Applied price. |
//| Period_1 , Period_2 - Periods for calculation of indicator |
//| (see formula below) |
//| Shift - Index of the value taken from the indicator buffer. |
//+----------------------------------------------------------------------------+----+
//| Formula for calculation standsrd AO (http://codebase.mql4.com/251) |
//| The function iAOfunc() is calculated according formula: |
//| AO = MA_mode (Applied_price, Period_1) - MA_mode (Applied_price, Period_2) |
//+---------------------------------------------------------------------------------+
double iAOfunc(string Sy,int Tf,int MA_mode,int Applied_price,int Period_1,int Period_2,int Shift)
{
double AO;
if (Sy=="" || Sy=="0") Sy=Symbol();
AO=iMA(Sy,Tf,Period_1,0,MA_mode,Applied_price,Shift)-iMA(Sy,Tf,Period_2,0,MA_mode,Applied_price,Shift);
return(AO);
}
//--------------------------------------------- iAOfunc() - end ------------------------------------------------------------
Comments