MT4- How can I have my Indicator analyze "X" # of candles before starting?

 

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

 
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:
  1. Terminal starts.
  2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
  3. OnInit is called.
  4. For indicators OnCalculate is called with any existing history.
  5. Human may have to enter password, connection to server begins.
  6. New history is received, OnCalculate called again.
  7. 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.
Don't try to use any price or server related functions in OnInit (or on load,) as there may be no connection/chart yet:
  1. Terminal starts.
  2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
  3. OnInit is called.
  4. For indicators OnCalculate is called with any existing history.
  5. Human may have to enter password, connection to server begins.
  6. New history is received, OnCalculate called again.
  7. 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.

Reason: