MACD_4ColorHist_2L_SEAlert

MACD_4ColorHist_2L_SEAlert

This script is a custom technical analysis tool designed for the MetaTrader platform. It enhances the standard Moving Average Convergence Divergence (MACD) indicator by adding visual color coding to its histogram and providing a comprehensive automated alert system for various market movements.

Visual Indicators and Customization

The tool provides a dynamic visual representation of the MACD, allowing users to choose which components are visible on their chart:

  • Histogram: Displays the momentum of price movement. The script distinguishes between upward and downward trends by applying specific colors (such as Lime, Red, Dark Green, and Maroon) based on the direction of the movement relative to previous bars.
  • MACD & Signal Lines: Users can toggle the visibility of the main MACD line and the Signal line, allowing for a cleaner chart layout depending on personal preference.
  • Customizable Parameters: The logic is built to be flexible, allowing users to adjust the sensitivity of the "Fast," "Slow," and "Signal" averages to match different trading styles.

Automated Logic and Alert System

The primary functionality of this script is its ability to monitor market conditions in real-time and notify the trader immediately when specific price actions occur. The logic identifies four primary types of events:

1. Zero Line Crossings The script monitors when the MACD line crosses the "Zero" level. A cross from below zero to above (and vice versa) indicates a shift in the overall trend of the market. When this happens, the script can trigger an instant sound alert or send an email notification.

2. Signal Line Crosses The tool tracks the interaction between the MACD line and the Signal line. When the MACD crosses over the Signal line, it typically suggests a change in momentum. The script identifies these "Up" and "Down" crossovers to notify the user of potential entry or exit points.

3. Directional Momentum Changes Beyond simple crosses, the script analyzes the trajectory of the MACD values. It can detect when the histogram begins to rise or fall while still above or below the zero line. This allows traders to see if momentum is accelerating or decelerating before a formal trend change actually occurs.

4. Confirmation Filtering The script includes an optional "Two Bars" confirmation logic. This ensures that alerts are not triggered by "noise" or tiny, insignificant fluctuations; it requires the movement to be sustained over multiple bars to ensure a higher level of reliability in its notifications.

Notification Delivery

To ensure the trader never misses a key moment, the script supports a multi-channel notification system:

  • Audio Alerts: Immediate sound notifications for fast-paced trading.
  • Email Notifications: Direct alerts sent to a registered email address, providing the specific symbol, timeframe, and price at the exact moment the condition was met.
  • Status Tracking: A status display allows users to quickly see whether their preferred alert systems (Sound/Email) are currently active or inactive.
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 sends emails
11 Views
0 Downloads
0 Favorites
MACD_4ColorHist_2L_SEAlert
//+------------------------------------------------------------------+
//|                                         MACD_ColorHist_Alert.mq4 |
//|                                    Copyright © 2006, Robert Hill |
//|                                                                  |
//+------------------------------------------------------------------+
#property  copyright "Copyright © 2006, Robert Hill"
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 6
#property  indicator_color1  Lime
#property  indicator_color2  Red
#property  indicator_color3  DarkGreen
#property  indicator_color4  Maroon
#property  indicator_color5  Aqua
#property  indicator_color6  Yellow

#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2
#property indicator_width4 2
#property indicator_width5 1
#property indicator_width6 1


//---- indicator parameters



extern int FastEMA =5;  //2
extern int SlowEMA =35;  //8
extern int SignalSMA=5;  //6

//extern int  OsmaMultiplier =1;
extern bool ShowHistogram  = true;
extern bool ShowMACDLine   = false;//true
extern bool ShowSignalLine = true;//false

extern bool SoundAlert =true;
extern bool EmailAlert  =false;
extern bool MACDzeroLineCrossAlert   = true;
extern bool MACDSignalLineCrossAlert = true;
extern bool MACDDirectionChangeAlert = false;
extern bool TwoBarsDirChageConfirm   = false;
extern bool ShowAlertStatus = true;
//---- indicator buffers
double     ind_buffer1[];
double     ind_buffer2[];


double HistogramBufferUp[];
double HistogramBufferDown[];

double HistogramBufferUp1[];
double HistogramBufferDown1[];

int flagval11 = 0;
int flagval12 = 0;
int flagval21 = 0;
int flagval22 = 0;
int flagval31 = 0;
int flagval32 = 0;
int flagval41 = 0;
int flagval42 = 0;

//---- variables

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- drawing settings
//   IndicatorBuffers(3);
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1);
   SetIndexBuffer(0,HistogramBufferUp);//lime
   SetIndexBuffer(1,HistogramBufferDown);//red
   SetIndexBuffer(2,HistogramBufferUp1);//green
   SetIndexBuffer(3,HistogramBufferDown1);//maroon
   SetIndexBuffer(4,ind_buffer1);//aqua
   SetIndexBuffer(5,ind_buffer2);//yellow

