![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
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
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.