Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 156
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Often I would declare a variable like this inside functions:
Further inside, at some condition I already call it to see if there is an error. Well, it's not only me but many other places in the code I've encountered. So to say, it's a typical situation. I thought today that it's not logical to declare the same variable each time in each function where you want to control errors. I thought it over and came to the conclusion that it's easier to declare globally once and initialize it in the init. It goes like this:
And further, when you need to call the err variable in user functions, knowing that it already has a value. As a matter of fact, GetLastError() outputs the code of the last error, so if this variable err is called in each function at the end of all calculations, which is responsible for outputting the error code, and calls GetLastError(), then everything will be correct, right?
But if you don't call this variable at the end of some function (following the chain of code execution), it won't reset, and it might be wrong execution, in case there was an error in previous execution chain, but not in current one, but error code is returned last... And to reset it, you have to call this function GetLastError(). I.e. here everything depends on whether it was called or not. If you're not sure that it will be everywhere, it's easier to re-insure and reset it every time, right?
We can declare err globally, then zero it in start() before calling GetLastError(), e.g:
1) why not initialize immediately when declaring int err=0 ?
2) didn't check, but according to documentation err is stored in some variable, which is auto-zeroed when using GetLastError() function,
and also always changes when using some functions (mostly terminal ones)
3) This is why GetLastError() gave a value of 0 after referring to a non-existent ticket number in OrderSelect:
" The other functions do not change the value of the last_error variable under any conditions. ................., OrderSelect, ...................."
You can declare err globally, then zero it in start() before calling GetLastError(), e.g:
then there is already a logical problem. Unless GetLastError() is constantly called (theoretically at the end of each user function).
Sometimes you have to call it more often
Victor (hoz), I don't understand your fuss with the last error.
Declare function for error handling and call it where needed. Everything will be local and can be used everywhere.
Victor (hoz), I don't understand your fuss with the last error.
Declare function for error handling and call it where needed. Everything will be local and can be used everywhere.
It's understandable. But this function will be called when I need it, i.e. when I want to check if there is an error. But if there was an error somewhere before and there is no error at this moment, it will return the previous error... Because in your function Vadim, the LastError variable is not zeroed , by calling GetLastError(). Here's the thing...
It's understandable. But this function will be called when I need it, i.e. when I want to check if there's an error. But if there was an error somewhere earlier, and at this moment there is no error, it will return the previous error... Because in your function Vadim, the LastError variable is not zeroed , by calling GetLastError(). That's the point...
It should not be reset to zero. There should be a habit of checking for errors everywhere after functions. You should also make the call disable. So that it doesn't slow down in combat mode. I.e. it is such a debugger.
The exception, of course, is for errors that need to be analysed, to make a decision.
That's understandable. But this function will be called when I need it, i.e. when I want to check if there is an error. But if there was an error somewhere before and there is no error at this moment, it will return the previous error... Because in your function Vadim, the LastError variable is not zeroed , by calling GetLastError(). Here's the point...
How to calculate profit factor with different t/p and s/l. It is clear, if take and stop are 20 pips each, let's calculate the number of profitable and loss-making trades and divide them. How do I calculate if I take a TP of 40 pips and the stop 30 pips? I have already seen this masks.