Don't check in OnInit. Check in OnCalculate and then remove it ChartIndicatorDelete
- Chart Operations - MQL4 Reference
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.
William Roeder:
Don't check in OnInit. Check in OnCalculate and then remove it ChartIndicatorDelete - Chart Operations - MQL4 Reference
Don't check in OnInit. Check in OnCalculate and then remove it ChartIndicatorDelete - Chart Operations - MQL4 Reference
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.
Thanks William Roeder
Very helpful

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
Hi
I have a condition in OnInit to check the AccountNumber.
It works correctly, but when I close the MT4 and re_open it, I have to drag the indicator to the chart again, If not, the indicator won't work.
I noticed that the OnInit function works before the account gets signed in, So, at that time AccountNumber() returns Zero and the condition returns false and the rest of my codes removes the indicator from the chart.
I also tried this:
But it didn't help and make the MT4 freezing.
Please help me understand what can I do.
Regards