Problems with ObjectCreate

Back to topics list To post a new topic, please log in or register
avatar
33
fx_maddin 2016.06.22 14:34
 
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.
 
avatar
12995
WHRoeder 2016.06.22 19:58 #
 
What part of "Object already exists" is unclear? you can only have one object named "HLine"
avatar
33
fx_maddin 2016.06.22 20:21 #
 
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.
avatar
12995
WHRoeder 2016.06.23 03:54 #
 
  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



avatar
33
fx_maddin 2016.06.23 09:49 #
 
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!
Back to topics list  

To add comments, please log in or register