Selecting all objects of a type

 

Coders,

Could someone help me with the following?

I'm using an Elliot wave script to manually label the waves. The script places 8 different objects on the chart (i,ii,iii,iv,v,a,b,c).

Everything works fine, but deleting the objects is a lot work. Because I have to click on every object(i,ii,iii,iv,v,a,b,c), to delete them. I would like to add something to the code which makes me able to highlight/select all objects (i,ii,iii,iv,v,a,b,c) with just one click on a object of the array. I've already searched but I couldn't find the function I need.

(I'm not looking for a script who deletes all objects on the chart, because I'm labeling more than one wave.)

Thanks in advance

//+------------------------------------------------------------------+
//|                                               wave labels ff.mq4 |
//+------------------------------------------------------------------+
#property version   "1.00"
#property strict
#include <stdlib.mqh>
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+ 

extern string Text1 = "(i)";  // Enter Text to place on screen
extern string Text2 = "(ii)";  // Enter Text to place on screen
extern string Text3 = "(iii)";  // Enter Text to place on screen
extern string Text4 = "(iv)";  // Enter Text to place on screen
extern string Text5 = "(v)";  // Enter Text to place on screen
extern string Text6 = "(a)";  // Enter Text to place on screen
extern string Text7 = "(b)";  // Enter Text to place on screen
extern string Text8 = "(c)";  // Enter Text to place on screen

extern string Text_font="Arial Bold"; // font of text
extern int Text_fontsize = 14; // size of text
extern color Text_color = Red; // color of text
 
int TextBarsAhead2 = 7; // # bars to space 2nd letter from first
int TextBarsAhead3 = 14; // # bars to space 3rd letter from first
int TextBarsAhead4 = 21; // # bars to space 4th letter from first
int TextBarsAhead5 = 28; // # bars to space 5th letter from first 
int TextBarsAhead6 = 35; // # bars to space 6th letter from first
int TextBarsAhead7 = 42; // # bars to space 7th letter from first
int TextBarsAhead8 = 49; // # bars to space 8th letter from first
//+------------------------------------------------------------------+  
 
 
 
 
//+-----------------------------SCRIPT CODE--------------------------+
int OnStart(){

  
     double price = WindowPriceOnDropped(); // find the price point where dropped
   datetime Time1 = WindowTimeOnDropped(); // find the time point where dropped
   datetime TimeNow = TimeCurrent(); // get the current time ( makes name unique)
   
   datetime Time2 = (int)Time1+TextBarsAhead2*(int)Period()*60;
   datetime Time3 = (int)Time1+TextBarsAhead3*(int)Period()*60;
   datetime Time4 = (int)Time1+TextBarsAhead4*(int)Period()*60;
   datetime Time5 = (int)Time1+TextBarsAhead5*(int)Period()*60;
   datetime Time6 = (int)Time1+TextBarsAhead6*(int)Period()*60;
   datetime Time7 = (int)Time1+TextBarsAhead7*(int)Period()*60;
   datetime Time8 = (int)Time1+TextBarsAhead8*(int)Period()*60;

 
   string gap="    "; // spacing between text characters
   string text=Text1+gap+Text2+gap+Text3+gap+Text4+gap+Text5; // put the text in a line
   TextToPrint ("Wave labels 1 " + (string)TimeNow, Text1, Text_fontsize, Text_font, Text_color, Time1, price); //print 1st letter
   TextToPrint ("Wave labels 2 " + (string)TimeNow, Text2, Text_fontsize, Text_font, Text_color, Time2, price); //print 1st letter
   TextToPrint ("Wave labels 3 " + (string)TimeNow, Text3, Text_fontsize, Text_font, Text_color, Time3, price); //print 1st letter
   TextToPrint ("Wave labels 4 " + (string)TimeNow, Text4, Text_fontsize, Text_font, Text_color, Time4, price); //print 1st letter
   TextToPrint ("Wave labels 5 " + (string)TimeNow, Text5, Text_fontsize, Text_font, Text_color, Time5, price); //print 1st letter
   TextToPrint ("Wave labels 6 " + (string)TimeNow, Text6, Text_fontsize, Text_font, Text_color, Time6, price); //print 1st letter
   TextToPrint ("Wave labels 7 " + (string)TimeNow, Text7, Text_fontsize, Text_font, Text_color, Time7, price); //print 1st letter
   TextToPrint ("Wave labels 8 " + (string)TimeNow, Text8, Text_fontsize, Text_font, Text_color, Time8, price); //print 1st letter
 
 
   return(0);
  }
//+------------------------------------------------------------------+
 
void TextToPrint(string TextName,string LabelText,int FontSize,string FontName,color TextColor,datetime Time0,double Price0)
  {
  if(StringLen(LabelText)>1){
   ObjectCreate(TextName,OBJ_TEXT,0,Time0,Price0);
   ObjectSetText(TextName,LabelText,FontSize,FontName,TextColor);
   }
  }
//+------------------------------------------------------------------+
 

Use ObjectsDeleteAll, e.g.:

ObjectsDeleteAll(0,0,OBJ_TEXT);
ObjectsDeleteAll - MQL4 Documentation
  • docs.mql4.com
ObjectsDeleteAll - MQL4 Documentation
 
Enrico Lambino:

Use ObjectsDeleteAll, e.g.:

Thanks for your reply.

 

ObjectsDeleteAll will work, but I don't want to delete all text objects.

Does a function exists which will combines all text objects of my script. Which will allow me when I double click on a text object the other text objects of the array will also highlight.

 

Explanation with pictures:

 

I would like to, when I click on one of the text objects placed by my script, that all textobjects of the array get highlighted/selected. 

http://prntscr.com/7yucrp 

 

So I can use the button delete selected items. 

http://prntscr.com/7yucfm

 

 

Thanks in advance,

Terry

 

I see, in that case, you will not need that function. In MQL5, it is possible to delete using a certain prefix (e.g. "Wave labels") using the same function (ObjectsDeleteAll). In MQL4, it does not have that argument, so you will need to iterate over the objects on the chart using a loop (with StringFind).

StringFind - MQL4 Documentation
  • docs.mql4.com
StringFind - MQL4 Documentation
 
Enrico Lambino:

I see, in that case, you will not need that function. In MQL5, it is possible to delete using a certain prefix (e.g. "Wave labels") using the same function (ObjectsDeleteAll). In MQL4, it does not have that argument, so you will need to iterate over the objects on the chart using a loop (with StringFind).

The prefix variant of ObjectsDeleteAll() is working also with MT4 (build 845). It's undocumented for now.
 
You can also use:
ObjectSetInteger OBJPROP_SELECTABLE
 Object availability
 bool

Then double click all objects you want to delete so they are selected and then

ObjectGetInteger OBJPROP_SELECTED
 Object is selected
 bool
 

in a loop to get all selected objects and then delete all of them with one delete button.

or if that's not what you were looking for you can have the code select them and delete them without clicking manually.

Reason: