Hello, a simple problem here, if you are an expert you will find this problem within seconds....my indicator always gets error "Array out of range" when trying to test it. I just dont know why...
tried everything from resizing array, setasseries, change beginning condition of "for" loop to j=1, and also trying to give the array a constant size when defining it. Help is appreciated!
logEURUSD[i]=log(closePricesEURUSD[i]); // HERE IT SAYS OUT OF ARRAY
i is varying between j and j+100 (excluded)
j is varying between 0 and rates_total-100 (excluded)
so i is from 0 to rates_total-1 (excluded)
but your array closePricesEURUSD[] is at best of size rates_total-100, so from 0 to rates_total-100 (excluded) :
CopyClose(NULL,timeFrame,0,rates_total-100,closePricesEURUSD);
When i is >= rates_total-100 you get an "array out of range".
You should also check returned value of CopyClose().
i is varying between j and j+100 (excluded)
j is varying between 0 and rates_total-100 (excluded)
so i is from 0 to rates_total-1 (excluded)
but your array closePricesEURUSD[] is at best of size rates_total-100, so from 0 to rates_total-100 (excluded) :
When i is >= rates_total-100 you get an "array out of range".
You should also check returned value of CopyClose().
thank you, I already changed this beforehand because my initial boundaries were also not working. I fixed it now to this:
CopyClose(NULL,timeFrame,0,rates_total,closePricesEURUSD); for(int j=0; j<=rates_total-n; j++) { for(int i=j; i<j+n-1; i++) { logEURUSD[i]=log(closePricesEURUSD[i]);
so now i goes from 0 to rates_total-1, and my CopyClose array should be large enough but still I get the error "array out of range". Also I Printed the values for each close price closePricesEURUSD[0], closePricesEURUSD[1] and closePricesEURUSD[2], and they never change, always constant, I thought they are re-calculated on a new bar? Or is array element [0] the close price of the oldest bar in the history? I thought [0] is the actual bar.
Try set closePricesEURUSD and closePricesGBPUSD into the indicator buffer, and check for i to be less than the length of closePricesEURUSD and closePricesGBPUSD arrays.
what do you mean by set closePricesEURUSD into the indicator buffer ? I think you mean I should add the array in global scope and adjust the number of #property indicator_buffers,
I tried that, but still array out of range. I also printed the maximum values for j and i, and the value or rates_total, and i is always smaller than length of the array closePricesEURUSD , as you can see here my Print:
2017.04.26 21:17:53.045 2016.02.01 01:01:38 rates_total: 80049 , array size: 80049 j max= 79950, i max= 80048
thank you, I already changed this beforehand because my initial boundaries were also not working. I fixed it now to this:
so now i goes from 0 to rates_total-1, and my CopyClose array should be large enough but still I get the error "array out of range". Also I Printed the values for each close price closePricesEURUSD[0], closePricesEURUSD[1] and closePricesEURUSD[2], and they never change, always constant, I thought they are re-calculated on a new bar? Or is array element [0] the close price of the oldest bar in the history? I thought [0] is the actual bar.
Forum on trading, automated trading systems and testing trading strategies
Indicator, Array out of range (tried everything...)
Alain Verleyen, 2017.04.26 20:27
logEURUSD[i]=log(closePricesEURUSD[i]); // HERE IT SAYS OUT OF ARRAY
i is varying between j and j+100 (excluded)
j is varying between 0 and rates_total-100 (excluded)
so i is from 0 to rates_total-1 (excluded)
but your array closePricesEURUSD[] is at best of size rates_total-100, so from 0 to rates_total-100 (excluded) :
CopyClose(NULL,timeFrame,0,rates_total-100,closePricesEURUSD);
When i is >= rates_total-100 you get an "array out of range".
You should also check returned value of CopyClose().
I added a check for the returned value, it returns the rates_total value, so everythign is okay but the error is still there. So I made it easier to find the error, by deleting the two for-loops and just use on single line:
double closePricesEURUSD[]; if(CopyClose(NULL,timeFrame,0,rates_total,closePricesEURUSD) < rates_total ) { ArrayResize(closePricesEURUSD,rates_total,0); } logEURUSD[0]=log(closePricesEURUSD[0]); // --> this line causes error "array out of range"
problem solved...I added ArrayResize(logEURUSD,rates_total);
now it works. If someone knows why this is necessary and why the array is not automatically adjusted to fit the size of the array closePricesEURUSD[] then please tell me, otherwise thank you all for helping me out!
problem solved...I added ArrayResize(logEURUSD,rates_total);
now it works. If someone knows why this is necessary and why the array is not automatically adjusted to fit the size of the array closePricesEURUSD[] then please tell me, otherwise thank you all for helping me out!
CopyClose(NULL,timeFrame,0,rates_total-100,closePricesEURUSD); CopyClose(currency2,timeFrame,0,rates_total-100,closePricesGBPUSD); : logEURUSD[i]=log(closePricesEURUSD[i]); // HERE IT SAYS OUT OF ARRAY logGBPUSD[i]=log(closePricesGBPUSD[i]);
If timeFrame isn't the current chart period, this fails. rates_total is the current chart.
If currency2 isn't the current chart, this fails. rates_total is the current chart
You are mixing apples and oranges.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello, a simple problem here, if you are an expert you will find this problem within seconds....my indicator always gets error "Array out of range" when trying to test it. I just dont know why...
tried everything from resizing array, setasseries, change beginning condition of "for" loop to j=1, and also trying to give the array a constant size when defining it. Help is appreciated!