if(ShowMACDLine)
    {
   SetIndexStyle(4,DRAW_LINE);
   SetIndexDrawBegin(4,SlowEMA);
    }
 else
    {
    SetIndexStyle(4,DRAW_NONE);
    }

if(ShowSignalLine)
    {
   SetIndexStyle(5,DRAW_LINE);
   SetIndexDrawBegin(5,SignalSMA);
    }
 else
    {
    SetIndexStyle(5,DRAW_NONE);
    }
 
 
 if(ShowHistogram)
   {
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexStyle(2,DRAW_HISTOGRAM);
   SetIndexStyle(3,DRAW_HISTOGRAM);
   }
 else
    {
   SetIndexStyle(0,DRAW_NONE);
   SetIndexStyle(1,DRAW_NONE);
   SetIndexStyle(2,DRAW_NONE);
   SetIndexStyle(3,DRAW_NONE);
   }


//   SetIndexDrawBegin(2,SlowEMA + SignalSMA);
//---- name for DataWindow and indicator subwindow label

   if (ShowAlertStatus)
   {
   string _SoundAlert="",_EmailAlert="";
   if(SoundAlert) _SoundAlert="Sound_ON";
   if(!SoundAlert)_SoundAlert="Sound_OFF";
   if(EmailAlert) _EmailAlert="Email_ON";
   if(!EmailAlert)_EmailAlert="Email_OFF";
   }
   IndicatorShortName("MACD ("+FastEMA+","+SlowEMA+","+SignalSMA+")  "+_SoundAlert+"  "+_EmailAlert+" ");
   
   SetIndexLabel(4,"MACD");
   SetIndexLabel(5,"Signal");
   SetIndexLabel(0,"");
   SetIndexLabel(1,"");
   SetIndexLabel(2,"");
   SetIndexLabel(3,"");
   
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence                           |
//+------------------------------------------------------------------+
int start()
{
   int limit;
   double temp,temp1;
   
   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);

   for(i=0; i<limit; i++)
   {
      HistogramBufferUp[i]    = 0.0;//lime
      HistogramBufferDown[i]  = 0.0;//red
      HistogramBufferUp1[i]   = 0.0;//green
      HistogramBufferDown1[i] = 0.0;//maroon
       
//       if (OsmaMultiplier<=0)OsmaMultiplier=1;
//      temp =  ind_buffer1[i]*OsmaMultiplier;
//      temp1 = ind_buffer1[i+1]*OsmaMultiplier;
      
      temp =  ind_buffer1[i];
      temp1 = ind_buffer1[i+1];


    
     if (temp >0) 
       {
          if (temp>temp1)     //>0up
            {       
            HistogramBufferUp[i] = temp;    
            }
            else              //>0dn
            { 
            HistogramBufferUp [i] = 0.0;
            HistogramBufferUp1[i] = temp;   
            }
       }    
      else
       {  
         if (temp>temp1)     //<=0 up
          {       
        HistogramBufferDown[i] = temp; 
          }  
        else                  //<=0 dn
           {
        HistogramBufferDown[i] = 0.0;
        HistogramBufferDown1[i] = temp;  
           }
//---
       }
//-
     if (i == 1)
    {

         if ((ind_buffer1[i] > 0)&&(ind_buffer1[i+1] < 0))
         {
// macd Cross 0 up
         if (flagval11==0)
           {
           flagval11=1;
           flagval12=0;
           flagval32=1;
           if ((SoundAlert)&&(MACDzeroLineCrossAlert)) Alert ("MACD crossed Zero Up! ",Symbol()," TF M",Period()," @ ",Bid); 
                if ((EmailAlert)&&(MACDzeroLineCrossAlert)) SendMail("MACD CrossedZero Up", "MACD CrossedZero Up, Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period());
           }
          }
//
       else if ((ind_buffer1[i]<0 )&&(ind_buffer1[i+1] >0))
        {
//macd Cross 0 down
         if (flagval12==0)
         {
          flagval11=0;
          flagval12=1;
          if ((SoundAlert)&&(MACDzeroLineCrossAlert)) Alert ("MACD crossed Zero Down! " ,Symbol()," TF M",Period()," @ ",Bid); 
               if ((EmailAlert)&&(MACDzeroLineCrossAlert)) SendMail("MACD Crossed Zero Down","MACD CrossedZero Down, Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period());
         }
        }

//
       else if ((ind_buffer1[i] < ind_buffer2[i])&&(ind_buffer1[i+1] > ind_buffer2[i+1]))
         {
//Macd xSigDn
         if (flagval21==0)
           {
           flagval21=1;
           flagval22=0;
           flagval41=1;
           if ((SoundAlert)&&(MACDSignalLineCrossAlert)) Alert ("MACD crossed SignalLane & going Down! ",Symbol()," TF M",Period()," @ ",Bid); 
                if ((EmailAlert)&&(MACDSignalLineCrossAlert)) SendMail("MACD xSignalLane & going Down", "MACD xSignalLane & going Down, Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period());
           }
         }

       else if ((ind_buffer1[i] > ind_buffer2[i])&&(ind_buffer1[i+1] < ind_buffer2[i+1]))
         {
//Macd xSigUp
         if (flagval22==0)
           {
         flagval21=0;
           flagval22=1;
           if ((SoundAlert)&&(MACDSignalLineCrossAlert)) Alert ("MACD crossed SignalLane & going Up! ",Symbol()," TF M",Period()," @ ",Bid); 
                if ((EmailAlert)&&(MACDSignalLineCrossAlert)) SendMail("MACD xSignalLane & going Up", "MACD xSignalLane & going Up, Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period());
           }
         }



// 
       else if  (((ind_buffer1[i]>0)&&(ind_buffer1[i] < ind_buffer1[i+1])&&(ind_buffer1[i+1] < ind_buffer1[i+2])&&(TwoBarsDirChageConfirm))||
                 ((ind_buffer1[i]>0)&&(ind_buffer1[i] < ind_buffer1[i+1])&&(!TwoBarsDirChageConfirm)))
         {
// >0dn
         if (flagval31==0)
           {
           flagval31=1;
           flagval32=0;
           if ((SoundAlert)&&(MACDDirectionChangeAlert)) Alert ("MACD>0 Declining... ",Symbol()," TF M",Period()," @ ",Bid); 
                if ((EmailAlert)&&(MACDDirectionChangeAlert)) SendMail("MACD Declining...", "MACD fDeclining.., Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period());
           }
         }

       else if (((ind_buffer1[i]>0)&&(ind_buffer1[i] > ind_buffer1[i+1])&&(ind_buffer1[i+1] > ind_buffer1[i+2])&&(TwoBarsDirChageConfirm))||
                ((ind_buffer1[i]>0)&&(ind_buffer1[i] > ind_buffer1[i+1])&&(!TwoBarsDirChageConfirm)))
         {
// >0up
         if (flagval32==0)
           {
           flagval31=0;
           flagval32=1;
           if ((SoundAlert)&&(MACDDirectionChangeAlert)) Alert ("MACD>0 Rising... ",Symbol()," TF M",Period()," @ ",Bid); 
                if ((EmailAlert)&&(MACDDirectionChangeAlert)) SendMail("MACD Rising...", "MACD Rising.., Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period());
           }
         }
       else if (((ind_buffer1[i]<=0)&&(ind_buffer1[i] < ind_buffer1[i+1])&&(ind_buffer1[i+1] < ind_buffer1[i+2])&&(TwoBarsDirChageConfirm))||
                ((ind_buffer1[i]<=0)&&(ind_buffer1[i] < ind_buffer1[i+1])&&(!TwoBarsDirChageConfirm)) )
         {
// <0dn
         if (flagval41==0)
           {
           flagval41=1;
           flagval42=0;
           if ((SoundAlert)&&(MACDDirectionChangeAlert)) Alert ("MACD<0 Declining... ",Symbol()," TF M",Period()," @ ",Bid); 
                if ((EmailAlert)&&(MACDDirectionChangeAlert)) SendMail("MACD Declining...", "MACD fDeclining.., Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period());
           }
         }
//
       else if  (((ind_buffer1[i]<=0)&&(ind_buffer1[i] > ind_buffer1[i+1])&&(ind_buffer1[i+1] > ind_buffer1[i+2])&&(TwoBarsDirChageConfirm))||
                 ((ind_buffer1[i]<=0)&&(ind_buffer1[i] > ind_buffer1[i+1])&&(!TwoBarsDirChageConfirm)))

         {
// <0up
         if (flagval42==0)
           {
           flagval41=0;
           flagval42=1;
           if ((SoundAlert)&&(MACDDirectionChangeAlert)) Alert ("MACD<0 Rising... ",Symbol()," TF M",Period()," @ ",Bid); 
                if ((EmailAlert)&&(MACDDirectionChangeAlert)) SendMail("MACD Rising...", "MACD Rising.., Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period());
           }
         }
//

      }
//-

   }
       
//---- done
   return(0);
 }

Comments