Questions from Beginners MQL5 MT5 MetaTrader 5 - page 386

 
Roman Shiredchenko:

Look, on the four, I can't seem to get through...

I work with arrays - I need to write the tick arrival time in the array - for example, I write a bid. On every tick. I do everything according to tickets, for which I am grateful to Artyom Trishkin . Not everything works. Fought for the second day. Prints

zeros.

https://www.mql5.com/ru/forum/145455/page913#1017464

Thank you.

I see that in init variable SIZE is 0, so what's the array size then? Then again in start SIZE is also 0 ... What's in the log?
 
Artyom Trishkin:
I see that in init the variable SIZE has a value of 0, so what is the size of the array then? Then again in start SIZE is also 0 ... What's in the log?
Zeros... I'm trying to figure it out...
 

And so are zeros... I don't understand anything...

//---------------------
extern int MaxDrawTicks=100;
extern int Num_Aver_of_Ticks=5;  
double     xBuffer_Time [1000000]; // Массив значений  
                         // В котором индекс - номер тика, значение - это бид 
int SIZE=0;               // Вспомогательная переменная для массива                                  
int tickCounter, tickCounter_Current; 
//+------------------------------------------------------------------+
int init()
  {   
//--- устанавливаем размер динамического массива
  // if(ArrayResize(xBuffer_Time,SIZE)<0) {Print(" Ошибка в изменении размера массива времени поступления тиков "); return(false);}
//--- установим индексацию для буфера как в таймсерии для динамического массива
  // ArraySetAsSeries(xBuffer_Time,true);    
//---   Возвращает количество элементов указанного массива. 
  // int S=ArraySize(xBuffer_Time);
  // if (S>=0) Print("Размер массива: ",S);
  // else Print("Ошибка. Массив не создан ",S);        
  // ArrayInitialize(xBuffer_Time, 0);
   return(0);
  }  
//+------------------------------------------------------------------+
int start()
  {  
   //ArrayResize(ValueArr,size);
   //ValueArr[size-1] = GetValue();
   //size++; 
 //----------------------------------------  
  // ArrayResize(xBuffer_Time,SIZE);
   xBuffer_Time[SIZE] = Bid; //NormalizeDouble((iTime (_Symbol,1,0)-_start), 2); 
   SIZE ++;
   Print (" Значение xBuffer_Time[SIZE] = ", DoubleToStr(xBuffer_Time[SIZE],Digits) );
   Print (" Значение SIZE = ", DoubleToStr(SIZE,2) );  
 //---------------------------------------      
//------------
   return(0);
  }
 
Roman Shiredchenko:

And so are zeros... I don't understand anything...

I hinted that SIZE must be increased first so that it's not zero, and only then the array's size should be changed.
 
Artyom Trishkin:
Well, I hinted at the fact that SIZE must first be increased to make it non-zero, and only then change the size of the array.

:-)

Thanks.

It works - use it if you need it.

//---------------------
extern int MaxDrawTicks=100;
extern int Num_Aver_of_Ticks=5;  
double     xBuffer_Time []; // Массив значений   динамический
                            // В котором индекс - номер тика, значение - это бид 
int SIZE=0;                 // Вспомогательная переменная для массива                                  
int tickCounter, tickCounter_Current; 
//+------------------------------------------------------------------+
int init()
  {   
//--- устанавливаем размер динамического массива
   if(ArrayResize(xBuffer_Time,2000000)<0) {Alert(" Ошибка в изменении размера массива времени поступления тиков "); return(false);}
//--- установим индексацию для буфера как в таймсерии для динамического массива
  // ArraySetAsSeries(xBuffer_Time,true);    
//---   Возвращает количество элементов указанного массива. 
   int S=ArraySize(xBuffer_Time);
   if (S>=0) Alert("Размер массива: ",S);
   else Print("Ошибка. Массив не создан ",S);        
   ArrayInitialize(xBuffer_Time, 0);
   return(0);
  }  
//+------------------------------------------------------------------+
int start()
  {  
   //ArrayResize(ValueArr,size);
   //ValueArr[size-1] = GetValue();
   //size++; 
 //----------------------------------------  
   ArrayResize(xBuffer_Time,SIZE);
   xBuffer_Time[SIZE-1] = Bid; //NormalizeDouble((iTime (_Symbol,1,0)-_start), 2); 
  
   if ( SIZE >= 0 && ArraySize(xBuffer_Time) < 2147483647)
      {
      Alert (" Значение xBuffer_Time[SIZE-1] = ", DoubleToStr(xBuffer_Time[SIZE-1],Digits) );
      Alert (" Значение SIZE = ", DoubleToStr(SIZE,2) );  
      } 
    SIZE ++;   
 //---------------------------------------      
//------------
   return(0);
  }
 
