It is almost always your code.
How To Ask Questions The Smart Way. (2004)
Don't rush to claim that you have found a bug.
Questions Not To Ask
My program doesn't work. I think system facility X is broken.
Do you really expect an answer? There are no mind readers here and our crystal balls are cracked, so we can't see your machine.
How To Ask Questions The Smart Way. (2004)
Be precise and informative about your problem
We can't see your broken code.
Always post all relevant code (using Code button) or attach the source file.
It is almost always your code.
How To Ask Questions The Smart Way. (2004)
Don't rush to claim that you have found a bug.
Questions Not To Ask
My program doesn't work. I think system facility X is broken.
Do you really expect an answer? There are no mind readers here and our crystal balls are cracked, so we can't see your machine.
How To Ask Questions The Smart Way. (2004)
Be precise and informative about your problem
We can't see your broken code.
Always post all relevant code (using Code button) or attach the source file.
For anyone else who's experiencing the same problem, it would appear that graphic objects are not actually removed from the chart until the next ChartRedraw. Mentioning this in ObjectDelete would have saved a lot of time. So, adding a ChartRedraw() before OnDeinit() returns will remove the deleted objects from the chart.
William - please don't judge everyone by your own yardstick. I suggest you take some lessons in etiquette as you have no idea how to respond in a well-mannered way. In the future, please don't reply to my posts, as your responses are not helpful.
Does anyone know any reason why my indicator's graphic objects do not get removed from the chart when the indicator is removed? After the indicator is removed, the objects appear in the chart's object list (CTRL-B).
I'm using the latest build 4410 21.06.24
I'm calling ObjectDelete on all graphic objects the indicator creates.
The object name and chart id is correct.
The object names are unique.
The result of ObjectDelete is true.
_LastError is ERR_SUCCESS.
Deletion is called in OnDeinit().
I've tried restarting the terminal, different symbols and timeframes.
Thanks.
This is a programmer error. So we need code to help you.
Hi Nikolai
Thank you for your offer of help. The following is some tested AI generated code, with a few comments added by me, that simply draws an HLINE on a chart, preferably EURUSD H4, and then uses ObjectDelete in OnDeinit. I appreciate that ObjectDelete is an asynchronous function that processes objects from a queue. But, clearly it needs another function call like ChartRedraw to get the queue processed before OnDeinit returns.
Perhaps you can direct me to the documentation showing how it should be done.
Thanks.
//+------------------------------------------------------------------+ //| HLine.mq5 | //| Copyright 2024, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property indicator_chart_window // AI generated // defined for EURUSD H4 15/09/2024 input double HLinePrice = 1.108; // Price level for the horizontal line input color HLineColor = clrRed; // Color of the horizontal line //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { // Create a horizontal line object if(ObjectCreate(0, "HLine", OBJ_HLINE, 0, 0, HLinePrice)) { // Set the properties of the horizontal line ObjectSetInteger(0, "HLine", OBJPROP_COLOR, HLineColor); ObjectSetInteger(0, "HLine", OBJPROP_WIDTH, 2); ObjectSetInteger(0, "HLine", OBJPROP_STYLE, STYLE_SOLID); } else { Print("Failed to create the horizontal line."); return(INIT_FAILED); } return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { // Delete the horizontal line object ObjectDelete(0, "HLine"); // without the following line, the horizontal line is not deleted when the indicator is removed from the chart. CTRL-B -> List all // uncomment this line to fix bug. //ChartRedraw(); } //+------------------------------------------------------------------+ //| 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[]) { // No calculations needed for this indicator return(rates_total); } //+------------------------------------------------------------------+
Hi Nikolai
Thank you for your offer of help. The following is some tested AI generated code, with a few comments added by me, that simply draws an HLINE on a chart, preferably EURUSD H4, and then uses ObjectDelete in OnDeinit. I appreciate that ObjectDelete is an asynchronous function that processes objects from a queue. But, clearly it needs another function call like ChartRedraw to get the queue processed before OnDeinit returns.
Perhaps you can direct me to the documentation showing how it should be done.
Thanks.
Hi Robert,
I don't see any problems if at the end of OnDeinit there is ChartRedraw();
Hi Robert,
I don't see any problems if at the end of OnDeinit there is ChartRedraw();
Hi Nikolai
I agree, there is no problem with adding ChartRedraw after ObjectDelete, or a similar function that causes the queue to be processed. But, it would have been helpful if this had been mentioned in the documentation for ObjectDelete, rather than spending unnecessary time guessing what needs to be done, or finding the answer in a post like this. Programmers need full, detailed documentation, preferably with examples.
Rob
we should not need ChartRedraw() in OnDeInit
It is more like an MT5 bug if it isn't deleting the object straight away. I also experienced this a few times, but not all the time.
we should not need ChartRedraw() in OnDeInit
It is more like an MT5 bug if it isn't deleting the object straight away. I also experienced this a few times, but not all the time.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Does anyone know any reason why my indicator's graphic objects do not get removed from the chart when the indicator is removed? After the indicator is removed, the objects appear in the chart's object list (CTRL-B).
I'm using the latest build 4410 21.06.24
I'm calling ObjectDelete on all graphic objects the indicator creates.
The object name and chart id is correct.
The object names are unique.
The result of ObjectDelete is true.
_LastError is ERR_SUCCESS.
Deletion is called in OnDeinit().
I've tried restarting the terminal, different symbols and timeframes.
Thanks.