Add alert and notification to histogram cross

 

Hi i need help on adding an alert sound and notification to send to phone to this MACD when the histogram bar crosses the zero line to negative/positive.


Can someone please help?

 

What you really mean to say, is that you want someone to modify and code it for you for free, right?

Because, "helping", would be you trying to do it yourself and then just requiring some guidance in the case you had some trouble with it.

 
Ok. i would reword it then. I need someone to help me to modify the code for me for free. If you are willing to. Thank you.
 
Yap Yew Hong:
Ok. i would reword it then. I need someone to help me to modify the code for me for free. If you are willing to. Thank you.

For something like this it is normal to only check on closed bars.

So, for a cross from negative to positive, you check if the histogram's value in the last closed bar was larger than zero

If it was, then check the value for the bar previous to that. If it was smaller than zero, you know that there was a cross and send an alert.

 
Yap Yew Hong:

Hi i need help on adding an alert sound and notification to send to phone to this MACD when the histogram bar crosses the zero line to negative/positive.


Can someone please help?

It can be done simply this way. You can arrange the remaining parts according to your wishes.


/********************************************************************************
 *                                                       MACD Histogram WIS.mq4 *
 *                                           MACD Histogram With Impulse System *
 *                             Copyright © 2016, G.Vladimir.Ivanovich@gmail.com *
 *                                        mailto:G.Vladimir.Ivanovich@gmail.com *
 *******************************************************************************/
#property copyright ""
#property link      ""

/*******************************************************************************/
#property  indicator_separate_window
#property  indicator_buffers 5

#property  indicator_color1 LightGray
#property  indicator_width1 2

#property  indicator_color2 Red
#property  indicator_width2 2

#property  indicator_color3 Green
#property  indicator_width3 2

#property  indicator_color4 Maroon
#property  indicator_width4 2

#property  indicator_color5 Orange
#property  indicator_width5 2
datetime prevtime;

//extern bool   SendAnEmail=false; // Send E-Mail
extern bool   NotifySend=false; // Send Cell Phone Notificatiom
//extern bool   SMSGonder=true;// Send Cell Phone SMS
extern bool   Alarm=true; 
extern bool   ShowChart=true; // Change Chart. Actively loads the graphic at the time of signal generation

/*******************************************************************************/
extern  int FastMA                      = 12;/* Ïåðèîä áûñòðîé ñêîëüçÿùåé ñðåäíåé          */
extern  int SlowMA                      = 26;/* Ïåðèîä ìåäëåííîé ñêîëüçÿùåé ñðåäíåé        */
extern  int SignalMA            = 9; /* Ïåðèîä ñèãíàëüíîé ëèíèè                    */
extern  int MAPeriod            = 13;/* Ïåðèîä ñêîëüçÿùåé ñðåäíåé åñëè Line = 0    */
extern  int MAMethod            = 1; /* Ìåòîä óñðåäíåíèÿ ïî óìîë÷àíèþ MODE_EMA     */
extern  int MAAppliedPrice      = 0; /* Èñïîëüçóåìàÿ öåíà ïî óìîë÷àíèþ PRICE_CLOSE */
extern  int Line                        = 0; /* Èíåðöèÿ 0-MA(MAPeriod); 1-MACD; 2-Signal   */
extern  int DigitsInc           = 2; /* Ôîðìàò òî÷íîñòè Digits + DigitsInc         */

/*******************************************************************************/
double  Histogram[];
double  HistogramWaitClose[];
double  HistogramSell[];
double  HistogramBuy[];
double  MACD[];
double  Signal[];
double  Filter[];

/*******************************************************************************/
int init()
{
        string Mode;
        
        SetIndexBuffer(0, HistogramWaitClose);
        SetIndexStyle(0, DRAW_HISTOGRAM);
        SetIndexEmptyValue(0, 0.0);
        SetIndexLabel(0, "Wait, Close");
        
        SetIndexBuffer(1, HistogramSell);
        SetIndexStyle(1, DRAW_HISTOGRAM);
        SetIndexEmptyValue(1, 0.0);
        SetIndexLabel(1, "Histogram Sell");
        
        SetIndexBuffer(2, HistogramBuy);
        SetIndexStyle(2, DRAW_HISTOGRAM);
        SetIndexEmptyValue(2, 0.0);
        SetIndexLabel(2, "Histogram Buy");
        
        SetIndexBuffer(3, Signal);
        SetIndexStyle(3, DRAW_LINE, STYLE_SOLID);
        SetIndexLabel(3, "Signal");
        
        SetIndexBuffer(4, MACD);
        SetIndexStyle(4, DRAW_LINE, STYLE_SOLID);
        SetIndexLabel(4, "MACD");
        
        if(Line <= 0) Mode = "MA(" + MAPeriod + ")";
        if(Line == 1) Mode = "MACD";
        if(Line >= 2) Mode = "Signal";
        
        IndicatorShortName("MACD Histogram (" + FastMA + "," + SlowMA + "," + SignalMA + ") With Filter " + Mode + "");
        IndicatorDigits(Digits + DigitsInc);
        
        return(0);
}

