funny lines in Time interval indicator MQL5 New comment Nima J 2022.01.18 17:07 Hello Guys! I am making a time interval indicator. My indicator gets starting and end time as input. It will first get the High and Low value of 30min time frame. and it will draw a line in that time span with some calculation with iATR of each day but sometimes in doesn't work correctly. like in the picture that I attach This happens almost every time the current time is in the time interval. here is the picture and the code 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[]) { //--- if(BarsCalculated(ma)<=0){ ma = iATR(Symbol(),PERIOD_D1,10); return(0); } for(int i=prev_calculated+10; i<rates_total-1; i++){ dayBarIndex = iBarShift(Symbol(),PERIOD_D1,time[i],true); MqlDateTime today,candleDay; TimeToStruct(TimeCurrent(),today); TimeToStruct(time[i],candleDay); if(today.year == candleDay.year && today.mon == candleDay.mon && today.day == candleDay.day){ if(today.hour<= openRangeStart){ break; } } if(dayBarIndex>=0){ int atrcheck = CopyBuffer(ma,0,iTime(Symbol(),PERIOD_D1,dayBarIndex),1,myAtr); if(atrcheck > 0){ rangeBarIndex = iBarShift(Symbol(),PERIOD_M30,iTime(Symbol(),PERIOD_D1,dayBarIndex)+(60*60*openRangeStart),true); if(rangeBarIndex>=0){ highL = iHigh(Symbol(),PERIOD_M30,rangeBarIndex); lowL = iLow(Symbol(),PERIOD_M30,rangeBarIndex); MqlDateTime rangeTime; TimeToStruct(time[i],rangeTime); if(rangeTime.hour>= openRangeStart && rangeTime.hour<=endRange){ line0[i] = highL + (myAtr[0]*0.10); //Orhigh line1[i] = lowL - (myAtr[0]*0.10); //orlow }else{ line0[i] = EMPTY_VALUE; line1[i] = EMPTY_VALUE; } } } } } return(rates_total); } Files: Untitled.png 16 kb Time interval indicators lines extends to zero at beginning and ending of the time interval Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes Help Creating MTF Previous Bar Indicator MQL5 William Roeder 2022.01.18 17:15 #1 ayBarIndex = iBarShift(Symbol(),PERIOD_D1,time[i],true);Except when the time[i] is the begging of the day, your call fails (returns -1). Nima J 2022.01.19 12:36 #2 William Roeder #: Except when the time[i] is the begging of the day, your call fails (returns -1). thanks a lot, that was the point I was missing out. New comment
Hello Guys!
I am making a time interval indicator.
My indicator gets starting and end time as input. It will first get the High and Low value of 30min time frame.
and it will draw a line in that time span with some calculation with iATR of each day
but sometimes in doesn't work correctly. like in the picture that I attach
This happens almost every time the current time is in the time interval.
here is the picture and the code