Array out of range in Need of help - page 7

 
Valeriy Yastremskiy:

The daily extrema, and what you are finding are essentially extrema, lows (or highs) have quite long distances from the current price. The difference between the low and the high on the 132 days on the eve is more than 12300 pips. Price from the nearest low of 2000, from the high of 800.

I don't get it either.

Sorry, I will try to explain tomorrow tired today

 
MakarFX:

AUDUSD is not like that for me

ArrayCopyRates(Bar_data_D1,_Symbol,PERIOD_D1); // Копирует в массив данные баров указанного графика и возвращает количество скопированных баров

What does it copy and return to where?

 
Алексей Тарабанов:

What is being copied where and to whom?

Alexei Tarabanov:

What does it copy to and return to?

of calling this function:

intArrayCopyRates(
MqlRates&rates_array[],// array of MqlRates passed by reference
stringsymbol=NULL,// the tool
inttimeframe=0// timeframe
);

Copies data of the specified chart bars into a two-dimensional array of the form double RateInfo[][6] and returns the number of copied bars.

intArrayCopyRates(
void&dest_array[][],// array passed by reference
stringsymbol=NULL,// tool
inttimeframe=0// timeframe
);

Parameters

ArrayCopyRates

When using the second form of call, data is actually copied into array dest_array[][], the array itself is automatically reallocated to match the timeframe size (even if the array has been declared static).

The first dimension of the array contains the number of bars. The second dimension has 6 elements with the values:

0 - time (time),
1 - open price (open),
2 - lowest price (low),
3 - highest price (high),
4 - close price (close),

Документация по MQL5: Основы языка / Функции / Вызов функции
Документация по MQL5: Основы языка / Функции / Вызов функции
  • www.mql5.com
Если некоторое имя, которое не было описано ранее, появляется в выражении и за ним следует левая круглая скобка, то оно по контексту считается именем некоторой функции. Аргументы (формальные параметры) передаются по значению, т. е. каждое выражение x1, . . . , xn вычисляется и значение передается функции. Порядок вычисления выражений и порядок...
 
Dark Kchlyzov:
of calling this function:

intArrayCopyRates(
MqlRates&rates_array[],// array of MqlRates passed by reference
stringsymbol=NULL,// the tool
inttimeframe=0// timeframe
);

Copies data of the specified chart bars into a two-dimensional array of the form double RateInfo[][6] and returns the number of copied bars.

intArrayCopyRates(
void&dest_array[][],// array passed by reference
stringsymbol=NULL,// tool
inttimeframe=0// timeframe
);

Parameters

ArrayCopyRates

When using the second form of call, data is actually copied into array dest_array[][], the array itself is automatically reallocated to match the timeframe size (even if the array has been declared static).

The first dimension of the array contains the number of bars. The second dimension has 6 elements with the values:

0 - time (time),
1 - open price (open),
2 - lowest price (low),
3 - highest price (high),
4 - close price (close),

And where is the returned value of the int-type saved? You passed all the data to the function, but didn't get anything from it.

 
Алексей Тарабанов:

Where is the return value of int type saved? You passed all the data into the function, but didn't get anything out of it.

Min_D_Level = iLow(_Symbol,PERIOD_D1,i); break;

It seems to be stored here

double Min_D_Level ; //nearest Minimal D-level

or I do not understand something ?

And where is the returned value of int type saved?

???

I am really brainstorming.

Is it possible to do it in a simpler way?

Like you (you) made a mistake here, the right way to do it is this code example, etc.

 

Been sitting here for a while:

#property version   "1.00"
#property strict

//символ и таймфрейм текущего графика
string symbol;
ENUM_TIMEFRAMES frame;
datetime time;
   

