EA sendmail problem persists

 

This was my previous problem https://www.mql5.com/en/forum/435434#comment_42935818 which has been solved

However, a new problem emerged that i'm needing help with.

When i load my EA onto a chart, immediately within seconds i get a email of the info i wanted to receive, but after that first email, my EA stops placing pending orders after the first pending orders expire or if price triggers a pending order and either hits my stop loss / take profit level. My EA stopped placing pending orders after i placed this code in the body of the on tick function: 

// In Global Scope
static datetime lastdealtime = 0;

//----------------------------------------------------------------------------------------------------------
//Send email alerts of last closed deals symbol & loss or profit amount in USD
//-----------------------------------------------------------------------------------------------------------      
//--- request trade history
   HistorySelect(0,TimeCurrent());
   uint total_deals=HistoryDealsTotal();
   ulong ticket_history_deal=0;
   int counter=0;
   string text="";
//--- for all deals
   for(uint i=total_deals-1; i>=0; i--){
   
      //--- try to get deals ticket_history_deal
      if((ticket_history_deal=HistoryDealGetTicket(i))>0){
      
         long     deal_ticket       =HistoryDealGetInteger(ticket_history_deal,DEAL_TICKET);
         long     deal_time         =HistoryDealGetInteger(ticket_history_deal,DEAL_TIME);
         long     deal_type         =HistoryDealGetInteger(ticket_history_deal,DEAL_TYPE);
         long     deal_entry        =HistoryDealGetInteger(ticket_history_deal,DEAL_ENTRY);
         long     deal_magic        =HistoryDealGetInteger(ticket_history_deal,DEAL_MAGIC);
         double   deal_commission   =HistoryDealGetDouble(ticket_history_deal,DEAL_COMMISSION);
         double   deal_swap         =HistoryDealGetDouble(ticket_history_deal,DEAL_SWAP);
         double   deal_profit       =HistoryDealGetDouble(ticket_history_deal,DEAL_PROFIT);
         string   deal_symbol       =HistoryDealGetString(ticket_history_deal,DEAL_SYMBOL);
         datetime m_from_date       = 0;
         uchar lastdeal = 1;
         //---                
         
         if((_Symbol==deal_symbol || _Symbol=="") && (Magic==deal_magic || Magic<0)){
         
            if(deal_entry==DEAL_ENTRY_OUT && deal_time>lastdealtime){
               
               counter++;
               string time=TimeToString((datetime)deal_time,TIME_DATE|TIME_MINUTES|TIME_SECONDS);
               SendMail(__FILE__, Symbol()+", $ "+DoubleToString(deal_commission+deal_swap+deal_profit,2));
               lastdealtime = (datetime)deal_time;
               if(counter==lastdeal){                  
               
                  m_from_date=(datetime)deal_time;
                  break;
                  }
               }
            }
         }
      }

and once i remove this code above and recompile it to test the EA on a live chart, it works normally and places pending orders every 2 minutes(expiry time 120 seconds) on the 1 minute chart.


Can someone please help me solve this. Why is my EA not placing orders whenever a signal is generated and how can i fix this? Thank you in advance!

Please help. MQL5 EA sendmail function sends me repeat emails on every tick, how to make it send me an email only once per closed deal?
Please help. MQL5 EA sendmail function sends me repeat emails on every tick, how to make it send me an email only once per closed deal?
  • 2022.10.30
  • www.mql5.com
Hey MQL5 community, i have a problem with my expert advisor as you have seen in my subject...