Not send alert when open metatrader for the past signal

 

Hello

how can i fixed indicator that send email , alert and notification for past when metatrader was opened ?

i use this code but when i open the metatrader send many notification and alert of past signals !

if (EnableSoundAlert){
SendNotification(TimeToStr(Time[0], TIME_DATE|TIME_MINUTES) + "  BUY " + Symbol() + " "+Period() );
           
            Alert(TimeToStr(Time[0], TIME_DATE|TIME_MINUTES) + "  BUY " + Symbol() + " "+Period());
            }
            if (EnableMailAlert) {
               SendMail(TimeToStr(Time[0], TIME_DATE|TIME_MINUTES) + "  BUY " + Symbol() + " " +Period(),TimeToStr(Time[0], TIME_DATE|TIME_MINUTES) + " BUY " + Symbol() + " " +Period());
               

and can i have other method of timeframe like : 1M because with Period() it send 1 only!

Thanks

 
Mohammad Aghaali:

Hello

how can i fixed indicator that send email , alert and notification for past when metatrader was opened ?

i use this code but when i open the metatrader send many notification and alert of past signals !

and can i have other method of timeframe like : 1M because with Period() it send 1 only!

Thanks


Hi,

You mean, just want to send an email once when your indicator meets a criteria?

Please show us your code, the loop of your criteria before call SendMail.

 
Yohana Parmi:

Hi,

You mean, just want to send an email once when your indicator meets a criteria?

Please show us your code, the loop of your criteria before call SendMail.

Thanks for your answer

please see this code that i add notification and email and alart to that

//+-----------------------------------------------------------------------------------------------------------+
//|                                                  rsi extreme.mq4                                          |
//|                                           Author: LordoftheMoney |
//|                                                                 |
//|                                Expert advisor is in the codebase                                          |
//|                                                    (Easiest RSI)                                          |
//+-----------------------------------------------------------------------------------------------------------+
#property copyright "orginal version"
#property link    "https://www.mql5.com/en/users/lordofthemoney"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_width1 1
#property indicator_width2 1
#property indicator_color1 Lime
#property indicator_color2 Red
extern int rsiperiod = 14;
double buffy1[];
double buffy2[];
int cb=0;
int bar;
extern bool EnableSoundAlert = FALSE;
extern bool EnableMailAlert = FALSE;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   int  draw;
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,233);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(1,234);
   SetIndexEmptyValue(0,0.0);
   SetIndexLabel(0,"buy");
   SetIndexLabel(1,"sell");
   SetIndexDrawBegin(0,draw);
   SetIndexDrawBegin(1,draw);
   SetIndexBuffer(0,buffy1);
   SetIndexBuffer(1,buffy2);
   return(0);
  }
//+------------------------------------------------------------------+
int deinit()
  {
   ObjectsDeleteAll(0,OBJ_ARROW);
   return(0);
  }
//+------------------------------------------------------------------+
int start()
  {
   if (bar==Time[0]) return(0);
   cb=IndicatorCounted();
   int x;
   if(Bars<=100) return(0);
   if (cb<0) return(-1);
   if (cb>0) cb--;
   x=Bars-cb;
   for(int i=0; i<x; i++)
   {
    double r1 = iRSI(NULL,0,rsiperiod,PRICE_CLOSE,i);
    double r2 = iRSI(NULL,0,rsiperiod,PRICE_CLOSE,i+1);
     if (r1>30 && r2<30)
      buffy1[i] = Low[i+1]-15*Point;
      if (EnableSoundAlert){
      SendNotification(TimeToStr(Time[0], TIME_DATE|TIME_MINUTES) + " EXTREAM RSI BUY " + Symbol() + " "+Period());
           
            Alert(TimeToStr(Time[0], TIME_DATE|TIME_MINUTES) + " EXTREAM RSI BUY " + Symbol() + " "+Period());
            }
            if (EnableMailAlert) {
               SendMail(TimeToStr(Time[0], TIME_DATE|TIME_MINUTES) + " EXTREAM RSI BUY " + Symbol() + " " +Period(),TimeToStr(Time[0], TIME_DATE|TIME_MINUTES) + " EXTREAM RSI BUY " + Symbol() + " " +Period());
               
            }
     bar=Time[0]; 
     if (r1<70 && r2>70)
      buffy2[i] = High[i+1]+15*Point;
      if (EnableSoundAlert){
      SendNotification(TimeToStr(Time[0], TIME_DATE|TIME_MINUTES) + " EXTREAM RSI SELL " + Symbol() + " "+Period() );
           
            Alert(TimeToStr(Time[0], TIME_DATE|TIME_MINUTES) + " EXTREAM RSI SELL " + Symbol() + " " +Period());
            }
            if (EnableMailAlert) {
               SendMail(TimeToStr(Time[0], TIME_DATE|TIME_MINUTES) + " EXTREAM RSI SELL " + Symbol() + " " +Period(),TimeToStr(Time[0], TIME_DATE|TIME_MINUTES) + " EXTREAM RSI BUY " + Symbol() + " " +Period() );
            }
     bar=Time[0]; 
   } 

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

when i attached this to chart it shows past times alerts and send emails of past times signal !!

and when i reopen metatrader and not remove indicator from chart it do that again and when reopen metatrader again and again and again :)

