Array out of range
Hello everyone! I am new to MQL4. Would love to have some help. I am trying to create an indicator and getting "Array out of range" on the code below for "var[1]". Would anyone know why?
You have to size the array
you mean add a number here:
double var[SIZE_HERE]; for(int i=0; i<rates_total; i++) { var[i]=Close[i]; }
I was wishing to use rates_total. If I understood right, that would include all candles on chart. But still get "'[' - invalid index value" error with that.
- No, because you don't know what the maximum of rates_total will be, you can't declare a constant size.
- Perhaps you should read the manual.
ArrayResize The function sets a new size for the first dimension
ArrayResize - Array Functions - MQL4 Reference - Why are you trying to use an array in an indicator. Use a buffer and it will be automatically resized for you.
As I understood, arrays would work like this on the chart:
https://pasteboard.co/IdNeOhR.png
So I wanted to be able to work using the second-last value from a line (array) in order to create the last value from another one.
Thank you guys very much for the help!
-
Please use the link button
See the difference? https://pasteboard.co/IdNeOhR.png
Messages Editor - Please don't post a link to or attach an image, just insert the image.
Messages EditorThat is supposed to mean something?
- Axel D: So I wanted to be able to work using the second-last value from a line (array) in order to create the last value from another one.That sounds like gibberish to me. Only the "last value" can create the "last value."

Hello everyone! I am new to MQL4. Would love to have some help. I am trying to create an indicator and getting "Array out of range" on the code below for "var[1]". Would anyone know why?
Any help would be very much appreciated!
Best regards!