In OnInit set a flag indicating it's the first tick. On OnTick if the flag is set, clear it and do what you need.
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.
whroeder1:
In OnInit set a flag indicating it's the first tick. On OnTick if the flag is set, clear it and do what you need.
In OnInit set a flag indicating it's the first tick. On OnTick if the flag is set, clear it and do what you need.
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.
Hi,
I dont really make the link with my question...
MT4
Thanks.
micky_mt4:
Hi,
I dont really make the link with my question...
MT4
Thanks.
The relevant answer was
whroeder1:
In OnInit set a flag indicating it's the first tick. On OnTick if the flag is set, clear it and do what you need.
The rest was additional information as so many people try to do initial calculations in OnInit when all data may not be loaded.
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,
MT4- How can I have my Indicator analyze "X" # of candles before starting?
If I dont do that, it may take many days/week before my EA has enough data to start dealing.
Thanks