-
Don't post pictures of code, they are too hard to read.
-
for(i=limit; i >=0; i--){ ⋮ MALast= varMA[i+nb_0];
When IndicatorCounted is zero, limit is Bars-1. I plus anything is beyond limit and array exceeded. - Fill your array and then Do your lookbacks correctly.
-
You should stop using the old event handlers and IndicatorCounted() and start using new event handlers.
Event Handling Functions - MQL4 Reference
How to do your lookbacks correctly - MQL4 programming forum #9-14 & #19 2016.05.11
-
Don't post pictures of code, they are too hard to read.
- When IndicatorCounted is zero, limit is Bars-1. I plus anything is beyond limit and array exceeded.
- Fill your array and then Do your lookbacks correctly.
-
You should stop using the old event handlers and IndicatorCounted() and start using new event handlers.
Event Handling Functions - MQL4 Reference
How to do your lookbacks correctly - MQL4 programming forum #9-14 & #19 2016.05.11
i changed this
limit = Bars-counted_bars-1; to
limit = Bars-counted_bars;
but still array error. what is wrong? thanks
i changed this
#property strict #property indicator_chart_window #property indicator_buffers 2 input int ma_per = 10; input int ma_met = 3; input color col_ang = clrYellow; input int ExtDepth = 21; input int ext = 0; input int Complect = 0; double varMA[], value[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int BarReduction=0; int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,varMA); SetIndexStyle(0,DRAW_NONE,EMPTY,EMPTY,clrNONE); SetIndexBuffer(1,value); SetIndexStyle(1,DRAW_NONE,EMPTY,EMPTY,clrNONE); BarReduction=(int)MathMax(ExtDepth,ma_per)+1; //--- 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 limit=rates_total-prev_calculated-BarReduction; double MALast, MACurr; for(int i=limit; i>=0; i--) { varMA[i]=iMA(NULL,0,ma_per,0,ma_met,PRICE_CLOSE,i); int nb_0=GetZZbar(ext); //if zzbar exists if(nb_0>-1) { MALast= varMA[i+nb_0]; MACurr= varMA[i+1]; if(ObjectFind("AngleA "+IntegerToString(Complect))<0) { ObjectCreate("AngleA "+IntegerToString(Complect),OBJ_TRENDBYANGLE,0,Time[i+nb_0],MALast,Time[i+1],MACurr); ObjectSet("AngleA "+IntegerToString(Complect),OBJPROP_STYLE,2); } if (ObjectFind("AngleText "+IntegerToString(Complect))==-1) ObjectCreate("AngleText "+IntegerToString(Complect),OBJ_TEXT,0,0,0); ObjectSet("AngleA "+IntegerToString(Complect),OBJPROP_TIME2,Time[i+1]); ObjectSet("AngleA "+IntegerToString(Complect),OBJPROP_PRICE2,MACurr); ObjectSet("AngleA "+IntegerToString(Complect),OBJPROP_TIME1,Time[i+nb_0]); ObjectSet("AngleA "+IntegerToString(Complect),OBJPROP_PRICE1,MALast); ObjectSet("AngleA "+IntegerToString(Complect),OBJPROP_COLOR,col_ang); value[i] = (double)ObjectGet("AngleA "+IntegerToString(Complect),OBJPROP_ANGLE); if(value[i]>90) value[i] = value[i]-360; value[i+1] = value[i]; ObjectSetText("AngleText "+IntegerToString(Complect),DoubleToStr(value[i],2),8,"Verdana",col_ang); ObjectMove("AngleText "+IntegerToString(Complect),0,Time[0]+8*Period()*60,ObjectGetValueByShift("AngleA "+IntegerToString(Complect),i)); } //if zzbar exists ends here } //--- return value of prev_calculated for next call return(rates_total); } int GetZZbar(int ne=0) { double zz; int j, k=iBars(NULL, 0), ke=0; for (j =1; j <k; j++) { zz=iCustom(NULL, 0, "ZigZag", ExtDepth,5,3, 0,j); if (zz !=0) { ke++; if (ke > ne) return(j); } } return(-1); }
You have to check if the nb_0 bar exists (not -1) before you proceed with calculations .
What was happening : your loop reached 0 (i=0) and if GetZZbar returned -1 then you were requesting
Time[i+nb_0] //Time[-1] MALast= varMA[i+nb_0] //varMA[-1]
i have a angle checking mql4 source but it have array out of range error.
i can't figure out what is problem.
i can guess problem is come from loop but can't fix error.
i did several modification like i+1 or so where possibly can fix error but no lucky.
i guessing error come around here
MALast= varMA[i+nb_0];
anyone help me much appreciate!!