Roman Shiredchenko:

:-)

Spc.

It works - use it if you need it.

Something I don't understand - SIZE is zero, so why should I change the array size first, and then increase SIZE? What a mess...

I once did an array filling with ticks for a ticks Expert Advisor, which defines the intensity and range of ticks. I've cut out pieces for examples:

//+------------------------------------------------------------------+
   MqlTick struct_tick;
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   //--- Запись ID графика
   gv_chart_id_name=Prefix+"_chart_id";                        // имя GV терминала
   long   chart_id=get.GetChartID(symbol);                     // id текущего графика
   double chart_id_double=ToDouble(chart_id);                  // id в представлении double
   if(chart_id>=0) {                                           // chart_id==0 в тестере
      if(!GlobalVariableCheck(gv_chart_id_name))               // Если GV-переменная удалена
         GlobalVariableSet(gv_chart_id_name,chart_id_double);  // создадим опять
      }
   else graph.Message("Чё-та нету chart_id : Symbol()="+symbol+", chart_id="+IntegerToString(chart_id));
   
   //--- работа с тиками текущего графика
   if(SymbolInfoTick(symbol,struct_tick)) {
      double tick_bid=struct_tick.bid;
      datetime tick_time=struct_tick.time;
      WorkOnTick(symbol,tick_bid,tick_time,slowPeriod);
      }
//---
  }
//+------------------------------------------------------------------+

The function below organizes work with the desired symbol stored in the symbol variable, if you need to work with another symbol - write it there. Function FillArrays() just fills arrays.

//+------------------------------------------------------------------+
void WorkOnTick(string sy, double symbol_bid, datetime symbol_time, int limit) {
   long chart_id=get.GetChartID(sy);                       
   int index_symbol=get.PositionsSymbolInList(sy);       // позиция символа в списке
   double pt=SymbolInfoDouble(sy,SYMBOL_POINT);
   double pa=SymbolInfoDouble(sy,SYMBOL_ASK);
   double pb=SymbolInfoDouble(sy,SYMBOL_BID);
   int stoplevel=(int)MarketInfo(sy,MODE_STOPLEVEL);
   int dg=(int)SymbolInfoInteger(sy,SYMBOL_DIGITS);
   //--- заполним массивы
   FillArrays(sy,symbol_bid,symbol_time,table_price,table_time);
   //--- расчёт среднего изменения цен тиков
   double avg_change_price=AverageChangePrice(index_symbol,limit,slowPeriod,table_price);
   //--- вывод информации на график
   wtf(index_symbol,avg_change_price,slowPeriod,table_price,table_time);
   return;   
   
   Trailing(sy, 50, 3, magic);
}
//+------------------------------------------------------------------+

I needed to fill the arrays with ticks this way:

//+------------------------------------------------------------------+
void FillArrays(string sy, double price, datetime time, double &mass_price[][], datetime &mass_time[][]) {
   //--- сместим данные в массивах влево
   int index_symbol=get.PositionsSymbolInList(sy);       // позиция символа в списке
   for(int i=99; i>0; i--) {                             // сместим данные в массивах влево
      mass_price[index_symbol][i]=mass_price[index_symbol][i-1];
      mass_time[index_symbol][i]=mass_time[index_symbol][i-1];
      }
   //--- запишем товый тик в массивы
   mass_price[index_symbol][0]=price;
   mass_time[index_symbol][0]=time;
}
//+------------------------------------------------------------------+
 
Artyom Trishkin:

I don't get it - the SIZE is zero, so why change the size of the array first and then increase the SIZE? What a mess...

I once did an array filling with ticks for a ticking advisor, which determines the intensity and spread of ticks. I've cut out pieces for examples:

The function below organizes work with the desired symbol stored in the symbol variable, if you need to work with another symbol - write it there. Function FillArrays() just fills arrays.

I needed to fill the arrays with ticks this way:

I need an average rate of 1 tick/in 1 sec in n - ticks. I.e. n-ticks are received in k-seconds, k/n are received in ticks per second. This speed must be measured on each tick arriving. It will change with each subsequent tick.

 

Can you tell me if there is a clock in mt4? Preferably with a second hand.

or maybe there is an Expert Advisor that would display the time somewhere in the bottom line of the terminal

Reason: