MACD divergence between waves

To add comments, please log in or register
iAndi
7
iAndi  
#include <MovingAverages.mqh>

#property indicator_separate_window
#property indicator_buffers 4

input int InpFastEMA = 12;
input int InpSlowEMA = 26;
input int InpSignalSMA = 9;
input int InpWidth = 2;

double ExtMacdBufferRed[];
double ExtMacdBufferMaroon[];
double ExtMacdBufferGreen[];
double ExtMacdBufferLime[];

int OnInit( void )
{
        SetIndexStyle( 0, DRAW_HISTOGRAM, STYLE_SOLID, InpWidth, Red );
        SetIndexStyle( 1, DRAW_HISTOGRAM, STYLE_SOLID, InpWidth, Maroon );
        SetIndexStyle( 2, DRAW_HISTOGRAM, STYLE_SOLID, InpWidth, Green );
        SetIndexStyle( 3, DRAW_HISTOGRAM, STYLE_SOLID, InpWidth, Lime );
        
        SetIndexBuffer( 0, ExtMacdBufferRed );
        SetIndexBuffer( 1, ExtMacdBufferMaroon );
        SetIndexBuffer( 2, ExtMacdBufferGreen );
        SetIndexBuffer( 3, ExtMacdBufferLime );
        
        IndicatorShortName( "MACD 4C" );
        
        return INIT_SUCCEEDED;
}

int OnCalculate
(
        const int rates_total,
        const int prev_calculated,
        const datetime& time[],
        const double& open[],
        const double& high[],
        const double& low[],
        const double& close[],
        const long& tick_volume[],
        const long& volume[],
        const int& spread[]
)
{
        int limit, i;
        
        if( rates_total <= InpSignalSMA )
        {
                return 0;
        }
        
        limit = ( rates_total - prev_calculated );
        
        if( prev_calculated > 0 )
        {
                limit++;
        }
        
        double prevVal = 0;
        
        for( i = 0; i < limit; i++ )
        {
                double fastMa = iMA( NULL, 0, InpFastEMA, 0, MODE_EMA,PRICE_CLOSE, i );
                double slowMa = iMA( NULL, 0, InpSlowEMA, 0, MODE_EMA,PRICE_CLOSE, i );
                
                double currVal = ( fastMa - slowMa );
                //Alert("Fast iMA: ", fastMa);
                //Alert("Slow iMA: ", slowMa);
                if( currVal > 0 )
                {
                        if( currVal > prevVal )
                        {
                                ExtMacdBufferGreen[i] = currVal;
                        }
                        else
                        {
                                ExtMacdBufferLime[i] = currVal;
                        }
                }
                else
                {
                        if( currVal < prevVal )
                        {
                                ExtMacdBufferRed[i] = currVal;
                        }
                        else
                        {
                                ExtMacdBufferMaroon[i] = currVal;
                        }
                }
                
                prevVal = currVal;
        }
        
        return rates_total;
}

Hello,

I have created a small macd for metatrader. I want to use it to find divergence between two waves.

As you can see in the picture, i have labeled the waves ABC. That is labeled like that because we have a divergence between A waves and C wave. The macd draws the waves in the histogram and we can see with our eyes the divergence between the two waves.
I want to know how can i mathematically calculate that divergence. The reason for this is to have proper labeling. ABC or WXY.

To add comments, please log in or register