Indicators: MACD_Flat_Trend

 

MACD_Flat_Trend:

MACD Flat Trend indicator

MACD_Flat_Trend

Author: Scriptor

 
I want to set an alert in this ( MACD Flat Trend Indicator ) , is this possible? If this is possible then what do I have to change  in the .mq5 code? you tell me i will do it ,THANK YOU SIR
 
VIJAY JADAV #:
I want to set an alert in this ( MACD Flat Trend Indicator ) , is this possible? If this is possible then what do I have to change  in the .mq5 code? you tell me i will do it ,THANK YOU SIR
//--- Расчёт индикатора
   for(int i=limit; i>=0 && !IsStopped(); i--)
     {
      BufferNL[i]=BufferDN[i]=BufferUP[i]=EMPTY_VALUE;
      if(BufferMACD[i]>0 && BufferSignal[i]<BufferMACD[i])
        {
         BufferUP[i]=0.5;
         BufferNL[i]=BufferDN[i]=EMPTY_VALUE;
         Alert("Buy ", _Symbol);
        }
      else
        {
         if(BufferMACD[i]<0 && BufferSignal[i]>BufferMACD[i])
           {
            BufferDN[i]=0.5;
            BufferNL[i]=BufferUP[i]=EMPTY_VALUE;
            Alert("Sell ", _Symbol);
           }
         else
           {
            BufferNL[i]=0.5;
            BufferDN[i]=BufferUP[i]=EMPTY_VALUE;
           }
        }
     }
 
Ryan L Johnson #:
Thank you Sir you did this for me, but there is a little problem in this
The modification you have made keeps the audio playing continuously,
I want such an alert that when the green line starts, I should get an alert only on its first candle, I should not get an alert on the candles after that
Alert should be received only when maCd line and signal line cross over, otherwise alert should not be received,
There should be no alerts from the second Candle of the Green Line,
THANKYOU SIR 

 
VIJAY JADAV #:
Thank you Sir you did this for me, but there is a little problem in this
The modification you have made keeps the audio playing continuously,
I want such an alert that when the green line starts, I should get an alert only on its first candle, I should not get an alert on the candles after that
Alert should be received only when maCd line and signal line cross over, otherwise alert should not be received,
There should be no alerts from the second Candle of the Green Line,
THANKYOU SIR 

//--- Расчёт индикатора
   int lastAlert = 0; // 0 is flat, 1 is buy, 2 is sell

   for(int i=limit; i>=0 && !IsStopped(); i--)
     {
      BufferNL[i]=BufferDN[i]=BufferUP[i]=EMPTY_VALUE;
      if(BufferMACD[i]>0 && BufferSignal[i]<BufferMACD[i])
        {
         BufferUP[i]=0.5;
         BufferNL[i]=BufferDN[i]=EMPTY_VALUE;

         if(lastAlert != 1)
           {
            Alert("Buy ", _Symbol);
            lastAlert = 1;
           }
        }
      else
        {
         if(BufferMACD[i]<0 && BufferSignal[i]>BufferMACD[i])
           {
            BufferDN[i]=0.5;
            BufferNL[i]=BufferUP[i]=EMPTY_VALUE;

            if(lastAlert != 2)
              {
               Alert("Sell ", _Symbol);
               lastAlert = 2;
              }
           }
         else
           {
            BufferNL[i]=0.5;
            BufferDN[i]=BufferUP[i]=EMPTY_VALUE;
            lastAlert = 0;
           }
        }
     }

I added a variable to limit the alert to one alert per crossover.

 

If you're still getting intrabar alerts, the code below additionally limits alerts by bar open time. Historic buffer values can't be used because they have empty values. Just be aware that I haven't compiled nor tested this code but I'm sure you'll do it and post back again.😉

// put these 2 lines up top in the scope of global variables
   datetime lastOpenTime;
   ulong uLastOpenTime;

//////////////////////////////////////////////////

// put these 2 lines in the OnInit() function
      lastOpenTime = 0;
      uLastOpenTime = ulong(lastOpenTime);

//////////////////////////////////////////////////

//--- Расчёт индикатора
   int lastAlert = 0; // 0 is flat, 1 is buy, 2 is sell

   for(int i=limit; i>=0 && !IsStopped(); i--)
     {
      BufferNL[i]=BufferDN[i]=BufferUP[i]=EMPTY_VALUE;
      if(BufferMACD[i]>0 && BufferSignal[i]<BufferMACD[i])
        {
         BufferUP[i]=0.5;
         BufferNL[i]=BufferDN[i]=EMPTY_VALUE;

         if(lastAlert != 1 && uLastOpenTime < ulong(iTime(_Symbol, PERIOD_CURRENT, 1))
           {
            Alert("Buy ", _Symbol);
            lastAlert = 1;
            uLastOpenTime = ulong(iTime(_Symbol, PERIOD_CURRENT, 1);
           }
        }
      else
        {
         if(BufferMACD[i]<0 && BufferSignal[i]>BufferMACD[i])
           {
            BufferDN[i]=0.5;
            BufferNL[i]=BufferUP[i]=EMPTY_VALUE;

            if(lastAlert != 2 && uLastOpenTime < ulong(iTime(_Symbol, PERIOD_CURRENT, 1))
              {
               Alert("Sell ", _Symbol);
               lastAlert = 2;
               lastOpenTime = ulong(iTime(_Symbol, PERIOD_CURRENT, 1);
              }
           }
         else
           {
            BufferNL[i]=0.5;
            BufferDN[i]=BufferUP[i]=EMPTY_VALUE;
            lastAlert = 0;
           }
        }
     }