-
You are looking at D1 bar zero. You will get multiple cross and uncross as the candle forms.
You should wait for a new D1 bar to start and check bars one and two.
-
if(newtime == TimeCurrent())
That will almost always be false, unless a tick happens at the first second of the start of the candle.
For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart), volume is unreliable (miss ticks), Price is unreliable (duplicate prices and The == operand. - MQL4 programming forum.) Always use time.
New candle - MQL4 programming forum #3 (2014.04.04)I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
Running EA once at the start of each bar - MQL4 programming forum (2011.05.06)
-
You are looking at D1 bar zero. You will get multiple cross and uncross as the candle forms.
You should wait for a new D1 bar to start and check bars one and two.
- That will almost always be false, unless a tick happens at the first second of the start of the candle.
For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart), volume is unreliable (miss ticks), Price is unreliable (duplicate prices and The == operand. - MQL4 programming forum.) Always use time.
New candle - MQL4 programming forum #3 (2014.04.04)I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
Running EA once at the start of each bar - MQL4 programming forum (2011.05.06)
Thank you William!
I am struggling with point No. 2. You send me to some mql4 forums and I am familiar with mql5. I believe the logic still the same... I just have to sort out how to code it...
Thank you William!
I am struggling with point No. 2. You send me to some mql4 forums and I am familiar with mql5. I believe the logic still the same... I just have to sort out how to code it...
Found it for MQL5!:
- 2021.02.23
- www.mql5.com
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
I am starting to code in mql5 and I am devloping a code that opens one positions every time there is a crossover of daily EMA8 and daily EMA21 and price is above daily SMA200.
I do get to open 2 positions, but there are not any more positions but conditions are being met... I am not getting what is my mistake.
I would aprreciate some help here!