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
I have edited your post. In future please use the CODE button when you insert code.
I have edited your post. In future please use the CODE button when you insert code.
That is MQL4 code, not MQL5. MQL5 does not support predefined array variables for timeseries rates data (Open[], Close[], etc.).
Those predefined variables don't exist in MQL5. You will have to convert all of your code into proper MQL5.
Or define them. Using global arrays like Open[], Close[], Low[], High[] in custom indicator for MetaTrader 5 - MQL5 programming forum (2023)
bool bullish = iOpen(Symbol(),_Period,1) < iClose(Symbol(),_Period,1) ? true : false;
That is not an assignment; it's initialization of a common (globally declared), or static variable(s) with a constant. They work exactly the same way in MT4/MT5/C/C++.
They are initialized once on program load.
They don't update unless you assign to them.
In C/C++ you can only initialize them with constants, and they default to zero. In MTx you should only initialize them with constants. There is no default in MT5, or MT4 with strict (which you should always use).
MT4/MT5 actually compiles with non-constants, but the order that they are initialized is unspecified and Don't try to use any price (or indicator) or server related functions in OnInit (or on load or in OnTimer before you've received a tick), as there may be no connection/chart yet:
Unlike indicators, EAs are not reloaded on chart change, so you must reinitialize them, if necessary.
external static variable - MQL4 programming forum #2 (2013)
You can't know when a candle closes. Only when a new tick arrives that starts a new bar is the old bar closed, and that tick could arrive almost at the end of a bar's duration.
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.
MT4: New candle - MQL4 programming forum #3 (2014)
MT5: Accessing variables - MQL4 programming forum #3 (2022)
I disagree with making a new bar function, because it can only be called once per tick (second call returns false). A variable can be tested multiple times.
Running EA once at the start of each bar - MQL4 programming forum (2011)
Increase Order after stoploss - MQL4 programming forum #1.3 (2017)