ResetLastError() gives old error despite ResetLastError()

 

Hi there,

at the end of my EA's OnTick() function I wrote a short line to get the latest error that occured:

         if (GetLastError()!=0) 
            {
             v_err = GetLastError();
             Print (v_err);
             ResetLastError();
            }

Although I am resetting it, on every tick there will be printed an error until there is a new one with another Error-Code. In my case there occurs an error 4756 due to market closed and it will be printed every new bar... How do I manage to get it printed only ONCE after it occured? I have tried to store it in a variable, but that got no relief at all :-(

edit: v_err is defined as a global variable of integer type

Documentation on MQL5: Constants, Enumerations and Structures / Codes of Errors and Warnings / Trade Server Return Codes
Documentation on MQL5: Constants, Enumerations and Structures / Codes of Errors and Warnings / Trade Server Return Codes
  • www.mql5.com
Trade Server Return Codes - Codes of Errors and Warnings - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

try this, it will print out only new error if it occurred

         int n_err=GetLastError();

         if(n_err && n_err!=v_err) 
            {
             v_err = n_err;
             Print(n_err);
             ResetLastError();
            }
 
Ilyas #:

try this, it will print out only new error if it occurred

THANK YOU! That worked. but I still don't understand what my failure was... is there some kind of errata?


edit: what if there is the same error multiple times after one another. I want the "new" errors to be shown.