ERR_ARRAY_BAD_SIZE or 4011 error in my expert with my low size arrays

 

hello

im sorry im not well in english language 

my expert create renko closes,opens and etc and save the data in a few arrays

when my MT5 was disconnected the expert print 4011 error

my mqltick array size is 10000 and The other 14 arrays each have a size of 50

I don't understand how the size of arrays is related to internet 

and few hours ago when internet was connected the error fixed automatically

now i run it again on two different chart( XAUUSD and WTI )

My expert works very well on XAUUSD chart but the other one doesn't work and gives  4011 error

can u help me to fix this problem 

my code : 


input int renko_time_start=50;
input int renko_time_finish=100;
MqlTick tick_array[];
MqlTick tick_array_new[];
uint tick_array_count=0;
input int tick_num=10000;
input int tick_num_max=10000;
input int time_sleep=2000;//time sleep (m seconds)
input int time_OnTime=5;//time On Time (seconds)
int band_period=20;
int band_deviations=2;
int band_shift=0;
int ichimoku_tenkansen=9;
int ichimoku_kijunsen=26;
int ichimoku_spanb=52;
int macdon_ma=3;
int macdon_rsiperiod=2;
int macdon_fastema=6;
int macdon_slowema=12;
int macdon_signalsma=3;
int candles_close[];
int candles_open[];
int candles_high[];
int candles_low[];
int candles_macdon[];
int candles_band_up[];
int candles_band_mid[];
int candles_band_down[];
int candles_span_a[];
int candles_span_b[];
int candles_ks[];
int candles_ts[];
int renko_time_int_count;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create timer

      int tick_count=CopyTicks(Symbol(),tick_array,COPY_TICKS_ALL,0,tick_num);
      if(tick_count==-1)Print("error ",GetLastError());
      Print("Primary ticks downloaded ---> ",tick_count);



   EventSetTimer(time_OnTime);
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- destroy timer
   EventKillTimer();
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
{
  int ticks = ArraySize(tick_array);
  MqlTick ppp[];
  if(CopyTicks(_Symbol,ppp,COPY_TICKS_ALL,0,1)<1)Print("Download Failed!  Line : ",__LINE__);
  tick_array_count=(ppp[0].time_msc - tick_array[ticks-1].time_msc)/400;
  CopyTicks(_Symbol,tick_array_new,COPY_TICKS_ALL,0,tick_array_count);
  Print(tick_array_count==0?"Tick Not Downloaded!  tick_array_count = "+(string)tick_array_count:"Refreshed! Ticks Downloaded ---> ",tick_array_count);
  insert_2(tick_array,tick_array_new);
  ZeroMemory(tick_array_new);
  if(GetLastError()==ERR_ARRAY_BAD_SIZE)Print("Size of Tick Array Is Too Much!  Size = ",ArraySize(tick_array));
  
  for( int renko_time_int=renko_time_start;renko_time_finish>=renko_time_int;renko_time_int++)
  {
\\calculating and saving data
  }
   
  ZeroMemory(candles_close);
  ZeroMemory(candles_open);
  ZeroMemory(candles_high);
  ZeroMemory(candles_low);
  ZeroMemory(candles_band_up);
  ZeroMemory(candles_band_mid);
  ZeroMemory(candles_band_down);
  ZeroMemory(candles_span_a);
  ZeroMemory(candles_span_b);
  ZeroMemory(candles_ts);
  ZeroMemory(candles_ks);
  Sleep(time_sleep);
  
  }

please help me!

 
  1. Amini1382: when my MT5 was disconnected the expert print 4011 error

    Stop using the timer. Wait for a new tick.

  2. int OnInit()
      {
    //--- create timer
    
          int tick_count=CopyTicks(Symbol(),tick_array,COPY_TICKS_ALL,0,tick_num);

    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:

    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. A new tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.
 
William Roeder #:
  1. Stop using the timer. Wait for a new tick.

  2. 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:

    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. A new tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.

very thanks for your answer

you right but i have to use ontimer to control my pc cpu

can you tell me what can i do for this problem?

 I want to create a bool value that will be valued True when tick is changed ( ontick() is called) , then call the ontimer. can you help me to make it?

or please help me if you have your own idea