EDIT: Here is the fix thanks to Johnvanwijk! -> https://www.forexfactory.com/showthr...9#post10791049
Hey guys,
So I've been trying to draw some stuff however it's giving me the error "Array out of range".
It draws the green arrows perfectly however the red arrows just won't work.
If someone could tell me what I'm doing wrong it would be great.
It's not because I'm trying to access candles that aren't there yet or at all as far as I know.
I get that some people might say that it's going past available bars but I have tested even with a limit of 1000 which I'm sure my chart has and it still gives me out of range.
This is the code:
Thanks!
Hey guys,
So I've been trying to draw some stuff however it's giving me the error "Array out of range".
It draws the green arrows perfectly however the red arrows just won't work.
If someone could tell me what I'm doing wrong it would be great.
It's not because I'm trying to access candles that aren't there yet or at all as far as I know.
I get that some people might say that it's going past available bars but I have tested even with a limit of 1000 which I'm sure my chart has and it still gives me out of range.
This is the code:
Inserted Code
//+------------------------------------------------------------------+ //| FractalsExercise.mq4 | //| AntiVi | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "AntiVi" #property link "https://www.mql5.com" #property version "1.00" #property strict #property indicator_chart_window double Highs[]; double Lows[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- drawing style SetIndexStyle(0, DRAW_ARROW, EMPTY, 1, clrGreen); SetIndexArrow(0, 234); SetIndexStyle(1, DRAW_ARROW, EMPTY, 1, clrRed); SetIndexArrow(1, 233); //--- indicator buffers SetIndexBuffer(0, Highs); SetIndexBuffer(1, Lows); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ 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[]) { //--- int i = 1; int ii = 1; int Limit = Bars - 1; while(i < Limit) { if(High[i] > High[i + 1]) { if(High[i] > High[i - 1]) { Highs[i] = High[i]; } } i++; } while(ii < Limit) { if(Low[ii] < Low[ii + 1]) { if(Low[ii] < Low[ii - 1]) { Lows[ii] = Low[ii]; } } ii++; } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+
Thanks!