struct BarData
   {
   struct Elem
      {
      int      number;     //порядковый номер периода (дня, месяца или года)
      double   high;       //максимум периода
      double   low;        //минимум периода
      datetime time_high;  //время максимума
      datetime time_low;   //время минимума
      } Arr[];             //массив периода
   int index;              //текущий индекс массива
   double   max;           //последнее максимальное значение периода
   double   min;           //последнее минимальное значение периода
   datetime time_max;      //время максимума
   datetime time_min;      //время минимума

   //при создании структуры указываем, что массив пустой
   BarData(){index=-1;}    
   
   //функция записывает текущие экстремумы
   void WriteBar(int eNumber, string eSymbol, ENUM_TIMEFRAMES eFrame, datetime eTime)
      {
      int eShift=iBarShift(eSymbol,eFrame,eTime);
      double eHigh=iHigh(eSymbol,eFrame,eShift);
      double eLow=iLow(eSymbol,eFrame,eShift);
      //если элементов ещё нет или период сменился
      if(index<0 || eNumber!=Arr[index].number)
         {
         ArrayResize(Arr,++index+1);
         Arr[index].number=eNumber;
         Arr[index].high=eHigh;
         Arr[index].low=eLow;
         Arr[index].time_high=eTime;
         Arr[index].time_low=eTime;
         }
      //если произошло обновление текущего максимума
      if(eHigh-Arr[index].high>0)
         {
         Arr[index].high=eHigh;
         Arr[index].time_high=eTime;
         }
      //если произошло обновление текущего минимума
      if(Arr[index].low-eLow>0)
         {
         Arr[index].low=eLow;
         Arr[index].time_low=eTime;
         }
      //если произошло обновление предыдущего максимума
      if(eHigh-max>0)
         {
         for(int i=index+1; i>=0; i--)
            {
            if(Arr[index].high-eHigh>0)
               {
               max=Arr[index].high;
               time_max=Arr[index].time_high;
               break;
               }
            }
         }
      //если произошло обновление предыдущего минимума
      if(min-eLow>0)
         {
         for(int i=index+1; i>=0; i--)
            {
            if(eLow-Arr[index].low>0)
               {
               min=Arr[index].low;
               time_min=Arr[index].time_low;
               break;
               }
            }
         }
      }
   } day, month, year;

int OnInit()
   {
   symbol=Symbol();
   frame=(ENUM_TIMEFRAMES)Period();
   return(INIT_SUCCEEDED);
   }

void OnTick()
   {
   //текущее время закрытого бара
   time=iTime(symbol,frame,1);
   
   MqlDateTime date; 
   TimeToStruct(time,date);
   
   //делаем записи каждого периода
   day.WriteBar(date.day,symbol,frame,time);
   month.WriteBar(date.mon,symbol,frame,time);
   year.WriteBar(date.year,symbol,frame,time);
   
   //теперь имеем значения   
   Comment(TimeToString(day.time_max)+" : "+DoubleToString(day.max)+" : "+DoubleToString(day.Arr[day.index].high)+"\n"+TimeToString(day.time_min)+" : "+DoubleToString(day.Arr[day.index].low)+" : "+DoubleToString(day.min));
   }
We should try to avoid unnecessary cycles. We have a lot of quotes coming in, and you need to make the right entries on the fly, so that you don't have to dig through history and waste computer resources.
 
Dark Kchlyzov:

Sort of like this

double Min_D_Level ; //nearest min D level

Or am I missing something ?

Yes, you do not understand something. It should go like this:

Количество_баров=ArrayCopyRates(Bar_data_D1,_Symbol,PERIOD_D1); // Копирует в массив данные баров указанного графика и возвращает количество скопированных баров

And then...

 
Алексей Тарабанов:

Yes, there's something you don't understand. That's the way it has to be:

And then...

Thank you very much!

 
Dark Kchlyzov:

Thank you very much on that one too !!!

You're very welcome.

 

3.47 I'm going to bed.

I'll digest it all tomorrow and if I have any questions I'll let you know !

Thanks a lot everyone !!!

Reason: