MACD_ColorHist_Alert_v1

Download script
MACD_ColorHist_Alert_v1

This script is a specialized technical analysis tool designed for the MetaTrader 4 platform. It enhances the standard Moving Average Convergence Divergence (MACD) indicator by providing visual clarity through color-coded data and automated notifications.

Core Functionality

The primary purpose of this tool is to monitor the relationship between two moving averages—the fast and the slow—to identify momentum in the market. It calculates the difference between these averages to create a "MACD Line" and then applies a further smoothing process to generate a "Signal Line."

Visual Logic and Presentation

Unlike standard indicators that may only show a single line or a monochrome histogram, this script provides three distinct visual elements:

  • The MACD Line: A solid line representing the immediate momentum.
  • The Signal Line: A dotted line used as a benchmark for trend direction.
  • The Color Histogram: This is the visual centerpiece of the script. It calculates the gap between the MACD Line and the Signal Line. Depending on whether this gap is positive or negative, the histogram changes color (typically shifting between Green and Red). This allows traders to see at a glance whether momentum is currently trending upward or downward.

Automated Alerts

The script includes an intelligent notification system designed to alert the trader the moment a significant "crossover" occurs. A crossover happens when the MACD line moves from one side of the signal line to the other, often signaling a potential shift in market sentiment.

The logic handles these alerts as follows:

  • Cross Up: If the histogram shifts from a negative value (downward momentum) to a positive value (upward momentum), the script triggers an alert.
  • Cross Down: If the histogram shifts from a positive value to a negative value, the script triggers a corresponding alert.

Notification Options

To ensure the trader does not miss these movements, the script offers two primary methods of communication:

  1. Audio Alerts: A sound notification will play within the MetaTrader platform immediately upon a crossover.
  2. Email Notifications: If enabled, the script can send an automated email containing specific details, including the date, time, currency symbol, and the timeframe of the trade.

Technical Configuration

Users have the flexibility to customize the "speed" of the indicator by adjusting the Fast EMA, Slow EMA, and Signal SMA periods. These settings determine how sensitive the indicator is to price fluctuations, allowing for a balance between capturing quick movements and filtering out market noise.

Price Data Components
Series array that contains open time of each bar
Indicators Used
Moving average indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screenIt sends emails
14 Views
0 Downloads
0 Favorites
MACD_ColorHist_Alert_v1
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//|                                         MACD_ColorHist_Alert.mq4 |
//|                                    Copyright © 2006, Robert Hill |
//|                                                                  |
//+------------------------------------------------------------------+
#property  copyright "Copyright © 2006, Robert Hill"
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 4
#property  indicator_color1  Aqua
#property  indicator_color2  Red
#property  indicator_color3  Green
#property  indicator_color4  Red

//---- indicator parameters

extern bool SoundON=true;
extern bool EmailON=false;

extern int FastEMA=12;
extern int SlowEMA=26;
extern int SignalSMA=9;
//---- indicator buffers
double     ind_buffer1[];
double     ind_buffer2[];
double HistogramBufferUp[];
double HistogramBufferDown[];
int flagval1 = 0;
int flagval2 = 0;
//---- variables

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- drawing settings
//   IndicatorBuffers(3);
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1);
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID);
   SetIndexBuffer(0,ind_buffer1);
   SetIndexDrawBegin(0,SlowEMA);
   SetIndexStyle(1,DRAW_LINE,STYLE_DOT);
   SetIndexBuffer(1,ind_buffer2);
   SetIndexDrawBegin(1,SignalSMA);
   SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID);
   SetIndexBuffer(2,HistogramBufferUp);
   SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_SOLID);
   SetIndexBuffer(3,HistogramBufferDown);
//   SetIndexDrawBegin(2,SlowEMA + SignalSMA);
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("MACD("+FastEMA+","+SlowEMA+","+SignalSMA+")");
   SetIndexLabel(0,"MACD");
   SetIndexLabel(1,"Signal");
   SetIndexLabel(2,"Histogram");
   
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence                           |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   double temp;
   
   int counted_bars=IndicatorCounted();
//---- check for possible errors
   if(counted_bars<0) return(-1);
//---- 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++)
      ind_buffer1[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++)
      ind_buffer2[i]=iMAOnArray(ind_buffer1,Bars,SignalSMA,0,MODE_SMA,i);
//      ind_buffer2[i] = alpha*ind_buffer1[i] + alpha_1*ind_buffer2[i+1];

   for(i=0; i<limit; i++)
   {
      HistogramBufferUp[i] = 0;
      HistogramBufferDown[i] = 0;
      temp = ind_buffer1[i] - ind_buffer2[i];
      if (temp >= 0)
        HistogramBufferUp[i] = temp;
      else
        HistogramBufferDown[i] = temp;
      
      if (i == 1)
      {
        if (HistogramBufferUp[i] > 0 && HistogramBufferDown[i + 1] < 0)
//        if (HistogramBufferUp[i] >  HistogramBufferUp[i + 1])
        {
// Cross up
         if (flagval1==0)
         {
           flagval1=1;
           flagval2=0;
           if (SoundON) Alert("MACD Crossed up","\n Time=",TimeToStr(CurTime(),TIME_DATE)," ",TimeHour(CurTime()),":",TimeMinute(CurTime()),"\n Symbol=",Symbol()," Period=",Period());
           if (EmailON) SendMail("MACD Crossed up", "MACD Crossed up, Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period());
         }
        }
        else if (HistogramBufferDown[i] < 0 && HistogramBufferUp[i + 1] > 0)
//        else if (HistogramBufferUp[i] <  HistogramBufferUp[i + 1] )
        {
// Cross down
         if (flagval2==0)
         {
          flagval2=1;
          flagval1=0;
          if (SoundON) Alert("MACD Crossed down","\n Date=",TimeToStr(CurTime(),TIME_DATE)," ",TimeHour(CurTime()),":",TimeMinute(CurTime()),"\n Symbol=",Symbol()," Period=",Period());
          if (EmailON) SendMail("MACD Crossed down","MACD Crossed Down, Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period());
         }
        }
      }
      
   }
      
//---- done
   return(0);
  }

Comments