int OnInit(){ tt1= (int)TimeTradeServer();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.
thanks William Roeder but I tried to enter OnCalculate and only once for each bar and on the first call there is always the same error
//+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { // NewBar if(prev_calculated != rates_total) { int tt1= (int)TimeTradeServer(); int tt2= (int)TimeLocal(); int tt3= tt1-tt2; Print("Tcurrent: ",TimeToString(tt1,TIME_MINUTES)," Tlocal; ",TimeToString(tt2,TIME_MINUTES)); if(tt3==3600 ) fuso=1; //Alert("NewBar"); //Print("rates_total: ",IntegerToString(rates_total)," prev_calculated: ",IntegerToString(prev_calculated)); } return(rates_total); }
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 have a problem restarting MT5 if I load the indicator on the chart the first time everything is ok but if I close and restart MT5 the time is not initialized correctly