yea i understund what you tell but , my case is different i know that array start the count 0 to end and i if i
create Array [2] ,resize it, and with(WindowFirstVisibleBar()
+ 5)and cicle for insert inside of array with for(int i=WindowFirstVisibleBar(); i>=0; i--) , i aspect the
script runn good , but return the same2020.05.15 23:19:13.116 candle-body-size USDCHF,H1: array
out of range in 'candle-body-size.mq4' (60,29) example if WindowFirstVisibleBar()
is equal = 100 and i resize in 105 , if for start to 0 or 1 for me is no problem i have 5 position plus
Sorry, english is not my first language, so I don't quite get what you don't understand.
Basics are simple:
if you use static arrays, you must use constant to declare the size, compiler won't accept variables
if you use dynamic arrays, you must make sure that you do correct ArrayResize()
see Alain's comment on resizing static arrays - it's undocumented, but it seems to work. Since it's undocumented it might stop working
in some future version.
In any case, you can use as much array elements as you declared. No more.
Again, array elements are indexed from 0 to n-1, where n is number of elements.
Finally:
"Array out of range" means you are trying to access array element beyond the array end.
When you get this error, you have a bug in your code - you have a wrong idea about the size of the array and you didn't properly resize your
array.
Use debugger and/or print out variables.
Your case is not different. There is no any other "special" situation where you can get "Array out of range".
. In a particular case of a one-dimensional array of 50 elements, calling of the first element will appear as array[0], of the last one - as array[49]. What's new in MQL5 Added functions for quick insertion, deletion, copying and expanding array elements. The new ArraySwap() function swaps the contents of two dynamic arrays of the...
sorry but i continue to not undesrtund i can create static array double array[10] or dinamic array double array[] but after with dinamic i must resize with arrayresize(array,1000),
now i correct the script with dinamic array but return me the same problem
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
You cannot resize an array that was created static. You can only resize a dynamic array. ArrayResize() has a return value, check it to detect errors.
Actually you can
Actually you can
Interesting to know. It's somewhat contradicting the mql reference:
Note
The function can be applied only to dynamic arrays.
yea i understund what you tell but , my case is different i know that array start the count 0 to end and i if i create Array [2] ,resize it, and with(WindowFirstVisibleBar() + 5)and cicle for insert inside of array with for(int i=WindowFirstVisibleBar(); i>=0; i--) , i aspect the script runn good , but return the same2020.05.15 23:19:13.116 candle-body-size USDCHF,H1: array out of range in 'candle-body-size.mq4' (60,29)
example if WindowFirstVisibleBar() is equal = 100 and i resize in 105 , if for start to 0 or 1 for me is no problem i have 5 position plus
Sorry, english is not my first language, so I don't quite get what you don't understand.
Basics are simple:
Finally:
Useful links:
read all about Array functions.
use ArraySize() function and print out actual array size before you try to access array elements. Make sure that you resized your array correctly.
Interesting to know. It's somewhat contradicting the mql reference:
Note
The function can be applied only to dynamic arrays.
I know, I can't say it has always be like that, but it is at least for the last 6 years. And it will not change because MT4/mql4 is "frozen".
sorry but i continue to not undesrtund i can create static array double array[10] or dinamic array double array[] but after with dinamic i must resize with arrayresize(array,1000),
now i correct the script with dinamic array but return me the same problem
the problem is not resize because the print after resize return me this
2020.05.17 21:50:41.781 candle-body-size USDCHF,H1: visiblebar 653 dimention array 658
now if i do a for with WindowFirstVisibleBar and is 653 if i have array of 658 why go in dimention excide?????
the for do only 653 cicle and arry is 658 how is possible??
i find a problem is allert
//Alert("Plus ", aBodyCount[i]," pt.");