尽管有预防代码,EA 仍发送大量 "SendMessage" 命令

EA sending a mass of "SendMessage" commands despite prevention code in place

Whosebugers 早上好

我目前正在测试一些基于允许 EA 进行交易的时间的代码。我如何防止 EA 发送大量电子邮件 - 显然可以。

我通过应用 LastActiontime=Time[0]; 在另一个 EA 中只发送了一个,但是,在应用 LastActiontime=Time[0]; 之后,它会发出大量消息....

我需要做出哪些改变才能防止这种情况发生?

查看下面的代码

//+------------------------------------------------------------------+
//|                                     EAServerVerificationPing.mq4 |
//|                        Copyright 2017, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

datetime       LastActiontime;
int            timeOfDay;
int            hour;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   RefreshRates();
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
//---

   timeOfDay            =  DayOfWeek();
   hour                 =  Hour();
   
   if(timeOfDay == 1 && hour >= 2)
   if(LastActiontime!=Time[0])
   {
      //Code to execute once in the bar
      SendMail("Is your Trade Allowed? (FXVM)",
      "Yes, your trade is allowed"+
      "\n"+
      "\nPRIVACY NOTICE");
   }else{
      SendMail("Is your Trade Allowed? (FXVM)",
      "No, your trade is not allowed"+
      "\n"+
      "\nPRIVACY NOTICE");
   }  
   LastActiontime=Time[0]; <!------This should prevent a mass of messages from sending--->
}
  

//+------------------------------------------------------------------+

感激不尽:)

  datetime       LastActiontime;
  int            timeOfDay;
  int            hour;
  
  int OnInit()
    {
  //---
     RefreshRates();   // <- useless
  //---
     return(INIT_SUCCEEDED);
    }
  void OnDeinit(const int reason)
    {
  //---
     
    }
  //+------------------------------------------------------------------+
  //| Expert tick function                                             |
  //+------------------------------------------------------------------+
  void OnTick()
  {
  //---
  
     timeOfDay            =  DayOfWeek();
     hour                 =  Hour();
     
     if(DayOfWeek()==MONDAY && Hour()>=2)
     {
        if(Time[0]>LastActiontime)
        {
           LastActiontime=Time[0];send();
        }
     }
  }
  void send()
  {
     if(true) //put your logic here
     {
        SendMail("Is your Trade Allowed? (FXVM)",
              "Yes, your trade is allowed"+
              "\n"+
              "\nPRIVACY NOTICE");
     }
     else
     {
        SendMail("Is your Trade Allowed? (FXVM)",
           "No, your trade is not allowed"+
           "\n"+
           "\nPRIVACY NOTICE");
     }
  }