"ArraySize and ArrayRange not returning what I expected"
Change your expectations.
"The first time the start() function is called, the value returned by ArraySize and ArrayRange is 56017 NOT 0 as expected."
The indicator index array size is the same as the number of bars in the chart.
On the first call to start() I can assume the first empty location is at index zero(0). But, what about subsequent calls to start()? What is the best way to determine the next empty (EMPTY_VALUE) location? I'm thinking that I can use static variables but is this the best way to do it?
Also, do the size of the arrays remain constant on subsequent calls?
Thanks
On the first call to start() I can assume the first empty location is at index zero(0)
If you have not written anything into the array during init(), yes, it is "empty"
But, what about subsequent calls to start()?
You are in control, ask yourself that question. What did you code?
What is the best way to determine the next empty (EMPTY_VALUE) location?
I'm thinking that I can use static variables but is this the best way to do it?
...enough
The index arrays are managed by MT4. When you get a new bar, the array gets a new
location at index 0. All values
currently in the array are shifted up one location. For example, a value in index
4 is moved to index 5 when a new
bar comes.
I have no idea what you are trying to do or why you think you need to use the index buffers to do it.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I'm trying the determine the index of the next available (blank) location in one of the buffers (ExtMap_Indicator) created for me automatically in a custom indicator. The first time the start() function is called, the value returned by ArraySize and ArrayRange is 56017 NOT 0 as expected. I've written the first 10 values contained in the buffer and all are 2147483647 which is 0x7FFFFFFF the default EMPTY_VALUE. I can implement my own linear search for 2147483647 in order to determine the index of the next unwritten location. However, this seems inefficient and ArraySize and ArrayRange should work. Following is a code snippet from my indicator. Any adivise would be greatly appreciated.
Next_Elem = ArraySize(ExtMap_Indicator);
FileWrite(dbg_handle,"Next_Size, Next_Range = ", ArraySize(ExtMap_Indicator), " ", ArrayRange(ExtMap_Indicator,0));
Next_Size, Next_Range = ;56017; ;56017
for (indx=0; indx<11; indx++)
FileWrite(dbg_handle,"ExtMap_Indicator, indx = ", ExtMap_Indicator[indx], " ", indx);
ExtMap_Indicator, indx = ;2147483647; ;0
ExtMap_Indicator, indx = ;2147483647; ;1
ExtMap_Indicator, indx = ;2147483647; ;2
ExtMap_Indicator, indx = ;2147483647; ;3
ExtMap_Indicator, indx = ;2147483647; ;4
ExtMap_Indicator, indx = ;2147483647; ;5
ExtMap_Indicator, indx = ;2147483647; ;6
ExtMap_Indicator, indx = ;2147483647; ;7
ExtMap_Indicator, indx = ;2147483647; ;8
ExtMap_Indicator, indx = ;2147483647; ;9
ExtMap_Indicator, indx = ;2147483647; ;10