how can i fix array error in mql4 source?

how can i fix array error in mql4 source?

Manage alerts

Loading saved threads...

jeon · External communityPost link
External question — Stack Overflow Stack Exchange Author: jeon Original post: https://stackoverflow.com/questions/63048910 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. I have a angle checking mql4 source but it have array out of range error. I can't figure out what is the problem. I can guess the problem comes from a loop but can't fix the error. I did several modifications like i+1 or so where possibly can fix the error but to no success. I'm guessing the error comes from here: MALast= varMA[i+nb_0]; anyone enlighten me much appreciate #property indicator_chart_window #property indicator_color1 CLR_NONE #property indicator_buffers 3 #property indicator_color2 CLR_NONE extern int ma_per = 10; extern int ma_met = 3; extern color col_ang = clrYellow; extern int ExtDepth = 21; extern int ext = 0; extern int Complect = 0; double varMA[], value[]; //------------------------------------------------------------------------- int init() { IndicatorBuffers(3); IndicatorDigits(Digits+1); SetIndexBuffer(0,varMA); SetIndexStyle(0,DRAW_LINE); SetIndexBuffer(1, value); return(0); } //------------------------------------------------------------------------- int deinit() { ObjectDelete("AngleA "+Complect); ObjectDelete("AngleText "+Complect); Comment(""); return(0); } //------------------------------------------------------------------------- int start() { int i, limit, counted_bars=IndicatorCounted(); limit = Bars-counted_bars-1; if(counted_bars<0) return(-1); if(counted_bars>0) counted_bars--; double MALast, MACurr; for(i=limit; i >=0; i--) { varMA[i] = iMA(NULL,0,ma_per,0,ma_met,PRICE_CLOSE,i); int nb_0 = GetZZbar(ext); MALast= varMA[i+nb_0]; MACurr= varMA[i+1]; if (ObjectFind("AngleA "+Complect)<0) { ObjectCreate("AngleA "+Complect,OBJ_TRENDBYANGLE,0,Time[i+nb_0],MALast,Time[i+1],MACurr); ObjectSet("AngleA "+Complect,OBJPROP_STYLE,2); } if (ObjectFind("AngleText "+Complect)==-1) ObjectCreate("AngleText "+Complect,OBJ_TEXT,0,0,0); ObjectSet("AngleA "+Complect,OBJPROP_TIME2,Time[i+1]); ObjectSet("AngleA "+Complect,OBJPROP_PRICE2,MACurr); ObjectSet("AngleA "+Complect,OBJPROP_TIME1,Time[i+nb_0]); ObjectSet("AngleA "+Complect,OBJPROP_PRICE1,MALast); ObjectSet("AngleA "+Complect,OBJPROP_COLOR,col_ang); value[i] = (double)ObjectGet("AngleA "+Complect,OBJPROP_ANGLE); if(value[i]>90) value[i] = value[i]-360; value[i+1] = value[i]; ObjectSetText("AngleText "+Complect,DoubleToStr(value[i],2),8,"Verdana",col_ang); ObjectMove("AngleText "+Complect,0,Time[0]+8*Period()*60,ObjectGetValueByShift("AngleA "+Complect,i)); } Comment(value[0]); return(0); } //------------------------------------------------------------------------- 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); } //-------------------------------------------------------------------------
Quote
Report

Post Reply

Checking account access…