Full code :
if(__FUNCTION__ == "TrailingStopLoss" && GetLastError() != 0)
This makes no sense since you always check this condition inside the "TrailingStopLoss" function. Therefore it can be simplified to this:
if(true && GetLastError() != 0)
And then simplify it to:
if(GetLastError() != 0)
Hello,
I am adding a GetLastError, which only print if error belongs to particular function.
I am trying like :
Full code :
Error :
Even GetLastError return 0 is print the if statement, it should only print when GetLastError is not equal to Zero.
Calling GetLastError resets the _LastError variable: GetLastError - Checkup - MQL4 Reference
So, store the error code in a variable at the top of your code.

Calling GetLastError resets the _LastError variable: GetLastError - Checkup - MQL4 Reference
So, store the error code in a variable at the top of your code.
What does true mean here?. we are not using any bool
Calling GetLastError resets the _LastError variable: GetLastError - Checkup - MQL4 Reference
Or alternatively use _LastError variable as your source.
if(__FUNCTION__ == "TrailingStopLoss" && GetLastError() != 0) Print(__FUNCTION__ + " Returning Error Code for Buy Trailing : " + _LastError); // OR if(__FUNCTION__ == "TrailingStopLoss" && _LastError != 0) Print(__FUNCTION__ + " Returning Error Code for Buy Trailing : " + _LastError);
if(__FUNCTION__ == "TrailingStopLoss" && _LastError != 0) Print(__FUNCTION__ + " Returning Error Code for Buy Trailing : " + GetLastError());
Is this correct, here i am not calling GetLastError on if statement
This means that the following expression will always return true:
__FUNCTION__ == "TrailingStopLoss"
Because you are using this expression inside the "Trailing Stop Loss" function.
Also think about the fact that if you change the name of the function and forget to make changes to these conditions, then you will accidentally disable your logs
int err = GetLastError(); if(err != 0) Print(__FUNCTION__ + " Returning Error Code for Buy Trailing : ", err);
Also think about the fact that if you change the name of the function and forget to make changes to these conditions, then you will accidentally disable your logs
I agree.
Vladislav Boyko #:
int err = GetLastError(); if(err != 0) Print(__FUNCTION__ + " Returning Error Code for Buy Trailing : ", err);
I got this and thanks for this code but what the issue with my this code :
if(_LastError != 0) Print(__FUNCTION__ + " Returning Error Code for Buy Trailing : " + GetLastError());
I got this and thanks for this code but what the issue with my this code :
This will most likely work, but it's best not to do it. You request the same error from the terminal 2 times and do it in two different ways. At the very least, this is not logical and may confuse you in the future. By storing the GetLastError value in a variable, you are guaranteed to use the same value in both the if statement and the Print function.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
I am adding a GetLastError, which only print if error belongs to particular function.
I am trying like :
Full code :
Error :
Even GetLastError return 0 is print the if statement, it should only print when GetLastError is not equal to Zero.