Errors, bugs, questions - page 465

 
uncleVic:
Write to the CD about this too. Like "not everything in the review can be chosen in the tester".
Nah, no backing out. I have two terminals open - Alpari, and MK, and switched back and forth, but in the latter I forgot to add EURGBP to the market overview.
 
marketeer:
Nah, rebound. I have two terminals open - Alpari, and MK, and switched back and forth, but in the latter I forgot to add EURGBP to the market overview.
It happens.
 

I'm trying to create an array in the script that behaves like an indicator series. Namely, when a new entry appears, the whole array is shifted back and the new entry is made to a null position.

void OnStart()
  {
   int a[];
   int size=5;               // размер массива
   bool flag=true;           // флаг направления индексации
   ArraySetAsSeries(a,flag);  // зададим направление индексации
   ArrayResize(a,size);      // зададим размер массива
//---
   for(int i=0;i<size;i++)  // задаём значения и распечатываем массив
      a[i]=size-i;         // 54321
   Print("[",a[0],"][",a[1],"][",a[2],"][",a[3],"][",a[4],"]");
//---
   ArrayResize(a,size-1);     // уменьшаем размер 5432
   ArraySetAsSeries(a,!flag);  // меняем направление индексации 2345
   ArrayResize(a,size);       // возвращаем в исходный размер  2345х
   ArraySetAsSeries(a,flag);   // возвращаем в исходную индексацию х5432   
   a[0]=6;                   // задаём "пустому" нулевому данному значение
//---
   Print("[",a[0],"][",a[1],"][",a[2],"][",a[3],"][",a[4],"]");
   // в результате получаем 64321 вместо нужного 65432
  }

As they say, why?

Maybe I got it wrong, but it's the first thing that springs to mind - another bug in language optimization.

HZZY I also ask those folks who want to shift data using loops not to bother. This works fine for arrays of 5...100...1000..., but will not work for bigger arrays.

 
Urain:

I'm trying to create an array in the script that behaves like an indicator series. Namely, when a new entry appears, the whole array is shifted back and the new entry is made to a null position.

As they say why?


What if we take the class CArrayInt and use an insert to shove data into it?
 
uncleVic:
And if we take class CArrayInt, and inserts there data?

I would like to be able to pass the array via parameters, while the array itself is private in the class.

Again, as far as I remember, this method is engaged in shifting the data in the loop, and it's pretty slow.

 
Urain:

I'm trying to create an array in the script that behaves like an indicator series. Namely, when a new entry appears, the whole array is shifted back and the new entry is made to a null position.

As they say, why?

Maybe I got it wrong, but it's the first thing that springs to mind - another bug in language optimization.

HZZY I also ask those folks who want to shift data using loops not to bother. This works fine for arrays of 5...100...1000..., but will not work for bigger arrays.


On the subject of "ZZZY": won't your resizes fray your memory?
 
uncleVic:
As for "ZZI": your resizes don't fragment memory for you?

I don't know any other function (that allocates memory) in mql5.

HH And as far as I understood the direction of the array is also purely a virtual thing.

ZZY Apparently you have to work not with memory, but with address space virtualization. And this also slows down the work, direct access is faster after all.

 
Urain:

I'd like to be able to pass the array via parameters, while the array itself is private in the class.

Again, as far as I remember, this method is just for shifting data in a loop and that's pretty slow.

I'll have to think about improving the array classes (for me).
 
uncleVic:
I would have to think about improving array classes (for me).

Yes, a virtual insert on a zero position would be nice. But not to really move the data, otherwise it would be long and inefficient.

Anyway, it's bad that you can't work with memory directly, it has good virtualization acceleration, even C++ speed is 1.5 times faster if you address a cell address instead of an array.

 
Urain:

I'm trying to create an array in the script that behaves like an indicator series. That is, when a new entry appears, the entire array is shifted back, and the new entry is made at the zero position.

ZZZY I ask comrades who want to advise to move data by the cycle not to worry, this option works well for arrays of 5...100...1000..., but at the larger size array is unacceptable.


But may I suggest not to move the entire array? :)

Dynamic array, new data is written to the end, size is changed/memorized, and AsSeries flag changes only indexation.

For normal order, it is N element of array, for "serial" Size-N-1.

Документация по MQL5: Основы языка / Типы данных / Объект динамического массива
Документация по MQL5: Основы языка / Типы данных / Объект динамического массива
  • www.mql5.com
Основы языка / Типы данных / Объект динамического массива - Документация по MQL5
Reason: