Asctrend not sending Emails

 

Hello

I was using asctrend and I added the SendMail() function, but it doesn't work. What is the problem?

   if( BuyBuffer[1]!=0 ) 
     {
      if(counter<NumberofAlerts) 
        {
         counter++; 
         if(SoundON) 
           {
            Alert("ASC_TREND BUY signal at Ask=",Ask,"\n Bid=",Bid,"\n currtime=",text,"\n Symbol=",Symbol()," Period=",sPeriod);
            PlaySound("matrixrevolution.wav");
            //  PlaySound("SysAlert1.wav");
            //   PlaySound("samsam.wav");
            //    PlaySound("Alert_Play.wav");
            }
         SendMail("ASC_TREND : BUY signal alert","BUY signal at Ask="+sAsk+", Bid="+sBid+", Date="+text+" Symbol="+Symbol()+" Period="+sPeriod);
         if(PushON) SendNotification("ASC_TREND: BUY signal at Ask="+sAsk+", Bid="+sBid+", Date="+text+" Symbol="+Symbol()+" Period="+sPeriod);
        }
     } 
      
   if(SellBuffer[1]!=0 ) 
     { 
      if(counter<NumberofAlerts)
        {
         counter++;
         if(SoundON)
           {
            Alert("ASC_TREND SELL signal at Ask=",sAsk,"\n Bid=",sBid,"\n Date=",text,"\n Symbol=",Symbol()," Period=",sPeriod);
            PlaySound("matrixrevolution.wav");
            //  PlaySound("SysAlert1.wav");
            //  PlaySound("samsam.wav");
            //    PlaySound("Alert_Play.wav");
           }
         SendMail("ASC_TREND","SELL signal at Ask="+sAsk+", Bid="+sBid+", Date="+text+" Symbol="+Symbol()+" Period="+sPeriod);
         if(PushON) SendNotification("ASC_TREND: SELL signal at Ask="+sAsk+", Bid="+sBid+", Date="+text+" Symbol="+Symbol()+" Period="+sPeriod);
        }
     }
  
//----------------------------------------------------------------------
 

Do you have such an error in the terminal log (tab "Journal"):

2016.08.13 09:45:40.474 MailDispatcher  invalid settings (Tools->Options->Email)
?
 
Karputov Vladimir:

Do you have such an error in the terminal log (tab "Journal"):

?
No but I have the asctrend buy/sell signal on experts tab. what is the problem?
 
564867:
No but I have the asctrend buy/sell signal on experts tab. what is the problem?

Why don't you check the return value?

bool  SendMail()

Return Value

true – if an email is put into the send queue, otherwise - false.

Note

Sending can be prohibited in settings, email address can be omitted as well. For the error information call GetLastError().

SendMail() function does not work in the Strategy Tester.

 
564867:
No but I have the asctrend buy/sell signal on experts tab. what is the problem?
You must correctly configure the e-mail in MetaTrader 5. Please show me a screenshot of the "Settings" -> "Email".
 

Example: How do I configure gmail.com, if you enable two-step authorization. Below is an example in Russian setting - if something is unclear - ask me:

Форум по трейдингу, автоматическим торговым системам и тестированию торговых стратегий

Как настроить почту в программе метатрейдер4

Karputov Vladimir, 2016.06.30 20:02

На примере аккаунта Google с двухэтапной аутентификацией.

Для начала нужно создать пароль приложения - для безопасности создаётся пароль для отдельного приложения:

Перейдите на эту страницу. Если потребуется, войдите в аккаунт Google.

, в данном случае назовём приложение "MetaTrader 4" и сгенерируем для него пароль:

Создание пароля приложения

 

Теперь этот сгенерированный пароль можно вставлять в настройки терминала, вкладка "Почта", поле "SMTP пароль":

Настройки почты в MetaTrader

 

Нажимаем кнопку "Тест" и смотрим во вкладку "Журнал":

2016.06.30 20:55:27.729 Mail: 'Test message' has been sent

 

Проверяю почтовую программу - письмо пришло!

Письмо в почтовой программе 


 
Marco vd Heijden:

Why don't you check the return value?

Return Value

true – if an email is put into the send queue, otherwise - false.

Note

Sending can be prohibited in settings, email address can be omitted as well. For the error information call GetLastError().

SendMail() function does not work in the Strategy Tester.

thanks for your advice. I have not used the return value, I will test it further. I know the settings problem and... you kno, the only error I have is the autotrade error and that is because I turned it off.

finally, I'm not testing it that way, i just use it for the trade time and nothing else. please do me a favor, I attach the file and just take a look at it. thank you

Files:
asctrend.mq5  13 kb
 
Karputov Vladimir:

Example: How do I configure gmail.com, if you enable two-step authorization. Below is an example in Russian setting - if something is unclear - ask me:


I know what you mean, and I have changed the settings for using some python programs for email. and also I checked the email settings for MT5 and that was exactly like what you said. There is a problem that this NOT a usual MT5 version and is used for iranian stocks market, but I have sent emails by other indicators using this version of MT5.

after all I attached the file to the previous comment. you can take a better look at it. thank you:)

 
564867:

