Hi
i'm currently trying to debug a MT5 indicator that randomly freezes the platform. I have to force the close then reopen it (i tried to wait for a long time to see if it gets its hand back but it didn't happen)
it freezes when i click "ok" after modifying some parameters. It doesn't matter which parameter i change.
To debug it, i have to be able to reproduce the error consistently, which i have not been able to do.
i tried starting from a smaller code and adding some parts but sometimes i click and change parameters for 20 minutes and nothing happens. Then another change and it freezes
this is really frustrating and i don't know how to go from there.
some help would be welcome
thanks a lot
Jeff
Your indicator is bugged. It's hard to help you without the code.
Your indicator is bugged. It's hard to help you without the code.
well that could be one reason, but i'm quite an experienced programmer and this is the first time i see something like that. granted i know MT5 a little bit less than MT4 but it is quite similar.
unfortunately the code is too big to share it here.
But is there a way to debug random events ?
i tried logging the Init function, but the logging mechanism is delayed so nothing is written on screen before the crash
i think writing on disk would be the same ? i need to find where the error comes from but as it is random i'm not sure i can.
thanks for help
ok so i wrote data to file to see where the problem is coming, hoping it is not delayed.
the log filed and DeInited correctly the previous set i used before it crashed.
but before the crash nothing was written on disk, not even the start of the Init() function.
so to summarize, the crash happened before the init function and after the previous (working) set was DeInited.
this is becoming really weird.
well that could be one reason, but i'm quite an experienced programmer and this is the first time i see something like that. granted i know MT5 a little bit less than MT4 but it is quite similar.
unfortunately the code is too big to share it here.
But is there a way to debug random events ?
i tried logging the Init function, but the logging mechanism is delayed so nothing is written on screen before the crash
i think writing on disk would be the same ? i need to find where the error comes from but as it is random i'm not sure i can.
thanks for help
Well the API is very similar (mql), though MT5 has a completely different architecture, and I would not say its "quite similar". Anyway...
Usually when MT5 freeze that's because either you have an infinite loop or it is doing heavy calculation. You can also try to change "Max bars in chart" to a small value to see if it's related. I can't help more without code, sorry.
EDIT: What build are you using ?Well the API is very similar (mql), though MT5 has a completely different architecture, and I would not say its "quite similar". Anyway...
Usually when MT5 freeze that's because either you have an infinite loop or it is doing heavy calculation. You can also try to change "Max bars in chart" to a small value to see if it's related. I can't help more without code, sorry.
EDIT: What build are you using ?thanks.
also i'm using AlgLib so if any pointer was going rogue, i would get a message i think.
i agree that if MT5 freezes it is that there is a long computation of some kind, but i could not pinpoint the culprit
i use latest build btw
Two ideas: (without knowing your code):
(1) insert
Comment(__FUNCTION__,", line ",__LINE__);
at some strategic points in your code and therefore narrow down the last line that definitely has been executed before the freezing
(2) run the profiler and wait for some time after freezing, then stop and check for lines with extreme processing time
Two ideas: (without knowing your code):
(1) insert
at some strategic points in your code and therefore narrow down the last line that definitely has been executed before the freezing
(2) run the profiler and wait for some time after freezing, then stop and check for lines with extreme processing time
good ideas i'll remember that.
i kinda pinpointed where the error comes from though (i removed most of the code until it didn't crash anymore)
and it comes down to labels that i create at the beginning of the processing of the last "maxBars"
if i remove the label creation, then no more freezes. If i put it back it eventually freezes.
here is the code i used:
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 (maxlogs >= 0) if(file_handle!=INVALID_HANDLE) { FileWrite(file_handle,"d"); }*/ if (maxBars > 0) { if (i < rates_total - maxBars-npoints-reserve) { if i remove this next comments then it frezes again /*LabelDelete("compute time"); LabelDelete("time left"); LabelInit("compute time", InpX, InpY, InpFont, InpFontSize, InpColor, InpAngle, InpAnchor, InpBack, InpSelection, InpHidden, InpZOrder); LabelInit("time left", InpX, InpY+20, InpFont, InpFontSize, InpColor, InpAngle, InpAnchor, InpBack, InpSelection, InpHidden, InpZOrder);*/ /*LabelUpdate(0); LabelTime(maxComputeTime);*/ i = rates_total - maxBars-npoints-reserve; for (int j = 0; j < rates_total && !_StopFlag; j++) { MASHC[j] = EMPTY_VALUE; } timCompute = TimeLocal(); } } else if (i == 0) { if i remove this next comments then it frezes again /*LabelDelete("compute time"); LabelDelete("time left"); LabelInit("compute time", InpX, InpY, InpFont, InpFontSize, InpColor, InpAngle, InpAnchor, InpBack, InpSelection, InpHidden, InpZOrder); LabelInit("time left", InpX, InpY+20, InpFont, InpFontSize, InpColor, InpAngle, InpAnchor, InpBack, InpSelection, InpHidden, InpZOrder);*/ /*LabelUpdate(0); LabelTime(maxComputeTime);*/ for (int j = 0; j < rates_total && !_StopFlag; j++) { MASHC[j] = EMPTY_VALUE; } timCompute = TimeLocal(); } else i = rates_total-1; for (; i < rates_total && !_StopFlag; i++) { ........... rest of the code ...........
and here is the code i use for the label creation (standard code from Metaquotes)
void LabelInit(string name, int x, int y, string InpFont, int InpFontSize, color InpColor, double InpAngle, ENUM_ANCHOR_POINT InpAnchor, bool InpBack, bool InpSelection, bool InpHidden,long InpZOrder) { //--- store the label's coordinates in the local variables //--- chart window size long x_distance; //--- set window size if(!ChartGetInteger(0,CHART_WIDTH_IN_PIXELS,0,x_distance)) { Print("Failed to get the chart width! Error code = ",GetLastError()); return; } //--- prepare initial text for the label //--- create a text label on the chart if(!LabelCreate(0,name,0,x,y,CORNER_RIGHT_UPPER,"Compute completion",InpFont,InpFontSize, InpColor,InpAngle,InpAnchor,InpBack,InpSelection,InpHidden,InpZOrder)) { return; } //--- redraw the chart and wait for half a second ChartRedraw(); // Sleep(500); }
i still don't understand why this code is an issue.
Would it be better to create the label only once and hide the text when i don't want it to show ? i might try that.
thanks for the help guys
Jeff
hmm i just noticed, i commented the "Sleep(500);" line at the end of label creation. could it be the reason it freezes ? i'll investigate
Jeff
ok i've tested the indicator for several hours now (without the Labels creation) and it doesn't freeze
so i'm confident to say that this is the reason of the freezes
i think it may be a bug, but i don't understand why it happens on my MT5 and probably not in other people MT5? or is it a global bug?
it's a problem if i can't use Labels in my indicator... any ideas?
Jeff
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi
i'm currently trying to debug a MT5 indicator that randomly freezes the platform. I have to force the close then reopen it (i tried to wait for a long time to see if it gets its hand back but it didn't happen)
it freezes when i click "ok" after modifying some parameters. It doesn't matter which parameter i change.
To debug it, i have to be able to reproduce the error consistently, which i have not been able to do.
i tried starting from a smaller code and adding some parts but sometimes i click and change parameters for 20 minutes and nothing happens. Then another change and it freezes
this is really frustrating and i don't know how to go from there.
some help would be welcome
thanks a lot
Jeff