"volume[1]" is accessing the 2nd array element, given that array indexing starts at 0. So what would happen if the "rates_total" was less than 2?
It would give "array out of range" error. So always check that the "rates_total" is equal or greater than the number of elements you need to process.
if( rates_total >= 2 ) { Print( volume[ 1 ] ); };
"volume[1]" is accessing the 2nd array element, given that array indexing starts at 0. So what would happen if the "rates_total" was less than 2?
It would give "array out of range" error. So always check that the "rates_total" is equal or greater than the number of elements you need to process.
Although the snippet itself didn't solve my issue but was enough as a pointer for me. I logged some Print() statements and can see the size of 'volumes[]' array and 'prev_calculated' variable is ZERO. I can tackle it with a similar `if` condition but wondering why is it so?
"volume[1]" is accessing the 2nd array element, given that array indexing starts at 0. So what would happen if the "rates_total" was less than 2?
It would give "array out of range" error. So always check that the "rates_total" is equal or greater than the number of elements you need to process.
I updated the condition to the below and it doesn't print anything now. Can you guide me what is the issue with it?
if(rates_total > prev_calculated && ArraySize(volume) > 1) { Print("rates_total:", rates_total, " prev_calculated:", prev_calculated, " Array:", ArraySize(volume)); Print(volume[1]); }
I replaced 'volume[1]' with "iVolume(0,0,1)" in my original snippet and it works.
But my original question is still there. Why 'volume[]' array is empty always?
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
This is a very simple practice indicator, with minimal code. I drag it to BTCUSD 15m chart and I get "array out of range" error. Why is it so and what is the workaround?