This indicator is supposed to simply display two horizontal lines at high/low of specified time range each day. As soon as I load it on a chart, it locks MT4. I took an existing indi I wrote that displays horizontal lines at support/resistance to make this indi, the original one works no problem. Very little was changed. Can anyone see what's wrong here?
This line . . .
if ((TimeCurrent() >= StartTime) && (Bar > 0))
. . . prevents the LineNumber variable incrementing past 6 so that it is always less than LinesToDraw (10) . . . the result is an infinite loop.
This line . . .
. . . prevents the LineNumber variable incrementing past 6 so that it is always less than LinesToDraw (10) . . . the result is an infinite loop.
Thanks ... I just spotted the logic flaw. The two lines that decrement StartTime and EndTime by one day should not be within that "if" statement block. If the start HH and MM specified was later than the current date's time (meaning don't draw lines for today yet), it never got into that block to decrement the start/end time so looped infinitely. Must've been daydreaming to miss that! Here's what it should look like:
while (LineNumber <= LinesToDraw) { Bar = iBarShift(NULL,0,StartTime,true); if ((TimeCurrent() >= StartTime) && (Bar > 0)) { DrawLine(LineName+LineNumber+"High",Bar,iBarShift(NULL,0,EndTime,false),High[Bar],HighColor); DrawLine(LineName+LineNumber+"Low",Bar,iBarShift(NULL,0,EndTime,false),Low[Bar],LowColor); LineNumber++; } StartTime -= SecondsInDay; EndTime -= SecondsInDay; if (Time[Bars -1] > StartTime) break; }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
This indicator is supposed to simply display two horizontal lines at high/low of the bar designated by StartHH and StartMM each day. As soon as I load it on a chart, it locks MT4. I took an existing indi I wrote that displays horizontal lines at support/resistance to make this indi, the original one works no problem. Very little was changed. Can anyone see what's wrong here?