Kiril Kirilov:
int OnInit() { //--- Initialize high and low with current bar values currentHigh = High[0]; currentLow = Low[0]; return INIT_SUCCEEDED; }
int OnInit() { //--- Initialize high and low with current bar values currentHigh = High[0]; currentLow = Low[0]; return INIT_SUCCEEDED; }
int OnInit() { //--- Initialize high and low with current bar values currentHigh = iHigh(_Symbol, _Period, 0); currentLow = iLow(_Symbol, _Period, 0); return INIT_SUCCEEDED; }
int OnInit() { //--- Initialize high and low with current bar values currentHigh = High[0]; currentLow = Low[0];
-
There are no predefine arrays in MT5 unless you define them. Using global arrays like Open[], Close[], Low[], High[] in custom indicator for MetaTrader 5 - MQL5 programming forum (2023)
- 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:
- 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.
- A new tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.
- Simplify your code.
int OnInit(){ //--- Initialize high and low with current bar values currentHigh = DBL_MIN; currentLow = DBL_MAX; return INIT_SUCCEEDED; } void OnTick(){ ⋮ currentHigh = MathMax( currentHigh, iHigh(_Symbol, _Period, 0) ); currentLow = MathMin( currentLow, iLow(_Symbol, _Period, 0) );
Unlike indicators, EAs are not reloaded on chart change, so you must reinitialize them, if necessary.
external static variable - MQL4 programming forum #2 (2013)
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
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 am trying to track the high and low of the current 15min bar on a give chart. I have this script so far:
However when I compile it I get these errors:
' HL_tracker.mq5' HL_tracker.mq5 1 1
By the way I am very new to scripting in MT5, so I would really appreciate your help!
Thank you in advance!