Do EA normally stops after Last error ?

 

I think EA stops control just after getting an error, If it's the case please tell me how to let the control passes in advance after the last error regardless what the error is.

      {
      
      while (TicketSell2 == -1)
      Sleep(100);
      RefreshRates();
      TicketSell2 = OrderSend(Symbol(), OP_SELLSTOP, Lot2, OpenSellPrice1, UseSlippage, SL, TP, "Sell1Case", MagicN, 0, clrGreen);  
      if (TicketSell2 == -1) Print ("Error opening TicketSell2 Order ", GetLastError());
           
      }
 
Toufik:

I think EA stops control just after getting an error, If it's the case please tell me how to let the control passes in advance after the last error regardless what the error is.


https://docs.mql4.com/common/resetlasterror

ResetLastError - Common Functions - MQL4 Reference
ResetLastError - Common Functions - MQL4 Reference
  • docs.mql4.com
ResetLastError - Common Functions - MQL4 Reference
 

Do I need to set the value of LastError into zero, is this going to make the control passes in advance ? if yes how do I use this function ?

Thanks. 

 
Toufik:

Do I need to set the value of LastError into zero, is this going to make the control passes in advance ? if yes how do I use this function ?

Thanks. 


No, GetLastError() won't stop the EA, it just returns the error code, identify the error to correct and avoid it ---> https://www.mql5.com/en/docs/constants/errorswarnings/errorcodes

Then after, you can code a check routine, this article is full of common errors check-routine : https://www.mql5.com/en/articles/2555

 
Toufik: I think EA stops control just after getting an error, If it's the case please tell me how to let the control passes in advance after the last error regardless what the error is.
Toufik: Do I need to set the value of LastError into zero, is this going to make the control passes in advance ? if yes how do I use this function ?
  1. It doesn't stop. Only on divide by zero, array exceeded, and those types of errors. Look in the Experts tab for those.

  2. You normally never need to reset it. Never look at it unless the function returns an error. Only those few functions that return a value (e.g. iTime, MarketInfo, etc.) must you reset, call, and then check.
              What are Function return values ? How do I use them ? - MQL4 and MetaTrader 4 - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
 
whroeder1:
  1. It doesn't stop. Only on divide by zero, array exceeded, and those types of errors. Look in the Experts tab for those.

  2. You normally never need to reset it. Never look at it unless the function returns an error. Only those few functions that return a value (e.g. iTime, MarketInfo, etc.) must you reset, call, and then check.
              What are Function return values ? How do I use them ? - MQL4 and MetaTrader 4 - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles

Here where EA stops running, and the LastError is 130 and it's about Invalid OpenPrice and not invalid SL/TP as we figured out before in an other topic https://www.mql5.com/en/forum/223994

I would like for it to continue and Sell at updated new price no matter when it will be available but it stops just after the error was printed. my question is why it stops and how can I make it ignore the error and continue 

14:59:44.254 '111111': order sell 0.40 USDCAD opening at market sl: 1.24431 tp: 1.23556 failed [Invalid S/L or T/P]

Help me understand why Order failed to open ?
Help me understand why Order failed to open ?
  • 2018.01.06
  • www.mql5.com
Hi, Under my EA the order failed to open saying in log "Invalid S/L or T/P" while SL and TP are set to NULL, it happened in very volatile market an...
 

Hello,

Maybe try something like this. If I get an error its meant to go to main function.

     {errorlevel=(GetLastError());
      main();
      }
   else  errorlevel=(GetLastError());
      TicketNumber=ticket;
   }
 
// Errors causing a temporary execution stop, the error code is available at the next call of a MQL root function, i.e. the next call of OnStart()
#define ERR_WRONG_FUNCTION_POINTER                                 4001
#define ERR_NO_MEMORY_FOR_CALL_STACK                               4003
#define ERR_RECURSIVE_STACK_OVERFLOW                               4004    // stack overflow
#define ERR_NO_MEMORY_FOR_PARAM_STRING                             4006
#define ERR_NO_MEMORY_FOR_TEMP_STRING                              4007
#define ERR_NO_MEMORY_FOR_ARRAYSTRING                              4010
#define ERR_TOO_LONG_STRING                                        4011
#define ERR_REMAINDER_FROM_ZERO_DIVIDE                             4012
#define ERR_UNKNOWN_COMMAND                                        4014

// Errors causing a full execution stop, the error code is available when/after the program is manually re-initialized
#define ERR_ZERO_DIVIDE                                            4013
#define ERR_DLL_CALLS_NOT_ALLOWED                                  4017    // DLL imported functions
#define ERR_CANNOT_LOAD_LIBRARY                                    4018
#define ERR_CANNOT_CALL_FUNCTION                                   4019
#define ERR_EX4_CALLS_NOT_ALLOWED                                  4020    // EX4 imported functions
 
Toufik: Here where EA stops running, and the LastError is 130 ... I would like for it to continue

Asked and answered, here and the other thread. Don't double post.
          General rules and best pratices of the Forum. - General - MQL5 programming forum

What part of "It doesn't stop" was unclear? What part of "we can't see your broken code," was unclear?

Use the debugger or print out your variables, and find out why.

 
whroeder1:

Asked and answered, here and the other thread. Don't double post.
          General rules and best pratices of the Forum. - General - MQL5 programming forum

What part of "It doesn't stop" was unclear? What part of "we can't see your broken code," was unclear?

Use the debugger or print out your variables, and find out why.


Well.. to summarize, the first thread was about Invalid Openprice causing error 130 at the time of an important news, it was answered and the current one regarding EA stops after error 130 as well and it was answered too, Thanks, I've learned a lot but my problem still not solved.

Now my main question is, how to let EA tries repeatedly open a market or pending order if error 130 happened 

I could be on wrong way, just correct me or guide me on other documentations, Thanks.

      {
      
      while (TicketSell2 == -1)
      Sleep(100);
      RefreshRates();
      TicketSell2 = OrderSend(Symbol(), OP_SELLSTOP, Lot2, OpenSellPrice1, UseSlippage, SL, TP, "Sell1Case", MagicN, 0, clrGreen);  
      if (TicketSell2 == -1) 
         {
         Print ("Error opening TicketSell2 Order ", GetLastError());
         //May be something here ??
         }  
      }


 


 
Toufik:  how to let EA tries repeatedly open a market or pending order if error 130 happened


Log the error, return, on the next tick if conditions are still valid, retry the operation.


Reason: