MACD_AK
Download scriptThis custom indicator is designed to provide a more nuanced visual representation of market momentum by enhancing the standard Moving Average Convergence Divergence (MACD) analysis. Instead of relying on a single data stream, it breaks down market movement into several distinct components to help traders identify the strength and direction of price trends more clearly.
Core Logic Overview
The tool functions by comparing two primary moving averages—a "Fast" average and a "Slow" average—to determine the gap between short-term price action and long-term trends. While a standard MACD simply shows this difference, this script analyzes the acceleration of those averages.
Key Features and Visual Components
-
Primary Momentum (Base Histogram): The indicator starts by calculating the fundamental difference between the fast and slow moving averages. This establishes the basic baseline of whether the market is currently trending upwards or downwards.
-
Momentum Acceleration Tracking: The script performs a deeper analysis by looking at "deltas"—essentially measuring the change in the moving averages over recent candles. It categorizes these changes into four distinct visual buffers:
- Positive Acceleration: It identifies instances where the fast average is not only rising but is increasing at a faster rate than it did in previous periods.
- Negative Acceleration: Conversely, it tracks when the slow average shows specific patterns of deceleration or acceleration relative to the fast average.
- Dynamic Highlighting: By separating these movements into different buffers, the indicator can visually distinguish between "steady" trends and "aggressive" moves, allowing users to see if a trend is gaining steam or beginning to tire out.
-
The Signal Line: To provide a smoother perspective on the data, the script calculates a "Signal Line." This is a secondary moving average of the primary MACD values. It acts as a stabilizer, helping traders identify crossover points where momentum may be shifting from one direction to another.
Summary for the Trader
Instead of providing a single line that can sometimes be noisy, this logic decomposes price movement into specific "speed" and "acceleration" zones. It allows you to see not just where the price is going, but how fast it is getting there, by highlighting different types of trend behavior in separate visual layers.
//+------------------------------------------------------------------+
//| Custom MACD_AK.mq4 |
//| Copyright © 2009, ALEXKUD. |
//| http://www.alexkud.com/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 6
#property indicator_color1 Silver
#property indicator_color2 Green
#property indicator_color3 MediumBlue
#property indicator_color4 Red
#property indicator_color5 Yellow
#property indicator_color6 Red
//#property indicator_color3 Blue
#property indicator_width1 4
#property indicator_width2 4
#property indicator_width3 2
#property indicator_width4 4
#property indicator_width5 2
//---- indicator parameters
extern int FastEMA=5;
extern int SlowEMA=18;
extern int SignalSMA=1;
//---- indicator buffers
double MacdBuffer[];
double MacdBufferu2[];
double MacdBufferu3[];
double MacdBufferu4[];
double MacdBufferu5[];
double SignalBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- drawing settings
SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexStyle(1,DRAW_HISTOGRAM);
SetIndexBuffer(1,MacdBufferu2);
SetIndexStyle(2,DRAW_HISTOGRAM);
SetIndexBuffer(2,MacdBufferu3);
SetIndexStyle(3,DRAW_HISTOGRAM);
SetIndexBuffer(3,MacdBufferu4);
SetIndexStyle(4,DRAW_HISTOGRAM);
SetIndexBuffer(4,MacdBufferu5);
SetIndexStyle(5,DRAW_LINE);
SetIndexDrawBegin(5,SignalSMA);
IndicatorDigits(Digits+1);
//---- indicator buffers mapping
SetIndexBuffer(0,MacdBuffer);
SetIndexBuffer(5,SignalBuffer);
//SetIndexStyle(2,DRAW_HISTOGRAM);
//SetIndexBuffer(2,MacdBuffer2);
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("MACD_AK ALEXKUD.COM("+FastEMA+","+SlowEMA+","+SignalSMA+")");
SetIndexLabel(0,"MACD_AK");
SetIndexLabel(5,"Signal");
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//---- macd counted in the 1-st buffer
for(int i=0; i<limit; i++)
{
MacdBuffer[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
}
for(i=0; i<limit; i++)
{
double MA=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i);
double MA1=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i+1);
double MA2=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i+2);
double delta=MA-MA1;
double delta1=MA1-MA2;
if((delta>delta1 && delta>0) )//|| (delta<0 && delta1>=0)
MacdBufferu2[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
}
for(i=0; i<limit; i++)
{
MA=iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
MA1=iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i+1);
MA2=iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i+2);
delta=MA-MA1;
delta1=MA1-MA2;
if((delta>=delta1 && delta>0) )//|| ( && delta1>=0))||(delta<=delta1 && delta<0
MacdBufferu3[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
}
for(i=0; i<limit; i++)
{
MA=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i);
MA1=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i+1);
MA2=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i+2);
delta=MA-MA1;
delta1=MA1-MA2;
if((delta<=delta1 && delta<0) )//|| (delta<0 && delta1>=0)
MacdBufferu4[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
}
for(i=0; i<limit; i++)
{
MA=iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
MA1=iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i+1);
MA2=iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i+2);
delta=MA-MA1;
delta1=MA1-MA2;
if((delta<=delta1 && delta<0) )//|| ( && delta1>=0))||(delta<=delta1 && delta<0
MacdBufferu5[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
}
//---- signal line counted in the 2-nd buffer
for(i=0; i<limit; i++)
SignalBuffer[i]=iMAOnArray(MacdBuffer,Bars,SignalSMA,0,MODE_SMA,i);
//---- done
return(0);
}
//+------------------------------------------------------------------+
Comments