[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 524

 

Thank you. That helped. Thought it was only the iMac*** iStoch*** indicators that came preinstalled.

 
Lisi4ka330:

Dear experts, isn't there an error in the textbook?

Here is my reasoning:

At the beginning of the code,int ArrayCopyRates function is called which copies the data of the bars of the current chart into a two-dimensional array of RateInfo[][6] type and returns the number of copied bars or -1 in case of failure according to the example of this function:

the current bar is the bar with index 0-0 , thus, returning to the original code, we copy the element with index 0-0 (the current bar) of array1 , to array2 with index 0-0, we get the last 10 bars (where the last bar is the current bar, the one with index [0]), which is contrary to what we wrote in the tutorial... and respectively, by copying element with index Bars*6-60,60 of array1 into array2 with start index of element 0 we get information about bars from history.


Without making loud statements, let's check it in practice:

//+------------------------------------------------------------------+
//|                                                       массив.mq4 |
//|                                                  Copyright 2012, |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012,"
#property link      "https://forum.mql4.com/ru/46980/page525"
#property show_inputs
extern string s=" -----номер бара--------";
extern int a=9;//номер 10 последних баров 
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
{if(a<10)
{double array1[][6];double array2[10][6];
  ArrayCopyRates(array1);
  ArrayCopy(array2,array1,0,Bars*6-60,60);
// теперь array2 содержит 10 последних баров из истории(имеется в виду,что последний бар-это текущий бар,бар с индексом [0])
Alert("Контрольный бар - ",a," время - ",TimeToStr(array2[a][0]),"  цена открытия - ",array2[a][1]);}return(0);}
 
Roll:


Without making high-profile claims, let's put it to the test:

Yes, in practice it does indeed turn out that the element with index Bars*6-60,60 is the current bar... then how do you explain that in the example :

double array1[][6];
ArrayCopyRates(array1,"EURUSD", PERIOD_H1);
Print("Текущий бар ",TimeToStr(array1[0][0]),"цена открытия ", array1[0][1]);
The current bar is array1[0][0] and after copying the array it becomes array1[Bars*6-60,60][0]... it turns out that somewhere there is renumbering... Of course, the result is clear after using the function in practice... but the logic is messed up, in my opinion)))
 
Lisi4ka330:

Yes, in practice it does turn out that the element with index Bars*6-60,60 is the current bar ...


This is your conclusion.
 
Roll:


Without making high-profile claims, let's put it to the test:

#property show_inputs
extern string s=" -----номер бара--------";
extern int a=9;//номер 10 последних баров 
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
{if(a<10)
{double array1[][6];double array2[10][6];
  ArrayCopyRates(array1);
  ArrayCopy(array2,array1,0,Bars*6-60,60);
// теперь array2 содержит 10 последних баров из истории(имеется в виду,что последний бар-это текущий бар,бар с индексом [0])
Alert("Контрольный бар - ",a," время - ",TimeToStr(array2[a][0]),"  цена открытия - ",array2[a][1]);}return(0);}

So here is a specific element of theTimeToStr(array2[a][0]) array.

That the output is correct, I agree. But what does Bars*6-60 have to do with it? What value is substituted for Bar during calculation? If bars, how do you get the last 10 bars?

You may notice, I am not the only one who did not understand this on the forum, but many people did.

It turns out that the number of all bars multiplied by 6 and minus 60. Where did we get 6 from ? It doesn't make any sense at all.

 
hoz:

So here is a specific element of theTimeToStr(array2[a][0]) array.

The output is correct, I agree. But what does Bars*6-60 have to do... What value is substituted for Bar during calculation? If bars, how do you get the last 10 bars?

As you may notice, I'm not the only one who hasn't understood it on the forum, many others haven't.



int Bars -- Number of bars on the current chart.

 
hoz:

It turns out that the number of all bars multiplied by 6 and minus 60. Where did we get 6 from? It doesn't make any sense at all.

MQL4 Reference - Array Operations - ArrayCopyRates
 
Roll:



int Bars -- Number of bars on the current chart.


Well, where did the last 10 come from then?

int Bars = 10 000;

Then Bars*6 - 60 = 10 000*6 - 60 = 60 000 - 60 = 59 960;

The value of59 960 is greater than the value of Bars. And it already means that it is outside the array. And 10 is nowhere to be traced...

 
hoz:

It turns out that the number of all bars multiplied by 6 and minus 60. Where did we get 6 from? It doesn't make any sense at all.

To avoid aggravating the confusion, I want to correct the mistake I made in the previous answer: the notation "array1[Bars*6-60,60][0]" is not correct, because Bars*6 is the total number of elements in array1.Each bar has 6 properties, let's assume we have 30 bars, multiplying by 6 we get the number of elements in the first array - 180. The second array has only 60 free "cells" (i.e. 10 x 6 properties), so we must select only 60 elements from the first array to copy. By expressing [Bars*6-60,60] we subtract 60 from the total, i.e. 180 - 60 = 120, i.e. 120 elements of the first array will be written to zero-element of the second, 121 to the first, and so on. Another question is how it turns out that information about the last formed bars is written not at the beginning of the first array, but at the end ... But apparently the answer lies in the function code, and there's no point in digging any deeper...
 
hoz:


Well, where did the last 10 come from then?

int Bars = 10,000;

Then Bars*6 - 60 = 10 000*6 - 60 = 60 000 - 60 = 59 960 -- error!!!

The value of59 960 is greater than the value of Bars. And this already means that it has gone beyond the array's limits. And 10 is nowhere to be seen.


Victor, don't worry, you'll get there. "Experience is the son of hard mistakes..." Go from the simple to the complex, not the other way around:

"PROGRESS (from lat. progressus - movement forward), a direction of development characterized by a transition from the inferior to the superior, from the less perfect to the more perfect. Progress can be spoken of in relation to the system as a whole, its individual elements, the structure of the developing object. The concept of progress is the opposite of the concept of regress.

REGRESS (from Latin regressus - reverse movement), the type of development, which is characterized by the transition from higher to lower. The opposite of progress."

Reason: