Must every individual object on the chart have its own unique name?

 

I want my EA to print arrows on the chart to indicate where a trade was opened/closed. Is there anyway that we can draw multiple of the same object at different points in the chart?

For example I might want to create an arrow on the current bar:

Created = ObjectCreate(ChartID(),"Sell_Arrow",OBJ_ARROW_SELL,0,Time[0],Level);

And then I might want to do the exact same thing on the most recent fully formed bar:

Created = ObjectCreate(ChartID(),"Sell_Arrow",OBJ_ARROW_SELL,0,Time[1],Level1);

But using the above method does not work - error 4200 (object already created) is returned if you write it this way.

...

Does this mean that we have to create a unique name for each individual arrow we place on the chart? Or is there a way that we can display multiple of the same created arrow at different points on the chart, effectively creating duplicates of the same object?

 
Created = ObjectCreate(ChartID(),"Sell_Arrow "+TimeToString(Time[0],TIME_DATE|TIME_MINUTES);,OBJ_ARROW_SELL,0,Time[0],Level);

Use time in the object name

 
Keith Watford:

Use time in the object name

Thanks again Keith.

 

@Keith Watford mentions using time, which I have used.

I've also used a sequential number for this. It's just a global integer that I increment for each object I create.

 
Anthony Garot:

@Keith Watford mentions using time, which I have used.

I've also used a sequential number for this. It's just a global integer that I increment for each object I create.

Thanks Anthony I'll keep that in mind.

 
Anthony Garot:

@Keith Watford mentions using time, which I have used.

I've also used a sequential number for this. It's just a global integer that I increment for each object I create.

The advantage of using time can be that it is easier to locate it if you need to. Ie if you need to know how many bars back the arrow was painted.

 
Part of a solution is to use a function 'getObjectName' and always use that instead of an actual name for Object Create:
string getObjName(void) // or pass some seed values
  {
     static int counter = 0;  counter++;
    return("someText"+IntegerToString(counter));
  }
ObjectCreate(ChartID(), getObjName(), ...
Reason: