borilunad: Why doesn't static work? It works everywhere I go. Fatalik, naphthalik, it can't be! I'm always looking for errors in myself and getting offended!
tara: Because it does not provide for variable initialization at program restart, it MUST.
Right, as in any function, even a local one, static is first presented with some value, then it is compared. Although at first I used it without any idea, checking it in action, and then comes the understanding. It's impossible to understand everything at once, and not everything can be arranged so easily at once. :) I don't touch arrays, they're too much work for me!
You can simply change some parameter. The reaction will occur only after the first tick of a new bar on the set TF.
But you yourself have wondered why the EA's operation is unexplainable on higher TF:)
I wonder if there is connection between the first tick of a new bar and the tester... I don't see it. A tester is a tester. And a chart... is a chart... (I don't mean a tester, but the same demo or real).
Besides, the textbook says... "If there is no explicit initialization, then a static variable is initialized by zero".
So there's no need, as you said, Alexey, in INIT to assign value 0 to lastBarTime variable. It will be zero when the program starts.
I wonder if there is connection between the first tick of a new bar in the working TF and the tester... ...well, I don't notice it... A tester is a tester. And a chart... is a chart... (I don't mean the tester, but the same demo or real).
In addition, the textbook says. "If there is no explicit initialization, a static variable is initialized by zero".
So there is no need, as you said, Alexey, to assign value 0 to lastBarTime variable in INIT. It will be zero when the program starts.
Although this point(from the textbook) is not quite clear to me:
" Static variables are initialized once before calling the specialized init() function, i.e., the value of this variable is not lost on exit from the function, within which a static variable is declared.
What does this have to do with, " before calling the special init() function " and after " i.e. when you exit a user function (judging by the content) in which a static variable is declared? "
A function in which a static variable is declared can be at the end of a program... i.e. at the end of code or somewhere else. Theinit() function is executed once just before the program starts. It turns out to be inconsistent. How can a variable be initialized before theinit() function?
Although this point(from the textbook) is not quite clear to me:
"Static variables are initialized once before calling the specialized init() function, i.e., the value of this variable is not lost on exit from the function, within which a static variable is declared.
What does this have to do with, " before calling the special init() function " and after " i.e. when you exit a user function (judging by the content) in which a static variable is declared? "
A function in which a static variable is declared can be at the end of a program... i.e. at the end of code or somewhere else. Theinit() function is executed once just before the program starts. It turns out to be inconsistent. How can a variable be initialized before theinit() function?
Well, if you are interested - all currently used modes of memory management were first implemented in PL/1. There are four of them: Automatic, Dynamic, Static and Based. C came after and fully adopted these standards.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
What's Static then? It's more like Fatalic...
Why doesn't static work? It works everywhere I go. Fatalik, naphthalik, it can't be! I'm always looking for errors in myself and getting offended!
Because it does not provide for variable initialization at program restart, it MUST.
Are there any other programmers who can confirm this? One vote would not be enough.
You can simply change some parameter. The reaction will occur only after the first tick of a new bar on the set TF.
But you yourself have wondered why the EA's operation is unexplainable on higher TF:)
I wonder if there is connection between the first tick of a new bar and the tester... I don't see it. A tester is a tester. And a chart... is a chart... (I don't mean a tester, but the same demo or real).
Besides, the textbook says... "If there is no explicit initialization, then a static variable is initialized by zero".
So there's no need, as you said, Alexey, in INIT to assign value 0 to lastBarTime variable. It will be zero when the program starts.
I wonder if there is connection between the first tick of a new bar in the working TF and the tester... ...well, I don't notice it... A tester is a tester. And a chart... is a chart... (I don't mean the tester, but the same demo or real).
In addition, the textbook says. "If there is no explicit initialization, a static variable is initialized by zero".
So there is no need, as you said, Alexey, to assign value 0 to lastBarTime variable in INIT. It will be zero when the program starts.
No, it won't. It's a bug :)
Although this point(from the textbook) is not quite clear to me:
" Static variables are initialized once before calling the specialized init() function, i.e., the value of this variable is not lost on exit from the function, within which a static variable is declared.
What does this have to do with, " before calling the special init() function " and after " i.e. when you exit a user function (judging by the content) in which a static variable is declared? "
A function in which a static variable is declared can be at the end of a program... i.e. at the end of code or somewhere else. Theinit() function is executed once just before the program starts. It turns out to be inconsistent. How can a variable be initialized before theinit() function?
Although this point(from the textbook) is not quite clear to me:
"Static variables are initialized once before calling the specialized init() function, i.e., the value of this variable is not lost on exit from the function, within which a static variable is declared.
What does this have to do with, " before calling the special init() function " and after " i.e. when you exit a user function (judging by the content) in which a static variable is declared? "
A function in which a static variable is declared can be at the end of a program... i.e. at the end of code or somewhere else. Theinit() function is executed once just before the program starts. It turns out to be inconsistent. How can a variable be initialized before theinit() function?
Well, if you are interested - all currently used modes of memory management were first implemented in PL/1. There are four of them: Automatic, Dynamic, Static and Based. C came after and fully adopted these standards.