Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 427
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
And read how many times a static variable is initialized. And the question itself will disappear for its absurdity ;)
Then how to understand this: Local variables declared with the static keyword retain their values for the lifetime of the function. Each time the function is called again, these local variables contain the values they had in the previous call. Isn't a variable declared in a user-defined function local?
On the second question,
if the first tick doesn't catch, the second one will.
Then how to understand this: Local variables declared with the static keyword retain their values for the lifetime of the function. Each time the function is called again, these local variables contain the values they had in the previous call. Isn't a variable declared in a user-defined function a local variable?
Returns the opening time of the bar. It will be the same throughout the bar.
Got it right here. Thank you.
The static modifier makes it static and it is already stored in memory for static variables, not local variables.
This is where I don't get it. In my opinion, it doesn't matter where it is stored, by code we reset the value of the variable to zero every time the function is accessed. What for?
This is where I don't get it. In my opinion, it doesn't matter where it is stored, by code we reset the value of the variable to zero every time the function is accessed. What for?
For the first launch - at declaration. Further you control its contents by yourself.
However, in my opinion, this is not the case: the code is read line by line every time and every time it hits zero, and at the first run even if there is no initialization, the variable would take a zero value. So, the static datetime line New_Time=0; forces the program to do unnecessary work.
However, in my opinion, this is not the case: the code is read line by line every time and every time it hits zero, and at the first run even if there is no initialization, the variable would take a zero value. So, the static datetime string New_Time=0; forces the program to do unnecessary work.
You say no, you say yes...
Don't be offended. But programmers obviously read text differently. I have always considered that if it says "equate to zero" in the program, the computer must equate it to zero regardless of whether at launch or at recurrent reference to a code line. And there's no need to visit any journal to prove zero initialization is unnecessary, you just need to remove it: static datetime New_Time; produces absolutely the same results as static datetime New_Time=0; I don't know how much faster the program's operation is, I admit that it's not significant at all, but still it removes "unnecessary gesture".