Notificação de indicador não funciona

 

Amigos,


Estou preparando um indicador que mede a distância que o preço está, em relação a Média Móvel de 200. acrescentei nesse código, uma função de envio de notificação caso a distância esteja acima ou abaixo de determinado valor.


As notificações não estão funcionando. Saberiam dizer o motivo ?


//+------------------------------------------------------------------+
//|                Distância para Média com Envio de Notificação.mq5 |
//+------------------------------------------------------------------+
#property version   "1.0"
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_plots   1
//--- plot distance
#property indicator_label1  "distance"
#property indicator_type1   DRAW_COLOR_HISTOGRAM
#property indicator_color1  clrDodgerBlue,clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  2
#property indicator_level1 -0.5
#property indicator_level2 0.5
//---
enum PRICE_METHOD
  {
   Close,
   Open,
   High,
   Low,
   Median,  // Median Price (HL/2)
   Typical, // Typical Price (HLC/3)
   Weighted // Weighted Close (HLCC/4)
  };
enum SHOW_TYPE
   {
   Porcentagem,
   Absoluto     // Valor Absoluto
   };
//--- input parameters
input int                 maPeriod   = 200;            // Período da média móvel
input ENUM_MA_METHOD      maMethod   = MODE_SMA;      // Método de Cálculo
input ENUM_APPLIED_PRICE  maApply_to = PRICE_TYPICAL; // Aplicar média a:
input PRICE_METHOD        priceType  = Median;        // Preço para cálculo de distância
input SHOW_TYPE           showType   = Porcentagem;   // Apresentar distância em:
input int    TriggerCandle      = 1;
input bool   EnableNativeAlerts = true;
input bool   EnableSoundAlerts  = true;
input bool   EnableEmailAlerts  = true;
input bool   EnablePushAlerts  = true;
input string AlertEmailSubject  = "";
input string AlertText          = "";
input string SoundFileName      = "alert.wav";
 
datetime LastAlertTime = D'01.01.1970';
int LastAlertDirection = 0;
//--- indicator buffers
double         distanceBuffer[];
double         distanceColors[];
double         MaBuffer[];
//--- global variables
int            Handler;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,distanceBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,distanceColors,INDICATOR_COLOR_INDEX);
   SetIndexBuffer(3,MaBuffer,INDICATOR_DATA);
   IndicatorSetInteger(INDICATOR_DIGITS,3);
   Handler=iMA(NULL,0,maPeriod,0,maMethod,maApply_to);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   if(prev_calculated<rates_total) CopyBuffer(Handler,0,0,rates_total,MaBuffer);
   for(int i=(int)MathMax(0,(double)prev_calculated-2); i<rates_total; i++)
      {
      distanceBuffer[i] = Price(open,high,low,close,i) - MaBuffer[i];
      if(showType==Porcentagem) distanceBuffer[i] /= MaBuffer[i]/100;
      if(distanceBuffer[i]>0) distanceColors[i]=0;
      else distanceColors[i]=1;
      }
//+------------------------------------------------------------------+
//| Notificação                                                      |
//+------------------------------------------------------------------+     
if (((TriggerCandle > 0) && (time[rates_total - 1] > LastAlertTime)) || (TriggerCandle == 0))
{
        string Text;
        // Above Zero Alert
        if (((MaBuffer[rates_total - 1 - TriggerCandle] > 0) && (MaBuffer[rates_total - 2 - TriggerCandle] <= 0)) && ((TriggerCandle > 0) || ((TriggerCandle == 0) && (LastAlertDirection != 1))))
        {
                Text = AlertText + "Coppock: " + Symbol() + " - " + EnumToString(Period()) + " - Above Zero.";
                if (EnableNativeAlerts) Alert(Text);
                if (EnableEmailAlerts) SendMail(AlertEmailSubject + "Coppock Alert", Text);
                if (EnableSoundAlerts) PlaySound(SoundFileName);
                if (EnablePushAlerts) SendNotification(Text);
                LastAlertTime = time[rates_total - 1];
                LastAlertDirection = 1;
        }
        // Below Zero Alert
        if (((MaBuffer[rates_total - 1 - TriggerCandle] < 0) && (MaBuffer[rates_total - 2 - TriggerCandle] >= 0)) && ((TriggerCandle > 0) || ((TriggerCandle == 0) && (LastAlertDirection != -1))))
        {
                Text = AlertText + "Coppock: " + Symbol() + " - " + EnumToString(Period()) + " - Below Zero.";
                if (EnableNativeAlerts) Alert(Text);
                if (EnableEmailAlerts) SendMail(AlertEmailSubject + "Coppock Alert", Text);
                if (EnableSoundAlerts) PlaySound(SoundFileName);
                if (EnablePushAlerts) SendNotification(Text);
                LastAlertTime = time[rates_total - 1];
                LastAlertDirection = -1;
        }
}
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
double Price(const double &iOpen[],
             const double &iHigh[],
             const double &iLow[],
             const double &iClose[],
             int          index)
  {
   double output;
   switch(priceType)
      {
      case Open:     output=iOpen[index]; break;
      case High:     output=iHigh[index]; break;
      case Low:      output=iLow[index]; break;
      case Median:   output=(iHigh[index]+iLow[index])/2; break;
      case Typical:  output=(iHigh[index]+iLow[index]+iClose[index])/3; break;
      case Weighted: output=(iHigh[index]+iLow[index]+iClose[index]+iClose[index])/4; break;
      default:       output=iClose[index]; break;
      }
   return(output);
  }
Razão: