Delete-All-Chart-Objects

Author: Copyright 2021, Thomas Nowotny
0 Views
0 Downloads
0 Favorites
Delete-All-Chart-Objects
ÿþ//+------------------------------------------------------------------+

//|                                     Delete-All-Chart-Objects.mq5 |

//|                                   Copyright 2021, Thomas Nowotny |

//|                                             https://www.mql5.com |

//+------------------------------------------------------------------+

#property copyright     "Copyright 2021, Thomas Nowotny"

#property version       "1.00"

#property description   "\n\nDeletes the comment, arrows and objects on the chart. \nCheck the inputs."

#property script_show_inputs



//+------------------------------------------------------------------+

//| Script program start function                                    |

//+------------------------------------------------------------------+



input bool DeleteComment   = true;                                         // Delete the comment in the chart

input bool DeleteArrow     = true;                                         // Delete old trading arrows

input bool DeleteAllOthers = true;                                         // Delete all lines and other objects



void OnStart(){



   if(DeleteComment)Comment("");                                           // clear the comment on chart

   

   if(DeleteArrow){

      int objectTotalCount = ObjectsTotal(0);

      for(int i=objectTotalCount-1 ; i>=0; i--){                           // loop backwards

         string objectName = ObjectName(0,i);                              

         if(StringFind(objectName,"autotrade") != -1){                     // found the "autotrade" in the object name?

            ObjectDelete(0,objectName);                                    // delete the found object

         }

      }

   }

   

   if(DeleteAllOthers){

      int objectTotalCount = ObjectsTotal(0);

      for(int i=objectTotalCount-1 ; i>=0; i--){                           // loop backwards

         string objectName = ObjectName(0,i);                              

         if(StringFind(objectName,"autotrade") != -1);                     // skip autotrade objects

         else{ 

            ObjectDelete(0,objectName);                                    // delete the object

            //Print("** ",objectName," deleted");

         }

      }

   }

   

} // end OnStart()

//+------------------------------------------------------------------+

Comments