Download MetaTrader 5

Shifting arrays & Filling arrays

To add comments, please log in or register
Proximus
766
Proximus  

Hi i`m curious how the MT4 handles the shifting of the arrays after each tick.And here i`m mostly interested in the Volume[] Array.

My question is that what algoritm shifts back the entire array by 1 element after each new data (in our case tick and/or time for a bar to close relative to timeframe).

I wish to know that algoritm if anyone can describe it to me, the shortest method to achieve this.

Here i will illustrate it in a picture

So basically every new unit of the array is shifted back 1 place to its previous one's place, and if the array has reached its maximum size, then the last ones will be discarded from the array.

In case of the Volume[] array, the close volume of the timeframe is our period when new data comes and shifts the old one's place.

Alain Verleyen
Moderator
33505
Alain Verleyen  
Proximus:

Hi i`m curious how the MT4 handles the shifting of the arrays after each tick.And here i`m mostly interested in the Volume[] Array.

My question is that what algoritm shifts back the entire array by 1 element after each new data (in our case tick and/or time for a bar to close relative to timeframe).

I wish to know that algoritm if anyone can describe it to me, the shortest method to achieve this.

Here i will illustrate it in a picture

So basically every new unit of the array is shifted back 1 place to its previous one's place, and if the array has reached its maximum size, then the last ones will be discarded from the array.

In case of the Volume[] array, the close volume of the timeframe is our period when new data comes and shifts the old one's place.

You can't really know how it's managed unless by doing an analysis of the memory usage, which it's not worth the effort.

Why are you asking ?

Ian Venner
2584
Ian Venner  
I think it is probably done by re-index the array in reverse, add a new element to the end then reverse the indexing back again.
Proximus
766
Proximus  
angevoyageur:

You can't really know how it's managed unless by doing an analysis of the memory usage, which it's not worth the effort.

Why are you asking ?



I`m asking it because i would like to build an indicator which logs volumes, but not by timeframe but by count.It would be like the renko bars, but instead of logging the price, i would log the volume, and for this i need to build my own array of volumes in this manner, since the Volume[] array segmented by timeframe not by count.

And of course i would need it in reverse order, since the Start() is capable of logging in the other direction only.So i guess i need to use the ArrayCopy() aswell.

Alain Verleyen
Moderator
33505
Alain Verleyen  
Proximus:

I`m asking it because i would like to build an indicator which logs volumes, but not by timeframe but by count.It would be like the renko bars, but instead of logging the price, i would log the volume, and for this i need to build my own array of volumes in this manner, since the Volume[] array segmented by timeframe not by count.

And of course i would need it in reverse order, since the Start() is capable of logging in the other direction only.So i guess i need to use the ArrayCopy() aswell.

I think best solution is the save time with volume, and build your array from that.
Proximus
766
Proximus  
angevoyageur:
I think best solution is the save time with volume, and build your array from that.

Yup, do you think i can reverse the array with ArrayCopy(), because i have already reversed it with for(), but with ArrayCopy it could be done in 1 line.
whroeder1
16112
whroeder1  
SDC: I think it is probably done by re-index the array in reverse, add a new element to the end then reverse the indexing back again.
See my ResizeBuffer No moving of elements.
Alain Verleyen
Moderator
33505
Alain Verleyen  
WHRoeder:
See my ResizeBuffer No moving of elements.

Your code doesn't compile
whroeder1
16112
whroeder1  
angevoyageur: Your code doesn't compile
Left as an exersize for the reader
Tomas Gracias
343
Tomas Gracias  

Hi,

I am not sure if my question belongs here but let me try it.

I have 2 dimensional array. I store pair names here. e.g.

pairs [4][5] = AUDUSD

this array has many empty values e.g.

pairs [2][3] is empty

I would like to reindex the array so each array index has a value.

Is that possible?

Thanks?

nicholishen
947
nicholishen  
Tomas Gracias:

Hi,

I am not sure if my question belongs here but let me try it.

I have 2 dimensional array. I store pair names here. e.g.

pairs [4][5] = AUDUSD

this array has many empty values e.g.

pairs [2][3] is empty

I would like to reindex the array so each array index has a value.

Is that possible?

Thanks?


Tomas,

It sounds to me like you should be using objects and collections (eg. CList) instead of multidimensional arrays. 

12
To add comments, please log in or register