So I have a strange problem. I tried to verify NewBar appearance with the following code from Samuels article "Step-By-Step Guide to writing an Expert Advisor in MQL5 for Beginners". I tried the code on System Tester and I saw that is no trade. Than I saw that the Old_Time variable take the value of New_Time variable without any code.
I mean that Old_Time=New_Time but IsNewBar is never equal to true.
I do not know why Old_Time is equal to New_Time[0] without execution of the if(Old_Time!=New_Time[0]) loop.
.
I hope you understand what I mean.
Sorry for my bad english.
Variable IsNewBar is declared locally, and so it will initiated on every tick with false value. To solve this, declare variable IsNewBar as statically declared local variable or globally declared variable.
Please read MQL5 doc about variable especially this Visibility Scope and Lifetime of Variables
Here's how to declare as statically declared local variable
void OnTick() { static bool IsNewBar=false;
Here's the global one
bool IsNewBar=false; void OnTick() {
Variable IsNewBar is declared locally, and so it will initiated on every tick with false value. To solve this, declare variable IsNewBar as statically declared local variable or globally declared variable.
Please read MQL5 doc about variable especially this Visibility Scope and Lifetime of Variables
Here's how to declare as statically declared local variable
Here's the global one
Thank ypu phi.nuts!
So to answer myself to my question: The if loop( ........) is executed but the variable IsNewBar do not change its value do to its every tick "false" initialization.
Variable IsNewBar is declared locally, and so it will initiated on every tick with false value. To solve this, declare variable IsNewBar as statically declared local variable or globally declared variable.
RaptorUK:
That means once set to true it will always be true and that defeats the aim, doesn't it ?
I think that if it is declared as "static variable" its value will be kept on the next function call.
So on first call isNewBar is initialized to "false", than if the "if loop" is "true" will be changed to "true", than on the next call of OnTick() the value remain "true".
Correct me please if I am wrong!
I think that if it is declared as "static variable" its value will be kept on the next function call.
So on first call isNewBar is initialized to "false", than if the "if loop" is "true" will be changed to "true", than on the next call of OnTick() the value remain "true".
Correct me please if I am wrong!
So I have a strange problem. I tried to verify NewBar appearance with the following code from Samuels article "Step-By-Step Guide to writing an Expert Advisor in MQL5 for Beginners". I tried the code on System Tester and I saw that is no trade. Than I saw that the Old_Time variable take the value of New_Time variable without any code.
I mean that Old_Time=New_Time but IsNewBar is never equal to true.
I do not know why Old_Time is equal to New_Time[0] without execution of the if(Old_Time!=New_Time[0]) loop.
The loop did execute, your code is good, try the attached.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
So I have a strange problem. I tried to verify NewBar appearance with the following code from Samuels article "Step-By-Step Guide to writing an Expert Advisor in MQL5 for Beginners". I tried the code on System Tester and I saw that is no trade. Than I saw that the Old_Time variable take the value of New_Time variable without any code.
I mean that Old_Time=New_Time but IsNewBar is never equal to true.
I do not know why Old_Time is equal to New_Time[0] without execution of the if(Old_Time!=New_Time[0]) loop.
.
I hope you understand what I mean.
Sorry for my bad english.