syrvn 0:
Hello!
is there a quick and nice way to get the index of the last element in an array or the index of the first empty value?
One way of course would be the use of an index variable but maybe there is a better way.
I also tried ArraySize but I initialize my Arrays at the beginning with a size of i.e. 10 and even though the array still does not contain any values, ArraySize returns 10 and not 0 or NULL.
Any ideas?
A dynamic array will give you the total count of elements through a single method call.
https://www.mql5.com/en/docs/standardlibrary/datastructures/carray/carraytotal
For fixed arrays, I know of no "nice easy" way. Maybe loop backwards from the end or remember the value as you suggested.

Documentation on MQL5: Standard Library / Data Collections / CArray / Total
- www.mql5.com
Standard Library / Data Collections / CArray / Total - Reference on algorithmic/automated trading language for MetaTrader 5

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello!
is there a quick and nice way to get the index of the last element in an array or the index of the first empty value?
One way of course would be the use of an index variable but maybe there is a better way.
I also tried ArraySize but I initialize my Arrays at the beginning with a size of i.e. 10 and even though the array still does not contain any values, ArraySize returns 10 and not 0 or NULL.
Any ideas?