Results 1 to 3 of 3
 0 Attachment(s)    

Thread: Help! Check for 2 opne Buy Orders...

  1. #1

    Default Help! Check for 2 opne Buy Orders...

    I'm having trouble with a simple line of code. Say I have 10 orders.... Both "Buys" and "Sells" open (hedge) in a single currency pair. I want to check if I have 2 buys (and 8 sells)... I want to do this to close other limit orders but this line of code is not working....





    if((OrderType()==OP_SELL)&& OrdersTotal()==2)

  2. #2

    Default

    Quote Originally Posted by BillR View Post
    I'm having trouble with a simple line of code. Say I have 10 orders.... Both "Buys" and "Sells" open (hedge) in a single currency pair. I want to check if I have 2 buys (and 8 sells)... I want to do this to close other limit orders but this line of code is not working....





    if((OrderType()==OP_SELL)&& OrdersTotal()==2)
    The OrdersTotal() function returns the total number of of open orders in the pool regardless of their symbol, magic number or anything else. It will therefore include open buys and sells from other EAs as well.

    You need to select your orders relating to just this EA and count them. You could do that through a function similar to this at the end of your code.

    Code:
    int MyOrdersTotal(int Magic)
    {
      int c=0;
      int total  = OrdersTotal();
    
      for (int cnt = 0 ; cnt < total ; cnt++)
      {
        OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
        if (OrderMagicNumber() == Magic && OrderSymbol()==Symbol())
        {
          c++;
        }
      }
      return(c);
    }
    You would then introduce a rule to do whatever you wanted according to the value returned by this function:

    Code:
    if(MyOrdersTotal(Magic)==//you need to fill this in yorself;
    The function will return the total open orders for this EA. You might want to modify it to just return a count of open buy or open sell orders.

  3. #3

    Default

    Jezzer Thanks...for your help!

Similar Threads

  1. How to check swappiness ?
    By fxtester in forum General discussion
    Replies: 1
    Last Post: 04-13-2015, 11:34
  2. Check my EA and please add EMA filter
    By smartone in forum Ideas for expert advisors
    Replies: 0
    Last Post: 06-12-2010, 13:25
  3. Check for TP take profit script
    By tkaboris in forum MQL programming
    Replies: 3
    Last Post: 04-20-2009, 11:51

Tags for this Thread

eas, hedge, limit, magic, magic number, sells, simple

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •