Does Metatrader allows to put all indicator buffers into single two-dimensional Array ?

 

Hello,

I am interesting if I could declare two dimensional array, and then put all indicators to this array.

For examle:

BUFF[8][]; //two dimesional array

SetIndexBuffer(0,BUFF[1][]);

SetIndexBuffer(1,BUFF[2][]);
SetIndexBuffer(2,BUFF[3][]);
SetIndexBuffer(3,BUFF[4][]);
SetIndexBuffer(4,BUFF[5][]);
SetIndexBuffer(5,BUFF[6][]);
SetIndexBuffer(6,BUFF[7][]);

SetIndexBuffer(7,BUFF[8][]);

//first dimesion for different indicators, second dimesion as usuall

I tried this way, but indicators does not appear.

If anyone tried this way ?

Edas

 

not possible

SetIndexBuffer(x, SomeArray) will also do an implicit ArraySetAsSeries() and this changes the actual memory location of the array. SomeArray will (internally) not point to where it used to point before, it will now point to a place in memory that is managed by MT4 and this place will not be inside your original array anymore.

Technically behind the scenes you don't make it use your array from now on, instead this will re-bind the variable name to its own location where the buffer has been all the time, it is in reality not a setter, it is a getter, something like GetIndexBufferAddress(int buffer_number, double*& buffer_address) and after this call SomeArray points to the indicator buffer (and not the indicator buffer to SomeArray).


I am surprised that the compiler does not completely refuse to compile your code at all, since there is no place for it to put the new address, a 2d array is internally not represented as an array of pointers to arrays, its an array of arrays.

 

It would be an interesting experiment to do the following:


double foo[];
double baz[];


int init(){
SetIndexBuffer(0, foo);
SetIndexBuffer(0, baz);

both should now be pointing to the same index buffer, foo and baz should now be different names for the same identical array and changes to foo should be visible in baz. I don't have my MT4 running at the moment to confirm it, maybe it works, maybe they did take precautions against that and restore foo to what it was before during the second call to SetIndexBuffer().

 

Thank you, 7bit.

I will then work with indicator buffers as usually.