Hi all,
I'm trying to introduce some logic using GetLastError(), and having trouble with it.
Here's the bit of code I'm working with right now
My order is going through fine, but the else condition is always triggered. Confusingly, my printed error result here is 0.
I fumbled around with this for a previous segment of this EA and abandoned it, but I'd like to include this part. Any ideas what my problem is?
GetLastError() resets error code when invoked - you can call it only once.
If you want to access error code multiple times, use _LastError variable and after that call ResetLastError() to clear the error code.
In your sample code, when GetLastError() is called as part of the if condition, _LastError variable is cleared, and in else you don't have error code any more.

GetLastError() resets error code when invoked - you can call it only once.
If you want to access error code multiple times, use _LastError variable and after that call ResetLastError() to clear the error code.
Or put GetLastError into a variable and access that multiple times.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi all,
I'm trying to introduce some logic using GetLastError(), and having trouble with it.
Here's the bit of code I'm working with right now
My order is going through fine, but the else condition is always triggered. Confusingly, my printed error result here is 0.
I fumbled around with this for a previous segment of this EA and abandoned it, but I'd like to include this part. Any ideas what my problem is?