MT4 No Object draw On Chart but i get Object Exist Error

 
hey folks ..im tryna create arrows to my closed orders history using this code
void draw_history(){
  for (int i=0; i<OrdersHistoryTotal(); i++) {
   if (OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true) {
    if (OrderSymbol()==Symbol()) 
       {if (OrderProfit()<0)
         {ObjectCreate(0,"loss",OBJ_ARROW_UP,0,0,OrderClosePrice());          
          ObjectSet("loss",OBJPROP_COLOR,clrGreen);
          /*Print("obj Error",GetLastError());*/ } }
     }
   }
 }

no object is created when i try to print the last error i get 4200 -Object Exists ...what is wrong

 

You are trying to create the same object over and over.

void draw_history(){
  for (int i=0; i<OrdersHistoryTotal(); i++) {
   if (OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true) {
    if (OrderSymbol()==Symbol()) 
       {if (OrderProfit()<0)
         {ObjectCreate(0,"loss"+IntegerToString(i),OBJ_ARROW_UP,0,0,OrderClosePrice());          
          ObjectSet("loss"+IntegerToString(i),OBJPROP_COLOR,clrGreen);
          /*Print("obj Error",GetLastError());*/ } }
     }
   }
 }

It's best to check if the object exists before creating it.

Check the return value of:

ObjectFind();
 
Omega J Msigwa:
hey folks ..im tryna create arrows to my closed orders history using this code

no object is created when i try to print the last error i get 4200 -Object Exists ...what is wrong

The object is created, but you have set the time to 1st January 1970.
Then when another losing trade is found, you try to create a new object with the same name.

topics concerning MT4 and MQL4 have their own section.

In future please post in the correct section.

I will move your topic to the MQL4 and Metatrader 4 section.

 
Marco vd Heijden:

You are trying to create the same object over and over.

It's best to check if the object exists before creating it.

Check the return value of:

but no object is drawn at all i see nothing Sir

 
Omega J Msigwa:

but no object is drawn at all i see nothing Sir

Yes it is.
Read my previous post.

 
Marco vd Heijden:

You are trying to create the same object over and over.

It's best to check if the object exists before creating it.

Check the return value of:

i have tried finding an object if Exists using this code and draw history 

void draw_history(){
  for (int i=0; i<OrdersHistoryTotal(); i++) {
   if (OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true) {
     for (int objcts=0; objcts<ObjectsTotal(ChartID()); objcts++){
       if (OrderSymbol()==Symbol() ) 
          {if (OrderProfit()<0 && ObjectFind(ChartID(),"loss"+IntegerToString(i))!=ObjectName(0,objcts))
            {ObjectCreate(0,"loss"+IntegerToString(i),OBJ_ARROW_DOWN,0,0,OrderClosePrice());          
             ObjectSet("loss"+IntegerToString(i),OBJPROP_COLOR,clrRed);
             /*Print("obj Error",GetLastError());*/ } 
           else if (OrderProfit()>0 && ObjectFind(ChartID(),"loss"+IntegerToString(i))!=ObjectName(0,objcts)) 
            {ObjectCreate(0,"profit"+IntegerToString(i),OBJ_ARROW_UP,0,0,OrderClosePrice());          
             ObjectSet("profit"+IntegerToString(i),OBJPROP_COLOR,clrGreen);
              /*Print("obj Error",GetLastError());*/   }
           }
          }
        }
     }
 }

still i get the same story when i try to get the object drawn ...Will you please help me also by code if you don't mind i found it hard to understand some of you the things you explain ..maybe code  will help me to better understand

 
Omega J Msigwa:

i have tried finding an object if Exists using this code and draw history 

still i get the same story when i try to get the object drawn ...Will you please help me also by code if you don't mind i found it hard to understand some of you the things you explain ..maybe code  will help me to better understand

You are asking for help but you are not even trying to help yourself.

if (OrderProfit()<0 && ObjectFind(ChartID(),"loss"+IntegerToString(i))!=ObjectName(0,objcts))

Have you even read the documentation for ObjectFind() or ObjectName() ??

 
Keith Watford:

You are asking for help but you are not even trying to help yourself.

Have you even read the documentation for ObjectFind() or ObjectName() ??

i get it ..Thanks

Reason: