Object creation on different charts

Back to topics list To post a new topic, please log in or register
avatar
2
xoxman4 2016.04.03 07: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 );
    }  

 


 

 

 

avatar
Moderator
3427
GumRai 2016.04.03 07: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

avatar
1111
Ovo 2016.04.03 08: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 );
avatar
13010
WHRoeder 2016.04.03 15: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
avatar
13010
WHRoeder 2016.04.03 15: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.
avatar
108
eddie 2016.04.03 23: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.


avatar
2
xoxman4 2016.04.04 10:44 #
 
thanks a lot, works now !! :)
avatar
13010
WHRoeder 2016.04.04 14:37 #
 
eddie:

Use the MQL5 definition:

It will also work on MQL4.

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

avatar
125
zirkoner 2016.04.08 13: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);
     }
Back to topics list  

To add comments, please log in or register