/*******************************************************************************/
int start()
{
        int i;
   int counted_bars = IndicatorCounted();
   if(counted_bars < 0)  return(-1);
   if(counted_bars > 0)   counted_bars--;
   int limit = Bars - counted_bars;
   if(counted_bars==0) limit-=2;
        
        BufferResize(Filter);
        BufferResize(Histogram);
        
        for(i = 0; i <= limit; i++)
                MACD[i] = iMA(NULL, 0, FastMA, 0, MAMethod, MAAppliedPrice, i) - iMA(NULL, 0, SlowMA, 0, MAMethod, MAAppliedPrice, i);
        for(i = 0; i <= limit; i++)
                Signal[i] = iMAOnArray(MACD, iBars(NULL,0), SignalMA, 0, MAMethod, i);
        for(i = 0; i <= limit; i++)
                Histogram[i] = MACD[i] - Signal[i];
        CalcFilter(Line, limit);
        for(i = limit; i >= 0; i--)
        {
                if(Histogram[i] > Histogram[i+1] && Filter[i] > Filter[i+1])
                {
                        HistogramWaitClose[i] = 0.0;
                        HistogramSell[i] = 0.0;
                        HistogramBuy[i] = Histogram[i];
                }
                if(Histogram[i] < Histogram[i+1] && Filter[i] < Filter[i+1])
                {
                        HistogramWaitClose[i] = 0.0;
                        HistogramSell[i] = Histogram[i];
                        HistogramBuy[i] = 0.0;
                }
                if((Histogram[i] >= Histogram[i+1] && Filter[i] <= Filter[i+1]) || (Histogram[i] <= Histogram[i+1] && Filter[i] >= Filter[i+1]))
                {
                        HistogramWaitClose[i] = Histogram[i];
                        HistogramSell[i] = 0.0;
                        HistogramBuy[i] = 0.0;
                }
                //Print(HistogramBuy[i]," ",HistogramSell[i] ); 
        }
        /////////////
        
   if(Time[0] == prevtime)
      return(0);
   prevtime = Time[0];
   if(HistogramBuy[0]>0 && HistogramSell[0]==0
     &&
     HistogramBuy[1]==0 && HistogramSell[1]==0)
   
     {
      if(NewBar())
        {
         if(Alarm)
            Alert(Symbol()+" TF:"+Period()+" MACD CROS  BUY!.");
         if(NotifySend)
            SendNotification("Haskaya  "+Symbol()+" TF:"+IntegerToString(Period())+ " MACD CROS BUY!.") ;
         //GlobalVariableSet(Symbol()+Period()+SinyalGlobal,1);
         if(ShowChart && !IsTesting())
            OnIDChange();
        }

     }
     
     if(HistogramBuy[0]==0 && HistogramSell[0]<0
     &&
     HistogramBuy[1]==0 && HistogramSell[1]==0)
  if(NewBar())
        {
         if(Alarm)
            Alert(Symbol()+" TF:"+Period()+" MACD CROS  SELL!.");
         if(NotifySend)
            SendNotification("Haskaya  "+Symbol()+" TF:"+IntegerToString(Period())+ " MACD CROS SELL!.") ;
        
         if(ShowChart && !IsTesting())
            OnIDChange();
        }
  
        ///////////
        return(0);
}


/*******************************************************************************/
void BufferResize(double &Array[])
{
        //int counted_bars = ArraySize(Array) - 1;
        //int limit = iBars(NULL, 0) - counted_bars;
        
   int counted_bars = IndicatorCounted();
   if(counted_bars < 0)  return(-1);
   if(counted_bars > 0)   counted_bars--;
   int limit = Bars - counted_bars;
   if(counted_bars==0) limit--;
        
        ArraySetAsSeries(Array, false);
        ArrayResize(Array, iBars(NULL, 0));
        
        for(int i = limit; i >= 0; i--)
                Array[i] = 0.0;
        ArraySetAsSeries(Array, true);
}

/*******************************************************************************/
void CalcFilter(int &a, int &max)
{
        if(a <= 0)
        {
                for(int i = 0; i <= max; i++)
                        Filter[i] = iMA(NULL, 0, MAPeriod, 0, MAMethod, MAAppliedPrice, i);
                return;
        }
        if(a == 1)
        {
                ArrayCopy(Filter, MACD);
                return;
        }
        if(a >= 2)
                ArrayCopy(Filter, Signal);
}
bool NewBar()
  {
   static datetime lastbar;
   datetime curbar = Time[0];
   if(lastbar!=curbar)
     {
      lastbar=curbar;
      return (true);
     }
   else
     {
      return(false);
     }
  }
/*******************************************************************************/

int OnIDChange()
  {
//---

   long id=ChartID();
// long chart_ID= id131676692917666082;//131690745707808067;

   if(!ChartSetInteger(id,CHART_BRING_TO_TOP,0,true))
     {

      Print(__FUNCTION__+", Error Code = ",GetLastError());
      return(false);
     }
//---
   return(INIT_SUCCEEDED);
  }
 
Mehmet Bastem:

It can be done simply this way. You can arrange the remaining parts according to your wishes.


I haven't figured it out. But thank you and blessings to you.