User login

  

Trading with MACD indicator includes the following signals:

MACD lines crossover — a trend is changing

MACD historam staying above zero line — market is bullish, below — bearish.

MACD histogram flipping over zero line — confirmation of a strength of a current trend.

MACD histogram diverges from price on the chart — signal of an upcoming reversal.

MACD

MACD is the simplest and very reliable indicators used by many Forex traders.

MACD (Moving Average Convergence/Divergence) has in its base Moving Averages.

It calculates and displays the difference between the two moving averages at any time. As the market moves, moving averages move with it, widening (diverging) when the market is trending and moving closer (converging) when the market is slowing down and possibility of a trend change arise. 

Standard indicator settings for MACD (12, 26, 9) are used in many trading systems, and these are the setting that MACD developer Gerald Appel has found to be the most suitable for both faster and slower moving markets. In order to get a more responsive and faster performance from MACD one can can experiment with lowering MACD settings to, for example, MACD (6, 12, 5), MACD (7, 10, 5), MACD (5, 13, 8) etc.

MACD indicator is based on Moving Averages in their simplest form. MACD measures the difference between faster and slower moving average: 12 EMA and 26 EMA (standard).

MACD line is created when longer Moving Average is subtracted from shorter Moving Average. As a result a momentum oscillator is created that oscillates above and below zero and has no lower or upper limits. MACD also has a Trigger line. Combined in a simple lines crossover strategy, MACD line and trigger line crossover outperforms EMAs crossover.

How does MACD indicator work

If to take 26 EMA and imagine that it is a flat line, then the distance between this line and 12 EMA would represent the distance from MACD line to indicator's zero line.

The further MACD line goes from zero line, the wider is the gap between 12EMA and 26 EMA on the chart. The closer MACD moves to zero line, the closer are 12 and 26 EMA.

MACD histogram measures the distance between MACD line and MACD trigger line.

 

Display/hide source code
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using PTLRuntime.NETScript;
using System.Drawing;
 
namespace ind
{
    [FullRefresh]
    [KillExceptions]    
        public class MACD : NETIndicator
    {
  
        public MACD()
            : base()
        {
                ProjectName = "Moving Average/Convergence Divergence";
                Comments = "A trend-following momentum indicator that shows the relationship between two moving averages of prices";
            SetIndicatorLine("line1", Color.DodgerBlue, 1, LineStyle.SimpleChart);
            SetIndicatorLine("line2", Color.Red, 1, LineStyle.SimpleChart);
            SetIndicatorLine("line3", Color.Green, 1, LineStyle.SimpleChart);
            SeparateWindow = true;      
        }
 
        [InputParameter("FastEMA", 0)]
        public int FastEMA=12;
        [InputParameter("SlowEMA", 1)]
        public int SlowEMA=26;
        [InputParameter("SignalSMA", 2)]
        public int SignalSMA=9;
        
        public IArray MacdBuffer; 
                public IArray SignalBuffer;
                public IArray Histogram;
                
                public override void Init()
                { 
                        mql4.SetIndexStyle(2, mql4.DRAW_HISTOGRAM);
                        platform.SetIndexBuffer(0, ref MacdBuffer);
                        platform.SetIndexBuffer(1, ref SignalBuffer);
                        platform.SetIndexBuffer(2, ref Histogram);
                        mql4.SetIndexLabel(0,"MACD");
                        mql4.SetIndexLabel(1,"Signal");
                        mql4.SetIndexLabel(2,"Histogram");
                }
        
        public override void OnQuote()
        {
           int limit;
                   int counted_bars=platform.IndicatorCounted();
                   if(counted_bars>0) counted_bars--;
                   counted_bars = Math.Max( Math.Max(counted_bars, FastEMA) , Math.Max(SlowEMA, SignalSMA) );
                   limit=mql4.Bars-counted_bars;
                   for(int i=0; i<limit; i++)
                          MacdBuffer[i]=mql4.iMA(mql4.NULL,0,FastEMA,0,mql4.MODE_EMA,mql4.PRICE_CLOSE,i)-mql4.iMA(mql4.NULL,0,SlowEMA,0,mql4.MODE_EMA,mql4.PRICE_CLOSE,i);
                   for(int i=0; i<limit; i++)
                      SignalBuffer[i]=mql4.iMAOnArray(ref MacdBuffer,mql4.Bars,SignalSMA,0,mql4.MODE_SMA,i);
                   for(int i=0; i<limit; i++)
                      Histogram[i]=(double)MacdBuffer[i] - (double)SignalBuffer[i];
                 }
    }    
}
12345

Comments