How do I delete comments and other things on the chart? - page 2

 
ZeroCafeine #:
Thank you all for your answers 😉
Concerning OnDeinit().

The function has a maximum execution time that may not be exceeded. It is 2500ms.

In case you delete lots of objects, you might need to switch to ObjectDeleteAll. And use the parameters.

Create all Objects with a common prefix for their names, use that prefix with the DeleteAll () function call.

It is faster, and selects only your objects, identified by the prefix.


 
Merci
Dominik Christian Egert #:
The function has a maximum execution time that may not be exceeded. It is 2500ms.

Thank you very much 😉. Can you tell me where you found this information? I don't see it in the documentation for the OnDeinit() function.

Documentation sur MQL5: Gestion d'Evènements / OnDeinit
Documentation sur MQL5: Gestion d'Evènements / OnDeinit
  • www.mql5.com
OnDeinit - Gestion d'Evènements - Référence MQL5 - Référence sur le langage de trading algorithmique/automatisé pour MetaTrader 5
 
ZeroCafeine #:
Merci

Thank you very much 😉. Can you tell me where you found this information? I don't see it in the documentation for the OnDeinit() function.

In the documentation.

https://www.mql5.com/en/docs/runtime/event_fire#deinit

Documentation on MQL5: MQL5 programs / Client Terminal Events
Documentation on MQL5: MQL5 programs / Client Terminal Events
  • www.mql5.com
Client Terminal Events - MQL5 programs - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Tks you 😊
 

Discard my previous idea for deleting all objects on the chart. Unnecessary looping can cause lagging in the indicator.


You can do this to delete the objects your indicator created:


void OnDeinit(const int reason){
    ObjectsDeleteAll(0, "my_first_object_name");
    ObjectsDeleteAll(0, "my_second_object_name");
    ObjectsDeleteAll(0, "my_third_object_name");
}

I overcomplicated it.

 
phade #:

Discard my previous idea for deleting all objects on the chart. Unnecessary looping can cause lagging in the indicator.


You can do this to delete the objects your indicator created:


I overcomplicated it.

i was gonna say about that after read everything.

Actually this also is not the best.

Instead, define a constant as prefix for all your objects, for example,

#define OBJ_PREFIX MQLInfoString(MQL_PROGRAM_NAME)

, then add this prefix to the name of your objects and when you need delete just call 

ObjectsDeleteAll(0, OBJ_PREFIX);

And for comments the Comment("") is enough. But is a better idea replace the comment by an object as well, because not only one program can write comments, so you don't know if the comment comes from your program or another.

 
Samuel Manoel De Souza #:

i was gonna say about that after read everything.

Actually this also is not the best.

Instead, define a constant as prefix for all your objects, for example,

, then add this prefix to the name of your objects and when you need delete just call 

And for comments the Comment("") is enough. But is a better idea replace the comment by an object as well, because not only one program can write comments, so you don't know if the comment comes from your program or another.

Good info, I will apply this myself, thanks

 

Thanks to all who gave input on this topic.

I just made a very simple Script from your comments and I think it works as it deleted a comment from the chart.

I only had the one comment to delete , so not a great test but here it is, I hope this helps someone.

Its only 6 lines as follows, save it in Scripts folder and Compile (0 errors,  1 warnings) 


// DELETE ALL COMMENTS SCRIPT

int start()

{

 ChartSetString(0, CHART_COMMENT, "");

}

//----------------------------------