iACfunc_v1
Download scriptThis script is a specialized calculation tool designed for the MetaTrader trading platform. Its primary purpose is to generate a specific technical analysis indicator known as the Accelerator Oscillator (AC), which helps traders understand the momentum of price movements.
How the Logic Works
The script operates by performing a multi-layered mathematical calculation to smooth out market noise and highlight underlying trends. It achieves this through a three-step process:
1. Determining the Base Momentum (AO) First, the script looks at the current price of an asset over two different timeframes (periods). By calculating the difference between these two moving averages, it identifies the "Oscillator" value. This step essentially measures how quickly the price is moving relative to its recent history.
2. Creating a Data Buffer Instead of looking at just one single point in time, the script creates a temporary "buffer"—a collection of historical data points. It calculates the momentum for a wide range of previous bars to ensure that the final result is based on a consistent and stable sequence of information.
3. Calculating the Final Acceleration (AC) In the final step, the script takes the momentum values calculated in the first step and applies one final moving average to them. By subtracting this smoothed average from the current momentum, it produces the "Accelerator Oscillator."
Key Takeaways for the User
- Trend Smoothing: By using moving averages at multiple stages, the tool filters out minor price fluctuations, allowing traders to see the broader direction of the market more clearly.
- Customizable Inputs: The logic is flexible; it allows you to define exactly which price types to use, how many past periods to look back at, and the specific type of moving average calculation you prefer.
- Dynamic Calculation: The script automatically adjusts to the current symbol and timeframe you are viewing on your chart, ensuring the data remains relevant as you switch between different assets (like Forex pairs or stocks).
//+------------------------------------------------------------------+
//| iACfunc.mq4 |
//| Author: paladin80 |
//| E-mail: forevex@mail.ru |
//+------------------------------------------------------------------+
#property copyright "paladin80"
#property link "forevex@mail.ru"
#property library
//--------------------------------------------- iACfunc() - ñòàðò ------------------------------------------------------------
//+----------------------------------------------------------------------------+
//| Âõîäíûå ïàðàìåòðû: |
//| Sy - ñèìâîë. |
//| Tf - ïåðèîä ãðàôèêà. |
//| MA_mode - ñêîëüçÿùàÿ ñðåäíÿÿ. |
//| Applied_price - ïðèìåíÿåìàÿ öåíà. |
//| Period_1 , Period_2 , Period_3 - ïåðèîäû äëÿ ðàñ÷¸òà èíäèêàòîðà |
//| (ñì. ôîðìóëû íèæå). |
//| Shift - èíäåêñ ïîëó÷àåìîãî çíà÷åíèÿ èç èíäèêàòîðíîãî áóôåðà. |
//+----------------------------------------------------------------------------+----+
//| Ôîðìóëû äëÿ ðàñ÷¸òà ñòàíäàðòíîé AC (http://codebase.mql4.com/ru/230) |
//| Ôóíêöèÿ iACfunc() ðàññ÷èòûâàåòñÿ â ñîîòâåòñòâèè ñ íèæåïðèâåä¸ííûìè ôîðìóëàìè: |
//| AO = MA_mode (Applied_price, Period_1) - MA_mode (Applied_price, Period_2) |
//| AC = AO - MA_mode (AO, Period_3) |
//+---------------------------------------------------------------------------------+
double iACfunc(string Sy,int Tf,int MA_mode,int Applied_price,int Period_1,int Period_2,int Period_3,int Shift)
{
double AOBuffer[], AC;
if (Sy=="" || Sy=="0") Sy=Symbol();
int limit=MathMax(MathMax(Period_1,Period_2),Period_3)-1+Shift;
ArrayResize(AOBuffer,limit);
for (int i=0; i<=limit; i++)
{
AOBuffer[i]=iMA(Sy,Tf,Period_1,0,MA_mode,Applied_price,i)-iMA(Sy,Tf,Period_2,0,MA_mode,Applied_price,i);
}
ArraySetAsSeries(AOBuffer,true);
AC=AOBuffer[Shift]-iMAOnArray(AOBuffer,0,Period_3,0,MA_mode,Shift);
return(AC);
}
//--------------------------------------------- iACfunc() - êîíåö ----------------------------------------------------------
Comments