CopyBuffer() getting wrong in dynamic array with SetIndexBuffer() !!! - page 2

 
Vladimir Karputov #:
I am a correct example for you - an example that is correctly formatted. Study my example, study the documentation (especially carefully read what a timeseries array is, what happens when you bind an array using 'INDICATOR_DATA') /

I don't know if it's a translation problem, but I didn't find the answer.  

as I understand it,  bind an array using 'INDICATOR_DATA',  will not ArrayResize() it ,and it's size will according bars count.

Could you please tell me where the document can be explained  when I bind an array using 'INDICATOR_DATA' ?  Thanks.
 
Yu Zhang #:

I don't know if it's a translation problem, but I didn't find the answer.  

as I understand it,  bind an array using 'INDICATOR_DATA',  will not ArrayResize() it ,and it's size will according bars count.

Could you please tell me where the document can be explained  when I bind an array using 'INDICATOR_DATA' ?  Thanks.

Indicator Styles in Examples

The difference between an indicator buffer and an array

In each indicator, on its global level, you should declare one or more arrays of the double type, which then must be used as an indicator buffer using the SetIndexBuffer() function. To draw indicator plots, only the values ​​of the indicator buffers are used, any other arrays cannot be used for this purpose. In addition, buffer values are displayed in the Data Window.

An indicator buffer should be dynamic and does not require specification of the size – the size of the array used as the indicator buffer is set by the terminal execution subsystem automatically.

After the array is bound to the indicator buffer, the indexing direction is set by default like in ordinary arrays, but you can use the ArraySetAsSeries() function to change the way of access to the array elements. By default, the indicator buffer is used to store data used for plotting (INDICATOR_DATA).

If the calculation of indicator values requires holding intermediate calculations and storing the additional values for each bar, then such an array can be declared as a calculation buffer during binding (INDICATOR_CALCULATIONS). For the intermediate values, you can also use a regular array, but in this case, the programmer has to manage the size of the array.

Some plots allow setting a color for each bar. To store the information about color, color buffers are used (INDICATOR_COLOR_INDEX). The color is an integer type color, but all indicator buffers must be of type double. Values of color and auxiliary (INDICATOR_CALCULATIONS) buffers cannot be obtained by using CopyBuffer().


SetIndexBuffer()

The function binds a specified indicator buffer with one-dimensional dynamic array of the double type.

***

Note

After binding, the dynamic array buffer[] will be indexed as in common arrays, even if the indexing of timeseries is pre-installed for the bound array. If you want to change the order of access to elements of the indicator array, use the ArraySetAsSeries() function after binding the array using the SetIndexBuffer() function. Please note that you can't change the size for dynamic arrays set as indicator buffers by the function SetIndexBuffer(). For indicator buffers, all operations of size changes are performed by the executing sub-system of the terminal.

Documentation on MQL5: Custom Indicators / Indicator Styles in Examples
Documentation on MQL5: Custom Indicators / Indicator Styles in Examples
  • www.mql5.com
Indicator Styles in Examples - Custom Indicators - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Vladimir Karputov #:

An example of an indicator - the indicator receives data from three iMAs and displays this data in three buffers:  Three MA Arrow

I studied the example you gave me,

and change:

CopyBuffer(handle, 0, -shift, 100, Buffer0); // -shift means it get all the indicator
// changed to --> 
CopyBuffer(handle, 0, 0, 100, Buffer0);

The result is the same with me.

 
Vladimir Karputov #:

Indicator Styles in Examples

The difference between an indicator buffer and an array

In each indicator, on its global level, you should declare one or more arrays of the double type, which then must be used as an indicator buffer using the SetIndexBuffer() function. To draw indicator plots, only the values ​​of the indicator buffers are used, any other arrays cannot be used for this purpose. In addition, buffer values are displayed in the Data Window.

An indicator buffer should be dynamic and does not require specification of the size – the size of the array used as the indicator buffer is set by the terminal execution subsystem automatically.

After the array is bound to the indicator buffer, the indexing direction is set by default like in ordinary arrays, but you can use the ArraySetAsSeries() function to change the way of access to the array elements. By default, the indicator buffer is used to store data used for plotting (INDICATOR_DATA).

If the calculation of indicator values requires holding intermediate calculations and storing the additional values for each bar, then such an array can be declared as a calculation buffer during binding (INDICATOR_CALCULATIONS). For the intermediate values, you can also use a regular array, but in this case, the programmer has to manage the size of the array.

Some plots allow setting a color for each bar. To store the information about color, color buffers are used (INDICATOR_COLOR_INDEX). The color is an integer type color, but all indicator buffers must be of type double. Values of color and auxiliary (INDICATOR_CALCULATIONS) buffers cannot be obtained by using CopyBuffer().


SetIndexBuffer()

The function binds a specified indicator buffer with one-dimensional dynamic array of the double type.

***

Note

After binding, the dynamic array buffer[] will be indexed as in common arrays, even if the indexing of timeseries is pre-installed for the bound array. If you want to change the order of access to elements of the indicator array, use the ArraySetAsSeries() function after binding the array using the SetIndexBuffer() function. Please note that you can't change the size for dynamic arrays set as indicator buffers by the function SetIndexBuffer(). For indicator buffers, all operations of size changes are performed by the executing sub-system of the terminal.

Thanks for your share.

I've read these, but they don't show the relationship between "shift, start_pos, and INDICATOR_DATA".

I worked out the relationship on my own.  They are much more complicated than " shift, start_pos, and Array".

"buffer to buffer" is different to "buffer to array". 

Now I know why it is result.

Thank you very much.

 
The authors of MQ5 are masters at complicating simple things and making our lives difficult, reading 400 lines of code 800 lines of documentation another 400 of examples just to copy 3 indicators into buffers and display them :)