While Loop | Restricting SendMail() attempts.

 

Morning all

I have an EA which is designed to send a confirmation email when an order is executed.

The 'orderselect' (Not to be confused with the MQL4 OrderSelect(...) function) function is called in the OnTick() section of the EA. Just to be clear, I am aware as to the implication of the OnTick() function, in that anything in the OnTick() section takes place on every incoming tick. 

However, I have section which is attempting to tell the terminal to have three attempts to sending a confirmation email via the SendMail(...) function, when it gets to the 3rd attempt, its to print an error. 

Looking at the code below, why am I still getting emails into infinity despite telling it to only give the terminal three attempts, then to break the loop?

The function below is an external file and called from the OnTick() section.

Thanks

bool orderselect(){

  int positionSelect = OrdersTotal() - 1;
                                             
      if(!OrderSelect(positionSelect,SELECT_BY_POS,MODE_TRADES)){
      
         PrintFormat("There was an error in selecting the order from the ledger (Error %d) #", lastError);
                   
               return false;
      
      } else {
               
            while(true){
            
               if(SendTransactionMessages == 1){ //extern variable
               
                  if(OrderType() == 4 || OrderType() == 5){
                  
                     int transMessage = <confirmation_email_function()>; //int function
                     
                        if(transMessage == -1){
                        
                           static int tryMe = 0;
                           
                              tryMe++;
                        
                                 if(tryMe >= 3){
                                 
                                    tryMe=0;
                                 
                                       Print("<!>___",__LINE__," OrderSend failed with Error: " + (string)GetLastError());
                                       
                                          return false;
                                       
                                 }  else  {
                                 
                                    Print("<!>___",__LINE__," OrderSend error " + (string)GetLastError() + ", retry #"+(string)tryMe+" of 3");
                                    
                                       continue;
                                                         
                                 }
                    
                        } else {
                        
                           Print("<!>___",__LINE__," OrderSend success");
                           
                              break;
                                             
                        }
                                    
                  } else  {
                  
                     <confirmation_email_function()>; //int function
                     
                        break;
                  
                  }
                  
               } else {
               
                  Print("Sending Transactional Messages have been turned off.");
                              
               }
               
               break;
            
            }
            
      }
      
      return true;

}
 
TheHonestPrussian:

Morning all

I have an EA which is designed to send a confirmation email when an order is executed.

The 'orderselect' (Not to be confused with the MQL4 OrderSelect(...) function) function is called in the OnTick() section of the EA. Just to be clear, I am aware as to the implication of the OnTick() function, in that anything in the OnTick() section takes place on every incoming tick. 

However, I have section which is attempting to tell the terminal to have three attempts to sending a confirmation email via the SendMail(...) function, when it gets to the 3rd attempt, its to print an error. 

Looking at the code below, why am I still getting emails into infinity despite telling it to only give the terminal three attempts, then to break the loop?

The function below is an external file and called from the OnTick() section.

Thanks

start with....

                 if(transMessage == -1){
                        
                           static int tryMe = 0;    
                           
                              tryMe++;       <<<<<<<<< you can't alter a static variable
                        
                                 if(tryMe >= 3){    <<<<<<<<<<<<<<< tryMe will always have a value less than 3 at this point
                                 
                                    tryMe=0;
                                 
                                       Print("<!>___",__LINE__," OrderSend failed with Error: " + (string)GetLastError());
                                       
                                          return false;
                                       
                                 }  else  {
 
Paul Anscombe #:

start with....

Thanks, I'll have a jiggle around with this. 

 
TheHonestPrussian #:

Thanks, I'll have a jiggle around with this. 

How do you call this 

orderselect()

function? I think there will be the problem. 

 
Laszlo Tormasi #:

How do you call this 

function? I think there will be the problem. 

Laszlo Tormasi #:

How do you call this 

function? I think there will be the problem. 

It' via a for loop in the mq4 document