Problems with ObjectCreate

 
Hi Guys,

i've the following code sample:
void OnTick()
  {
//---
   /* Check for Open Orders */
    for (int cnt = 0; cnt < OrdersTotal(); cnt++) {
   
        if (!OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES)) continue;
      
        if (OrderSymbol() == Symbol()) {
               
            if (OrderType() == 0) {
                double LinePrice = OrderOpenPrice() + 0.00050;
                bool obj = ObjectCreate("HLine", OBJ_HLINE, 0, 0, LinePrice);
                if (obj==true) {
                    Print("Object created");
                } else {
                    Print("Object NOT created. " + IntegerToString(GetLastError()));
                }
            }
        }
              
    }
  }
I open a Pending Order and wait. If the Pending Order became active, the object will created. This is working as expected. Now, I want the Line also for Pending Orders.

So I changed the code from
"OrderType()==0"
to
"OrderType()==0 || OrderType()==2 || OrderType==4"
The object is not created until the Order become active (OrderType=0).
There is one more curio in this scenario. If it is a Pending Order, the variable obj returns "true", althought line is not drawn. If order become active, the line is drawn but the variable returns "false" with error code 4200 (Object already exist).

Could anyone help? thanks in advance.
 
 
What part of "Object already exists" is unclear? you can only have one object named "HLine"
 
WHRoeder:
What part of "Object already exists" is unclear? you can only have one object named "HLine"
I know, but the error said, that the object exists, but it does not exist. I checked it in Objects (Ctrl+B).

While the order is a pending order (type 2 or 4), i got true as response to object create but it does not exist! When the order become market order (typ 0), then will the object created but with response false and the error that it already exists.
 
  1. fx_maddin: When the order become market order (typ 0), then will the object created
    You created it when you had a pending order (type 2 or 4,) then you again try to create it when it becomes market (type 0)
  2. Don't hard code constants, use the enumeration Order Properties - Trade Constants - Standard Constants, Enumerations and Structures - MQL4 Reference



 
WHRoeder:
  1. fx_maddin: When the order become market order (typ 0), then will the object created
    You created it when you had a pending order (type 2 or 4,) then you again try to create it when it becomes market (type 0)
  2. Don't hard code constants, use the enumeration Order Properties - Trade Constants - Standard Constants, Enumerations and Structures - MQL4 Reference
1. The Plan is, to create this line and it should does not matter which type of order is there. Once again my explanation:

I create a Pending Order. Then, the ObjectCreate function return true, but the object DO NOT EXIST! It is not created!! The Pending Order becomes Market Order, the Object Create function returns false, but the object EXISTS now.


If i create a market order, the object is created instantly.

It sounds crazy and for me it makes no sense, but it is a fact!
Reason: