Check Open Orders

 

Hi,

I want to check open orders (market) orders for special number in OrderComment. If order with same comment exsist do not open another order.

Problem is that somethimes it duplicate order. Can you check for errors, please?

int countbuy = 0;
    for (int i=OrdersTotal()-1; i >= 0; i--)
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
    {
        if (OrderSymbol() == Symbol() && OrderType()==OP_BUY)
        if (StrToDouble(OrderComment())==NormalizeDouble(Mynumber,5))
        {
            countbuy++;
        }
    }
    else
    {
        Print("countbuy error - ", ErrorDescription(GetLastError()));
    }
    if (countbuy <1 || i==0)
    {
        res=OP_BUY;
 
Comments are not reliable, they can be changed or overwritten by your Broker.
 
That is true. But when order is closed. I need info until order is opened. Anyway can someone check code?
 
MINTA:
That is true. But when order is closed. I need info until order is opened. Anyway can someone check code?


Suggestion....

Mynumber as part of MagicNumber.....

MagicNumber = Magic + Mynumber ???

If (MagicNumber() - Magic == Mynumber) //.....countbuy++;  
 
MINTA:
That is true. But when order is closed. I need info until order is opened. Anyway can someone check code?
Maybe you have a Double precision issue . . . Can price != price ?
 
Mynumber as integer.
 
MINTA:
Mynumber as integer.
Then why are you converting the comment to a double?
 if (StrToDouble(OrderComment())==NormalizeDouble(Mynumber,5))