Forum on trading, automated trading systems and testing trading strategies
When you post code please use the CODE button (Alt-S)!
-
Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum 2019.05.06
Messages Editor -
// Global Variables int hShift = iHighest(_Symbol, MyPeriod, MODE_HIGH, HighLowBars, Shift); int lShift = iLowest(_Symbol, MyPeriod, MODE_LOW, HighLowBars, Shift); double hHigh = High[hShift]; double lLow = Low[lShift]; double LastClose = Close[0]; datetime NewCandleTime = TimeCurrent();
Those are not assignments; they are initialization of a common (globally declared), or static variable 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 server related functions in OnInit (or on load), as there may be no connection/chart yet:
- Terminal starts.
- Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
- OnInit is called.
- For indicators OnCalculate is called with any existing history.
- Human may have to enter password, connection to server begins.
- New history is received, OnCalculate called again.
- New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.
-
Unlike indicators, EAs are not reloaded on chart change so you must reinitialize them, if necessary.
external static variable - MQL4 programming forum #2 2013.02.10
-
-
if(Minute()==00 || Minute()==30)
What if there are no ticks during a specific candle period? There can be minutes between ticks during the Asian session, think M1 chart. Larger charts, think weekend, market holiday (country and broker specific), requires knowledge of when your broker stops and starts (not necessary the same as the market.)
"Free-of-Holes" Charts - MQL4 Articles 20 June 2006
No candle if open = close ? - MQL4 programming forum
Thank you... I didn't know it

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi, I am new with MQ4 and I've tried to put this to work but there is not way to read a second NEW candle. I've being testing in a range of 2 weeks, and the script should look for a new candle every 5 minutes (candles of 5 minutes period). I really don't know what I am missing. Here you will see the code, please modify any part of the code and put it the Comment just to know what was wrong and learn from you. I will really appreciate your help.