I have a problem with MT5. I was building a more advanced EA and I had strange problems. Then I decided to go to basics and see what is the problem. Here is the simple code I wrote, and it is not performing how it should.
The first logic is for checking if there is a new candle close/open.
When there is, it should take a trade if EMA 20 is below the EMA 50).
But here are the results in the strategy tester... It opens trades everywhere!
Your code is written in such a way that it cannot be called on each TICK.
The way you did, it will only work as you want, if called on each opening of a new candle..
Your code is written in such a way that it cannot be called on each TICK.
The way you did, it will only work as you want, if called on each opening of a new candle..
I want my code to work on opening of a new candle, but the problem is that the tester is not recognizing the if statement, on every new candle open it opens a trade, doesnt care about EMAs..
You can try it yourself. I wanted to put a picture put forum rules didnt allow that big message
- Luka Savić: The first logic is for checking if there is a new candle close/open.
if(price_close1!=old_price_close || price_high1!=old_price_high || price_low1!=old_price_low || price_open1!=old_price_open)
-
Doubles are rarely equal. Understand the links in:
The == operand. - MQL4 programming forum #2 2013.06.07 -
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
-
-
double MA1 = iMA(Symbol(),timeframe,MA1period,1,MODE_EMA,PRICE_CLOSE); double MA2 = iMA(Symbol(),timeframe,MA2period,1,MODE_EMA,PRICE_CLOSE);
Perhaps you should read the manual, especially the examples.
How To Ask Questions The Smart Way. 2004
How To Interpret Answers.
RTFM and STFW: How To Tell You've Seriously Screwed Up.They all (including iCustom) return a handle (an int). You get that in OnInit. In OnTick/OnCalculate (after the indicator has updated its buffers), you use the handle, shift and count to get the data.
Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 2020.03.08
How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 2020.07.05
How to call indicators in MQL5 - MQL5 Articles 12 March 2010
-
Doubles are rarely equal. Understand the links in:
The == operand. - MQL4 programming forum #2 2013.06.07 -
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
-
-
Perhaps you should read the manual, especially the examples.
How To Ask Questions The Smart Way. 2004
How To Interpret Answers.
RTFM and STFW: How To Tell You've Seriously Screwed Up.They all (including iCustom) return a handle (an int). You get that in OnInit. In OnTick/OnCalculate (after the indicator has updated its buffers), you use the handle, shift and count to get the data.
Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 2020.03.08
How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 2020.07.05
How to call indicators in MQL5 - MQL5 Articles 12 March 2010
I found a video on YT... I can't check values of MAs like this, i need to put them into buffers... coming from MT4 to MT5...
Thanks..

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I have a problem with MT5. I was building a more advanced EA and I had strange problems. Then I decided to go to basics and see what is the problem. Here is the simple code I wrote, and it is not performing how it should.
The first logic is for checking if there is a new candle close/open.
When there is, it should take a trade if EMA 20 is below the EMA 50).
But here are the results in the strategy tester... It opens trades everywhere!