how can i fixed it? and other like this?

Thanks again

 

Because it's an indicator... of course it's gonna do that.

So you can use a globalvar so that it remembers where it left the previous time to skip all the previous alerts.

Please see: https://www.mql5.com/en/docs/globals

Documentation on MQL5: Global Variables of the Terminal
Documentation on MQL5: Global Variables of the Terminal
  • www.mql5.com
Global Variables of the Terminal - Reference on algorithmic/automated trading language for MetaTrader 5
 
Mohammad Aghaali:

Thanks for your answer

please see this code that i add notification and email and alart to that

when i attached this to chart it shows past times alerts and send emails of past times signal !!

and when i reopen metatrader and not remove indicator from chart it do that again and when reopen metatrader again and again and again :)

how can i fixed it? and other like this?

Thanks again


Hi,

Yes, and I thought here is your issue :

     double r2 = iRSI(NULL,0,rsiperiod,....
     if (r1>30 && r2<30)
      buffy1[i] = Low[i+1]-15*Point;
      if (EnableSoundAlert){

RSI is lagging, and so when the price is running then the value meets your criteria many times  ͡ᵔ ͜ʖ ͡ᵔ )

you should check it only  at every 1 candle ended, depending on your time frame, and not at every tick

 
Mohammad Aghaali:

Thanks for your answer

Yohana Parmi:

you should check it only  at every 1 candle ended, depending on your time frame, and not at every tick


I hope this can help

int bar;
extern bool EnableSoundAlert = FALSE;
extern bool EnableMailAlert = FALSE;
//------
datetime lastcandle;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   int  draw;
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,233);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(1,234);
   SetIndexEmptyValue(0,0.0);
   SetIndexLabel(0,"buy");
   SetIndexLabel(1,"sell");
   SetIndexDrawBegin(0,draw);
   SetIndexDrawBegin(1,draw);
   SetIndexBuffer(0,buffy1);
   SetIndexBuffer(1,buffy2);

   //--- your first drawing RSI here ---//

   return(0);
  }
//+------------------------------------------------------------------+
int deinit()
  {
   ObjectsDeleteAll(0,OBJ_ARROW);
   return(0);
  }
//+------------------------------------------------------------------+
int start()
{
   if (bar==Time[0]) return(0);
   cb=IndicatorCounted();
 //-----------------------
 if(lastcandle!=Time[1])
 {

   //--do something here (check your RSI and alert, redraw, etc)

    lastcandle=Time[1];   }//--if lastcandle

}//--start

 

  static datetime alertBarTime=0;

  

  if(Time[i]>alertBarTime && AlertCondition && i==1)

    {

    //send alert

    alertBarTime=Time[i];

    }

If you only want alerts when a bar is closed, test that i==1

If you test for i==0, then it will alert while the current bar is open, but only once.

 
Keith Watford:

  static datetime alertBarTime=0;

  

  if(Time[i]>alertBarTime && AlertCondition && i==1)

    {

    //send alert

    alertBarTime=Time[i];

    }

If you only want alerts when a bar is closed, test that i==1

If you test for i==0, then it will alert while the current bar is open, but only once.

Thanks so much but there is problem with both i==0 and i==1 that when i start indicator show me past signal (only 1) and send email , how can i fix it?
 
Yohana Parmi:


I hope this can help

Thanks so much but there is problem , when i start indicator show me past signal (only 1) and send email , how can i fix it?

 

And can you please let me know what is wrong when i use

if(EnableSoundAlert && iTime(_Symbol,PERIOD_CURRENT,0))

That is not work!

Thanks

 
Mohammad Aghaali:

Thanks so much but there is problem , when i start indicator show me past signal (only 1) and send email , how can i fix it?


Mohammad Aghaali:

Hello

how can i fixed indicator that send email , alert and notification for past when metatrader was opened ?

i use this code but when i open the metatrader send many notification and alert of past signals !

and can i have other method of timeframe like : 1M because with Period() it send 1 only!

Thanks


Hi, Aghaali

Actually, I thought your main problem has been fixed ^̮^

And the second step is how to give new value to your variable before next checking at if()

int start()
{

 //-- process RSI here, new value in the variable is needed for next candle.

 //-----------------------
 if(lastcandle!=Time[1])
 {

    //--do something here (check your RSI and alert, redraw, etc)


    lastcandle=Time[1];
  }//--if lastcandle
}//--start

and also you can find many codes that you need here:

https://www.mql5.com/en/code

MQL5 Code Base
MQL5 Code Base
  • www.mql5.com
MQL5 Source Code Library for MetaTrader 5
Reason: