Errors, bugs, questions - page 269

 
AndrNuda:
You guys are so slow :) Falls aren't fals, but everything works. You're looking in the wrong place. )))) There is a correct function.
Smart?
 
BoraBo:

I'm trying to figure out why ArrayIsSeries(High) is always false

The help for this function says(https://www.mql5.com/ru/docs/array/arrayisseries)

Return value

Returns true if the array being checked is a timeseries array, otherwise returns false. Arrays passed as a parameter to OnCalculate() should be checked for the order in which the elements of the array are accessed with ArrayGetAsSeries().

The array you declared is not a timeseries and cannot become one under any circumstances. Timeseries are arrays that are predefined by the runtime system, for example in the OnCalculate() function:

int OnCalculate (const int rates_total,      // размер входных таймсерий
                 const int prev_calculated,  // обработано баров на предыдущем вызове
                 const datetime& time[],     // Time
                 const double& open[],       // Open
                 const double& high[],       // High
                 const double& low[],        // Low
                 const double& close[],      // Close
                 const long& tick_volume[],  // Tick Volume
                 const long& volume[],       // Real Volume
                 const int& spread[]         // Spread
   )
Документация по MQL5: Операции с массивами / ArrayIsSeries
Документация по MQL5: Операции с массивами / ArrayIsSeries
  • www.mql5.com
Операции с массивами / ArrayIsSeries - Документация по MQL5
 
Rosh:

The help for this function says(https://www.mql5.com/ru/docs/array/arrayisseries)

The array you declared is not a timeseries and cannot become one under any circumstances. Timeseries are runtime predefined arrays, for example in the OnCalculate() function:

ArrayGetAsSeries does not work as intended.
 
AlexSTAL:
ArrayGetAsSeries does not work as intended.
The ArrayGetAsSeries function only changes the indexing direction, but does not turn the array into a timeseries. What are you trying to get with this function?
 
Rosh:
Timeseries are runtime predefined arrays, e.g. in OnCalculate():
int OnCalculate (const int rates_total,      // размер входных таймсерий
                 const int prev_calculated,  // обработано баров на предыдущем вызове
                 const datetime& time[],     // Time
                 const double& open[],       // Open
                 const double& high[],       // High
                 const double& low[],        // Low
                 const double& close[],      // Close
                 const long& tick_volume[],  // Tick Volume
                 const long& volume[],       // Real Volume
                 const int& spread[]         // Spread
   )


What about this is written in the help:

Примечание

Для проверки массива на принадлежность к таймсерии следует применять функцию ArrayIsSeries(). Массивы ценовых данных, переданных в качестве входных параметров в функцию OnCalculate(), не обязательно имеют направление индексации как у таймсерий. Нужное направление индексации можно установить функцией ArraySetAsSeries().

 
joo:

What about this is written in the help:


Run such an indicator and you will see for yourself:

//+------------------------------------------------------------------+
//|                                           CheckArrayIsSeries.mq5 |
//|                      Copyright © 2009, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
//---- plot Label1
#property indicator_label1  "Label1"
#property indicator_type1   DRAW_LINE
#property indicator_color1  Red
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- indicator buffers
double         Label1Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,Label1Buffer,INDICATOR_DATA);
//---
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void checkArray(const double & array[])
  {
   if(ArrayGetAsSeries(array))
     {
      Print("array can use as timeseria");
     }
     else
     {
      Print("array can not use as timeseria!!!");
     }
     
  }
//+------------------------------------------------------------------+
//| 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[])
  {
//---
   if(ArrayIsSeries(open))
     {
      Print("open[] is timeseria");
      checkArray(open);
     }
   else
     {
        {
         Print("open[] is timeseria!!!");
        }
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
Rosh:
The ArrayGetAsSeries function only changes the indexing direction, but does not turn an array into a timeseries. What are you trying to get with this function?

This function checks the direction, not the change.

1) Without initialisation

double Buf[];
void OnStart()
  {
   ArrayResize(Buf, 3);

   Print("ArrayGetAsSeries(Buf): ", ArrayGetAsSeries(Buf));             // ArrayGetAsSeries(Buf): false
   
   // Меняем направление на обратный порядок
   Print("Установка в true прошла: ", ArraySetAsSeries(Buf, true));     // Установка в true прошла: true
   Print("ArrayGetAsSeries(Buf): ", ArrayGetAsSeries(Buf));             // ArrayGetAsSeries(Buf): false
   
   // Меняем направление на прямой порядок
   Print("Установка в false прошла: ", ArraySetAsSeries(Buf, false));   // Установка в false прошла: true
   Print("ArrayGetAsSeries(Buf): ", ArrayGetAsSeries(Buf));             // ArrayGetAsSeries(Buf): false
  }

2) With initialization

double Buf[];
void OnStart()
  {
   ArrayResize(Buf, 3);
   Buf[0] = 0; Buf[1] = 1; Buf[2] = 2;

   Print("ArrayGetAsSeries(Buf): ", ArrayGetAsSeries(Buf));             // ArrayGetAsSeries(Buf): false
   
   // Меняем направление на обратный порядок
   Print("Установка в true прошла: ", ArraySetAsSeries(Buf, true));     // Установка в true прошла: true
   Print("ArrayGetAsSeries(Buf): ", ArrayGetAsSeries(Buf), " [", Buf[0], ",", Buf[1], ",", Buf[2], "]"); // ArrayGetAsSeries(Buf): true [2,1,0]
   
   // Меняем направление на прямой порядок
   Print("Установка в false прошла: ", ArraySetAsSeries(Buf, false));   // Установка в false прошла: true
   Print("ArrayGetAsSeries(Buf): ", ArrayGetAsSeries(Buf), " [", Buf[0], ",", Buf[1], ",", Buf[2], "]"); // ArrayGetAsSeries(Buf): false [0,1,2]
  }

3) The code above, only with the ArrayGetAsSeries function obtaining the array indexing direction

double High[];
#include <Indicators\TimeSeries.mqh>
void OnStart()
  {
   Print("ArrayGetAsSeries(High) ",ArrayGetAsSeries(High));                   // ArrayGetAsSeries(High) false

   CiHigh z;

   int count=3;
   if(z.Create(_Symbol,_Period)==true)
     {
      if(z.GetData(0,count,High)==count)
        {
         for(int i=0; i<count; i++) Print(i,"=",High[i]);
         Print("ArraySetAsSeries(High,true) ",ArraySetAsSeries(High,true));   // ArraySetAsSeries(High,true) true
         Print("ArrayGetAsSeries(High) true = ",ArrayGetAsSeries(High));      // ArrayGetAsSeries(High) true = false
         for(int i=0; i<count; i++) Print(i,"=",High[i]);
         Print("ArraySetAsSeries(High,false) ",ArraySetAsSeries(High,false)); // ArraySetAsSeries(High,false) true
         Print("ArrayGetAsSeries(High) false = ",ArrayGetAsSeries(High));     // ArrayGetAsSeries(High) false = false
         for(int i=0; i<count; i++) Print(i,"=",High[i]);
        }
      else
         Print("Не удалось получить ",count," данных таймсерии.");
     }
   else Print("Ошибка создания таймсерии.");
   Print("ArrayGetAsSeries(High) ",ArrayGetAsSeries(High));                   // ArrayGetAsSeries(High) false
   Print("GetLastError() ",GetLastError());
  }
In the service-desk I got the function name wrong just


 
Rosh:

Run such an indicator and you will see for yourself:

It's understandable. And my question was not about errors, everything works as written in the help:

Примечание

Для проверки массива на принадлежность к таймсерии следует применять функцию ArrayIsSeries(). Массивы ценовых данных, переданных в качестве входных параметров в функцию OnCalculate(), не обязательно имеют направление индексации как у таймсерий. Нужное направление индексации можно установить функцией ArraySetAsSeries().


The question arose because of the discrepancy between the colour and bold highlighted in the help and what you said:

Rosh:
Timeseries are runtime predefined arrays, for example in OnCalculate():

That's why I do this in OnCalculate():

    //--------------------------------------
    if (ArrayGetAsSeries(time)!=true)
      ArraySetAsSeries(time,true);
    if (ArrayGetAsSeries(open)!=true)
      ArraySetAsSeries(open,true);
    if (ArrayGetAsSeries(high)!=true)
      ArraySetAsSeries(high,true);
    if (ArrayGetAsSeries(low)!=true)
      ArraySetAsSeries(low,true);
    if (ArrayGetAsSeries(close)!=true)
      ArraySetAsSeries(close,true);
    //--------------------------------------
 
Rosh:

The help for this function says(https://www.mql5.com/ru/docs/array/arrayisseries)

The array you declared is not a timeseries and cannot become one under any circumstances. Timeseries are predefined arrays, for example in the OnCalculate() function:

The check does not work in the indicator either.

//+------------------------------------------------------------------+
//|                                                    ind_proba.mq5 |
//|                        Copyright 2010, MetaQuotes Software Corp. |
//|                                              https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2010, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_separate_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping

//---
   return(0);
  }
//+------------------------------------------------------------------+
//| 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[])
  {
//---
   int count=3;
   int i=0;
   int limit;
//   bool printCom;

   if(prev_calculated>0)
     {
      limit=1;
     }
   else
     {
      Print("rates_total  ",rates_total,"  prev_calculated  ",prev_calculated);
      for(i=0; i<count; i++) Print(i,"=",open[i]);
      Print("ArraySetAsSeries(open,true) ",ArraySetAsSeries(open,true));
      Print("ArrayIsSeries(open) true = ",ArrayIsSeries(open));
      Print("ArrayGetAsSeries(open) true = ",ArrayGetAsSeries(open));
      for(i=0; i<count; i++) Print(i,"=",open[i]);
      Print("ArraySetAsSeries(open,false) ",ArraySetAsSeries(open,false));
      Print("ArrayIsSeries(open) false = ",ArrayIsSeries(open));
      Print("ArrayGetAsSeries(open) false = ",ArrayGetAsSeries(open));
      for(i=0; i<count; i++) Print(i,"=",open[i]);
     }
   Print("GetLastError() ",GetLastError());
//--- return value of prev_calculated for next call

   return(rates_total);
  }
//+------------------------------------------------------------------+

Also,prev_calculated doesn't work any more, it's always 0:

 

Yes, I think with these functions, they have already sorted themselves out.


But as a wish, so that I don't forget - in the editor, when prompted after typing three or how many characters, when you click up standing on the first line of the list is not removed from the list. Just used to so already as in the studio, I think that many will be "annoyed" if not done in the same way as in the studio. IMHO.