I know what you mean, and I have changed the settings for using some python programs for email. and also I checked the email settings for MT5 and that was exactly like what you said. There is a problem that this NOT a usual MT5 version and is used for iranian stocks market, but I have sent emails by other indicators using this version of MT5.

after all I attached the file to the previous comment. you can take a better look at it. thank you:)

This verification code. It is fully working. Message to e-mail is sent:

//+------------------------------------------------------------------+
//|                                                         Test.mq5 |
//|                              Copyright © 2016, Vladimir Karputov |
//|                                           http://wmua.ru/slesar/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2016, Vladimir Karputov"
#property link      "http://wmua.ru/slesar/"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   string sAsk="1.2010";
   string sBid="1.2005";
   string text="216.08.15";
   string sPeriod="PER";
   SendMail("ASC_TREND : BUY signal alert","BUY signal at Ask="+sAsk+", Bid="+sBid+", Date="+text+" Symbol="+Symbol()+" Period="+sPeriod);
  }
//+------------------------------------------------------------------+

Posted in the "Journal" of the terminal:

2016.08.15 12:42:59.585 MailDispatcher  email 'ASC_TREND : BUY signal alert' sent to barabashkakvn@gmail.com
Files:
Test.mq5  3 kb
 

Forum on trading, automated trading systems and testing trading strategies

share utility code

Mehrdad Shiri, 2014.03.18 08:43

hi;

below code can use for " send email & send massage to mobile & send sound and alarm " .i write below and use it in all my indicator.

uint counterBUY=0;
uint counterSELL=0;
double Ask,Bid;
string text,sAsk,sBid,sPeriod;
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
input string s99="-----------------------------------------------";      // ----------- ALARM Settings -----------------
input uint Numberof_Alerts_Maximum_Iterations=2;
input bool On_Push = true;                        //allow to send push-messages
input bool On_Email = true;                       //allow to send e-mail messages
input bool On_Alert= true;                        //allow to put alert
input bool On_Play_Sound = true;                  //allow to put sound signal
input string NameFileSound="request.wav";          //name of the file with sound in "...\MetaTrader 5\Sounds"
input string  CommentSirName="your indicator name:";  //the first part of the allert comment
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+------------------------------------------------------------------+
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     &TickVolume[],
                const long     &Volume[],
                const int      &Spread[])
{

//----------------------------------------------------------------------//
   MqlDateTime tm;
   TimeToStruct(TimeCurrent(),tm);
   text=TimeToString(TimeCurrent(),TIME_DATE)+" "+string(tm.hour)+":"+string(tm.min);
   Ask=Close[0];
   Bid=Close[0]+Spread[0];
   sAsk=DoubleToString(Ask,_Digits);
   sBid=DoubleToString(Bid,_Digits);
   sPeriod=EnumToString(ChartPeriod());
   if(rates_total!=prev_calculated) {counterBUY=0;counterSELL=0;}
//----------------------------------------------------------------------//      

//----------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------- PlaySound Alert SendNotification SendMail 
//+++
     {
      if(counterBUY<Numberof_Alerts_Maximum_Iterations)
        {
         if(Indicator_Signal[0]==1&&Indicator_Signal[1]!=1) {BUY_ALARM();counterBUY++;}
        }
      if(counterSELL<Numberof_Alerts_Maximum_Iterations)
        {
         if(Indicator_Signal[0]==-1&&Indicator_Signal[1]!=-1) {SELL_ALARM();counterSELL++;}
        }
     }
//----------------------------------------------------------------------------------------------------------//
//--- done
   return(rates_total);
}
//+------------------------------------------------------------------+
//----------------------------------------------------------------------------------------------------------//
//********************************************************************************************************************
void BUY_ALARM()
  {
   if(On_Alert) Alert("BUY # ",Symbol(),"\n Period=",sPeriod,"\n Ask=",sAsk,"\n Bid=",sBid,"\n currtime=",text);
   if(On_Play_Sound) PlaySound("matrixrevolution.wav");
   if(On_Email) SendMail("BUY #",Symbol()+" Period="+sPeriod+", Ask="+sAsk+", Bid="+sBid+", currtime="+text);
   if(On_Push) SendNotification("BUY #"+Symbol()+" Period="+sPeriod+", Ask="+sAsk+", Bid="+sBid+", currtime="+text);
  }
//+------------------------------------------------------------------+
void SELL_ALARM()
  {
   if(On_Alert) Alert("SELL # ",Symbol(),"\n Period=",sPeriod,"\n Ask=",sAsk,"\n Bid=",sBid,"\n currtime=",text);
   if(On_Play_Sound) PlaySound("matrixrevolution.wav");
   if(On_Email) SendMail("SELL #",Symbol()+" Period="+sPeriod+", Ask="+sAsk+", Bid="+sBid+", currtime="+text);
   if(On_Push) SendNotification("SELL #"+Symbol()+" Period="+sPeriod+", Ask="+sAsk+", Bid="+sBid+", currtime="+text);
  }
//********************************************************************************************************************
//----------------------------------------------------------------------------------------------------------//

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


Reason: