My EA sends multiple duplicate emails

时间:2018-02-05 13:02:21

标签: email windows2012 mt4

I have an EA on my MetaTrader4 Platform which is designed to send an email via the SendMail function whenever a trade is executed, and another when that trade is closed out.

This all works without a hitch, however, it sends multiple duplicate emails whenever a trade position is closed. It obviously needs to only send one Email.

This is also the case with the SendNotification function as well

My setup is as follows:

  • Windows 2012 R2 VPS Server
  • MetaQuotes MT4

Other Useful Information

  • I did set up an auto forwarding on my Email client to send all Trade Notifications to another address. So these emails are in two separate inboxes.

  • I only have one MT4 Terminal.

  • I have one EA per symbol

My question is, has anyone else had this issue and/or does anyone know the reason for this & how would I fix this issue?

Thanks

//+------------------------------------------------------------------+
//| forexmts, forexmts@mail.ru, v4.0vs-                              |
//| Events function,                                                 |
//| detects changes in orders list                                   |
//+------------------------------------------------------------------+
void fEvents(ENUM_FUNCTION_MODE enMode)
   {   
   if (enMode == MODE_INIT) { fOrders(); return; }
   
   if (enMode == MODE_WORK)
   {
   bool bFoundFlag;
   fOrders();
   //existing orders check
   for(int i = 0; i < ArraySize(stcOrdOldArr); i++)  //search all orders from the old array
      {
      bFoundFlag = false;
      for(int j = 0; j < ArraySize(stcOrdNewArr); j++) //.. in the new array
         {         
         if (stcOrdOldArr[i].ticket == stcOrdNewArr[j].ticket) //found by ticket 
            {
            if (stcOrdOldArr[i].type != stcOrdNewArr[j].type) { }//but the type has changed
            if (stcOrdOldArr[i].sl != stcOrdNewArr[j].sl) { } //SL was changed
            if (stcOrdOldArr[i].tp != stcOrdNewArr[j].tp) { } //TP was changed
               
            bFoundFlag = true;
            break;                              //stop searching in the new array
            }
         }

      if (bFoundFlag == false)                 //order wasn't found
         {
         if (stcOrdOldArr[i].type <= 1)
            //we can't use profit and close price, lots and commentary (for partial close) from the dOrdOldArr, because we need their after close values
            if (OrderSelect(stcOrdOldArr[i].ticket, SELECT_BY_TICKET))
               {
               string sKindOfExit = "";
               if ((OrderType() == OP_BUY && OrderClosePrice() <= stcOrdOldArr[i].sl) || (OrderType() == OP_SELL && OrderClosePrice() >= stcOrdOldArr[i].sl && stcOrdOldArr[i].sl > 0) || StringFind(OrderComment(), "[sl]") >= 0)
                  sKindOfExit = " at StopLoss"; //close by sl
               else
               if ((OrderType() == OP_BUY && OrderClosePrice() >= stcOrdOldArr[i].tp && stcOrdOldArr[i].tp > 0) || (OrderType() == OP_SELL && OrderClosePrice() <= stcOrdOldArr[i].tp) || StringFind(OrderComment(), "[tp]") >= 0)
                  sKindOfExit = " at TakeProfit"; //close be tp
               else
                  { }         //ordinary close
               
               SendMail("(TNEPC)Trade Notification Email of Position Closure","Order #"+IntegerToString(OrderTicket())+" has been closed "+sKindOfExit+" on the account "+AccountName()+" "+AccountServer()+
               "\n"+
               "\nThe order exit price for this trade is "+DoubleToStr(OrderClosePrice(),_Digits)+" with a "+(OrderProfit()>=0?"profit":"loss")+" of £"+DoubleToStr(OrderProfit(),2)+
               "\n"+
               "\nThis is an Automated Message from xxxxxx"+
               "\n-----------------------------------------------------------------------"+
               "\n"+
               "\nPRIVACY NOTICE"+
               "\nThis email is intended for the recipient stated at the address at the top of this email. If you have received this in error, please delete this email immediately and contact us at xxxxxxx"+
               "\n"+
               "\n"+
               "\nH"+
               "\n"+
               "\n"+
               "\n");
               SendNotification("Ticket #"+IntegerToString(OrderTicket())+" has closed with a "+(OrderProfit()>=0?"profit":"loss")+" of "+DoubleToStr(OrderProfit(),2));
               }
            else
               { }   //order not found

         if (stcOrdOldArr[i].type > 1) { }      //pending order is deleted
         
         }
      }
   
  
      
   }
   
  }

0 个答案:

没有答案