Is it not necessary to SetIndexEmptyValue ?

 
int ArrayInitialize( double&array[], double value) 

Sets all elements of a numeric array to the same value. Returns the count of initialized elements.
Note: It is not recommended to initialize index buffers in the custom indicator init() function as such functions are initialized automatically with an "empty value" at allocation and re-allocation of buffers

=========

The above is from MQL4 Book.

1) Here "functions" should be buffers,right?

2) Because index buffers are initialized autimatically in the init() section, so SetIndexEmptyValue(0,0) is not necessary?

 

Variables (including Arrays (including Index Buffers)) STORE things (data allocation). Functions DO things (usually to data) and/or return a value.

Index Buffers are 'special' Arrays, that get reallocated for each new bar that's created. As new entries get created, they are initialised with EMPTY_VALUE (unless SetIndexEmptyValue is used)

So ...

1) You are correct, (but perhaps some might say that index buffers are a 'special case' as it is as though functions are called as each new entry is created)

2) You are incorrect, and perhaps confusing 2 concepts.

SetIndexBuffer(N, MyArrayIndexBuffer)

is what signals an array as the 'special case' Index Buffer. It will be extended/re-allocated automatically for each new bar, and by default each new entry will be initialed with EMPTY_VALUE (which is not the same 0)

The default behaviour is like doing SetIndexEmptyValue(N, EMPTY_VALUE) for N = 0 to 7.

If you really want the default initial value of each new entry of index buffer 0 to be 0, then you should put SetIndexEmptyValue(0, 0) in the init() function.

HTH

 
In init, the buffers have not yet been allocated, you can't use ArrayInitialize there. In start the buffers have been resized and initialized to SETIndexEmptyValue specified or defaulted.
 

Very clear explaination.

Thanks to brewmanz and WHRoeder

Thank you very much!