Learn to use the debugger and how to deal with errors:
https://www.mql5.com/en/articles/654
https://www.mql5.com/en/articles/2041
This way you can find your errors yourself.
- www.mql5.com
Hello.
I am trying to learn coding for 3 months. I have read many many articles and sample codes. I tried to write a multicurrency indicator. When i try to use it, i get the "array out of range" error on H4 timeframe. I have read a lot of "array out of range" explanation on this forum but i can not solve the problem (because i am a beginner). Because of this error, i can not use this indicator in EA either. I kindly ask you to help me. Best regards.
Learn to use the debugger and how to deal with errors:
https://www.mql5.com/en/articles/654
https://www.mql5.com/en/articles/2041
This way you can find your errors yourself.
You have not specified at which line the array out of range error is occurring, so we can only guess, but I do see several lines where there are problems, namely:
Buffer[rates_total-1]
The above would fail if "rates_total" were zero, and this can happen at the beginning when the indicator does not yet have any data ready. Always check for that condition first:
// OnCalculate event handler int OnCalculate( const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[] ) { // Make sure we have rates data if( rates_total < 1 ) return 0; // Other logic ... // Return value of prev_calculated for next call return rates_total; };
Learn to use the debugger and how to deal with errors:
https://www.mql5.com/en/articles/654
https://www.mql5.com/en/articles/2041
This way you can find your errors yourself.
Hello again.
...
Hello,
The first step to find the source of the problem,
- I suggest that you first check it by 'Print()' the contents of the variable that I highlighted in yellow.
- Once you know their contents, I'm sure you can continue solving the problem.
Print("limit: ",limit," | rates_total: ",rates_total," | prev_calculated: ",prev_calculated); for(int i=limit;i<rates_total;i++) {
Because I suspect this code is asking for an unavailable sequence of array numbers.
topsqrxBuffer[i]=sqrxBuffer[i]+sqrxBuffer[i-1]+sqrxBuffer[i-2]+sqrxBuffer[i-3]+sqrxBuffer[i-4]+sqrxBuffer[i-5]+sqrxBuffer[i-6]+sqrxBuffer[i-7]+sqrxBuffer[i-8]+sqrxBuffer[i-9]+sqrxBuffer[i-10]; topxyBuffer[i]=xyBuffer[i]+xyBuffer[i-1]+xyBuffer[i-2]+xyBuffer[i-3]+xyBuffer[i-4]+xyBuffer[i-5]+xyBuffer[i-6]+xyBuffer[i-7]+xyBuffer[i-8]+xyBuffer[i-9]+xyBuffer[i-10];
Good luck.
Had the same issue writing an indicator.
Solution was :
#property indicator_buffers >> total number of ANY ARRAY<<
You are using 11 arrays in your indicator, so the total number of indicator buffers has to be 11 and
you need to set the index for each :
SetIndexBuffer(number,name,data...calc...etc);
.
You do not need to increment the indicator plots, if you do not need more than 1.
Increment the indicator buffers count, if you need to add a new array and -of course- set a new index for each new array.
For your indicator :
#property indicator_buffers 11 // ... // and add : SetIndexBuffer(9,tm1,INDICATOR_CALCULATIONS); SetIndexBuffer(10,tm2,INDICATOR_CALCULATIONS); //That´s it. :o)
This should solve it.
Good luck !
oli
double valx[1]; double valy[1]; ⋮ SetIndexBuffer(1,valx,INDICATOR_CALCULATIONS); SetIndexBuffer(2,valy,INDICATOR_CALCULATIONS);
Note
After binding, the dynamic array buffer[]
Those are not dynamic arrays.
- 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.
I am trying to learn coding for 3 months. I have read many many articles and sample codes. I tried to write a multicurrency indicator. When i try to use it, i get the "array out of range" error on H4 timeframe. I have read a lot of "array out of range" explanation on this forum but i can not solve the problem (because i am a beginner). Because of this error, i can not use this indicator in EA either.
Error occurs with the line that begins " topsgrxBuffer[i] = sqrxBuffer[i]+...... ".
I kindly ask you to help me. Best regards.