Download MetaTrader 5
To add comments, please log in or register
Register at MQL5.community and leave your comments!
xoxman4
13
xoxman4 2016.04.03 05:01 

Hi guys, 

I create objects on different charts (same symbol). Afterwards when iterating through all open charts in order to collect ALL objects mt4 does NOT return all !! Any ideas ?

    long chartID = ChartFirst();
    while ( chartID > -1 )
    {
      if ( ChartSymbol(chartID) == Symbol() )
      {
        int obj_total = ObjectsTotal ( chartID ); 
        for ( int x = 0; x < obj_total; x++ ) 
        { 
          string name = ObjectName ( x ); 
          if ( StringFind(name,key,0) > -1 )
          {
            ObjectDelete ( chartID, name );
            Print ( "-----> object ", name, " deleted" );
          }
        }      
      }
      ChartRedraw ( chartID );
      chartID = ChartNext ( chartID );
    }  
Keith Watford
Moderator
7984
Keith Watford 2016.04.03 05:39  

I must admit that as yet I have not had reason to work with objects on a different chart.

You might try

          string name = ObjectName (chartID, x ); 

and see if it works for you

Ovo Cz
2952
Ovo Cz 2016.04.03 06:36  

In addition to Gumrai. This coding problem was thousand times here.

        for ( int x = 0; x < obj_total; x++ ) 
        { 
          string name = ObjectName ( x ); 
          if ( StringFind(name,key,0) > -1 )
          {
            ObjectDelete ( chartID, name );
            Print ( "-----> object ", name, " deleted" );
          }
        }      
      }
      ChartRedraw ( chartID );
whroeder1
13641
whroeder1 2016.04.03 13:08  
Ovo: In addition to Gumrai. This coding problem was thousand times here.
 for ( int x = 0; x < obj_total; x++ ) 

As has been repeated thousands of time here, you must count down in position loops.
In the presence of multiple orders (one EA multiple charts, multiple EA's, manual trading) you must count down when closing/deleting/modifying in a position loop. Get in the habit of always counting down. Loops and Closing or Deleting Orders - MQL4 forum
whroeder1
13641
whroeder1 2016.04.03 13:36  
xoxman4: I create objects on different charts (same symbol). Afterwards when iterating through all open charts in order to collect ALL objects mt4 does NOT return all !!
string name = ObjectName ( x ); 

  1. Not going to work. ObjectName only works on the current chart. There is no ObjectName(chartId, position)
  2. I'd ask Metaquotes what use is ObjectsTotal(chartID) when you can't get their names.
peter.MT4Web
158
peter.MT4Web 2016.04.03 21:41  

Use the MQL5 definition:

string  ObjectName( 
   long  chart_id,           // Identifikator des Charts  
   int   pos,                // Nummer in der Liste der Objekte  
   int   sub_window=-1,      // Nummer des Fensters 
   int   type=-1             // Typ des Objekts 
   );

It will also work on MQL4.


xoxman4
13
xoxman4 2016.04.04 08:44  
thanks a lot, works now !! :)
whroeder1
13641
whroeder1 2016.04.04 12:37  
eddie:

Use the MQL5 definition:

It will also work on MQL4.

Then the missing documentation should be reported to the service desk.
Zirkon
123
Zirkon 2016.04.08 11:26  

You should use the ObjectsDeleteAll() with a prefix, easier and faster.

   long chartID=ChartFirst();
   while(chartID>-1)
     {
      if(ChartSymbol(chartID)==Symbol())
        {
         ObjectsDeleteAll(chartID,key);
        }
      ChartRedraw(chartID);
      chartID=ChartNext(chartID);
     }
/
To add comments, please log in or register