Object creation on different charts

 

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 );
    }  
 

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

 

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 );
 
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
 
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.
 

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.


 
thanks a lot, works now !! :)
 
eddie:

Use the MQL5 definition:

It will also work on MQL4.

Then the missing documentation should be reported to the service desk.
 

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);
     }
 
peter.MT4Web:

Use the MQL5 definition:

It will also work on MQL4.


How can I do it?

Thanks in advance

Reason: