Do you have mq4 script to update currency's all time frames?

 

Sometimes I got "On Update" for charts. Do you have mq4 script to update currency's all time frames?

So that I can get the data and display properly on chart, thanks.

 
Susan Beiermann:

Sometimes I got "On Update" for charts. Do you have mq4 script to update currency's all time frames?

So that I can get the data and display properly on chart, thanks.

Hi! I don't think a script will help you, your problem probably is poor connection to your broker, that is why it say On Update,

it simply is your connection that is not able to receive the data your broker sends to MT4 quickly enough, anyway, that is my bet on it.

check your gear, router, cables, etc, however, the problem could, but not very likely to be on the broker side, they usually have very fast connections,

but I have experienced a broker on New Zeeland once, they where so slow I had to find another broker with servers closer to me.

sorry can't help with a script, Hope this helps.

 
cozyman:

Hi! I don't think a script will help you, your problem probably is poor connection to your broker, that is why it say On Update,

it simply is your connection that is not able to receive the data your broker sends to MT4 quickly enough, anyway, that is my bet on it.

check your gear, router, cables, etc, however, the problem could, but not very likely to be on the broker side, they usually have very fast connections,

but I have experienced a broker on New Zeeland once, they where so slow I had to find another broker with servers closer to me.

sorry can't help with a script, Hope this helps.

Thanks @cozyman!

I don't want to open charts with different timeframes 1 by 1, so I would like to have scripts to do so.

Yes, sometimes bad internet connection leads to load chart's details slowly and show On Update.

I may think of seeking brokers if I could not find any scripts.

Thanks again for your ideas.

 

On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
          Download history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26.4 2019.05.20

The function linked to, opens a hidden chart for the symbol/TF in question (if not already open), thus updating history, and temporarily placing the symbol on Market Watch (if not already there), so SymbolInfoDouble(symbol, SYMBOL_BID) or MarketInfo(symbol, MODE_BID) don't also return zero on the first call.

 
William Roeder:

On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
          Download history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26.4 2019.05.20

The function linked to, opens a hidden chart for the symbol/TF in question (if not already open), thus updating history, and temporarily placing the symbol on Market Watch (if not already there), so SymbolInfoDouble(symbol, SYMBOL_BID) or MarketInfo(symbol, MODE_BID) don't also return zero on the first call.

Thanks William.


I tried to use below but still faced 4073 error, how can I deal with it?

Steps to procedure:

1. Tools -> History Center -> AUDJPY M1 -> delete all records except top record (Aim to simulate no history data)
2. Launch below EA
3. Result: Num rates = -1, Error Code = 4073


#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
int day = 0;

#define HR2400 (PERIOD_D1 * 60)    // 86400 = 24 * 3600
#define SYMBOL string
#define THIS_SYMBOL ""

bool download_history(ENUM_TIMEFRAMES period=PERIOD_CURRENT) {
   return download_history(_Symbol, period);
}

bool download_history(SYMBOL symbol, ENUM_TIMEFRAMES period=PERIOD_CURRENT){
   if(period == PERIOD_CURRENT) {
      period = (ENUM_TIMEFRAMES)_Period;
   }
   
   ResetLastError();
   
   datetime other = iTime(symbol, period, 0);
   if(_LastError == 0 && other != 0) {
      return true;
   }
   if(_LastError != ERR_HISTORY_WILL_UPDATED && _LastError != ERR_NO_HISTORY_DATA) {
      PrintFormat("iTime(%s,%i) Failed: %i", symbol, period, _LastError);
   }
   
   return false;
}

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
  
  
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
      if(TimeDayOfWeek(TimeCurrent()) != day)
      {
         Print("Start Downloading history");
         
         day = TimeDayOfWeek(TimeCurrent());
         while(!download_history(PERIOD_M1) ) {
            Sleep(1000);
            RefreshRates();
            Print("Retrying download history");
         }
         Print("Downloaded history");

         datetime start_time = TimeCurrent() - 2 * PERIOD_D1 * 60;
         datetime end_time = TimeCurrent() - 1 * PERIOD_D1 * 60;

         Print("Set times - start: ", start_time, " stop: ", end_time);
         
         // Get rates of smaller periods within the session
         MqlRates rates[];
         
         int num_rates = CopyRates(Symbol(), PERIOD_M1, start_time, end_time, rates);
            
         Print("Num rates = ", num_rates);
         if(num_rates == -1)
         {
            Print("Error Code = ",GetLastError()); 
            ResetLastError();
         }
      }
  }
//+------------------------------------------------------------------+
Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • www.mql5.com
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
 
Susan Beiermann:

Sometimes I got "On Update" for charts. Do you have mq4 script to update currency's all time frames?

So that I can get the data and display properly on chart, thanks.

Is your update problem causing problems with all charts, or are you having problems with a multicurrency indicator or expert?

 
Ahmet Metin Yilmaz:

Is your update problem causing problems with all charts, or are you having problems with a multicurrency indicator or expert?

Sometimes I got this problem on charts. Thus, due to missing bars for calculate multicurrency in expert.
 
William Roeder:

On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
          Download history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26.4 2019.05.20

The function linked to, opens a hidden chart for the symbol/TF in question (if not already open), thus updating history, and temporarily placing the symbol on Market Watch (if not already there), so SymbolInfoDouble(symbol, SYMBOL_BID) or MarketInfo(symbol, MODE_BID) don't also return zero on the first call.

Hi William,

May you advise how to handle error 4066/4073 from my case mentioned above? Thanks.

 
Maybe it would be possible to Sleep() and retry the request. Maybe even in a repetitive loop.
We are talking about coding, right?



 
Dominik Egert:
Maybe it would be possible to Sleep() and retry the request. Maybe even in a repetitive loop.
We are talking about coding, right?



hi Dominik,

Yes, we are now talking about coding. May you advise where and how to use Sleep() to prevent error?

Thanks.

 
Susan Beiermann:

hi Dominik,

Yes, we are now talking about coding. May you advise where and how to use Sleep() to prevent error?

Thanks.

I suggest going something like this:

int err_cnt = NULL;
int err_code = NULL;

while( (err_cnt < 5)
    && (err_code != NULL) )
{
	ResetLastError();
        [... Call some MQL-Api function ...]
        err_code = GetLastError();
        err_cnt++; // += (err_code != NULL);
        Sleep((500 * err_cnt) * (err_code != NULL));
}

[... continue with your code ...]

As an idea of what I ment.

Reason: