Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16
 5 Attachment(s)    

Thread: Count Lots OP_SELL and OP_BUY

  1. #11

    Default

    Here is my code that I used in all my EAs to count the total lots of long and short positions ...

    Code:
    double TotalOpenLotsUP(string smbl){ 
       int cnt, total; 
       double lot = 0;
       total = OrdersTotal(); 
       for(cnt=0; cnt<total; cnt++){ 
          OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES); 
          if(OrderSymbol()==smbl && OrderMagicNumber()==MagicUP)
             lot = lot + OrderLots(); 
       }
       return(lot);
    }
    
    double TotalOpenLotsDN(string smbl){ 
       int cnt, total; 
       double lot = 0;
       total = OrdersTotal(); 
       for(cnt=0; cnt<total; cnt++){ 
          OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES); 
          if(OrderSymbol()==smbl && OrderMagicNumber()==MagicDN)
             lot = lot + OrderLots(); 
       }
       return(lot);
    }

  2. #12
    Junior Member CodeMonkey's Avatar
    Join Date
    Sep 2013
    Location
    Portland Oregon USA
    Posts
    3

    Cool Function to get the lot count of open orders.

    Quote Originally Posted by christion View Post
    HI
    I wanna count the lots of all open orders (OP_Buy and OP_Sell).
    could someone tell me the code to count the lots of all open orders?
    The following function will display the lot count for your open buy and sell orders.

    Code:
    void lot_count(){   
       double buy_lots,sell_lots;
       for(int x=OrdersTotal()-1; x>=0; x--){
          OrderSelect(x,SELECT_BY_POS,MODE_TRADES);
          if(OrderType()==OP_BUY) { buy_lots=buy_lots+OrderLots(); }
          if(OrderType()==OP_SELL){ sell_lots=sell_lots+OrderLots();}    
       }
       Comment( "\nBuy lots: ",NormalizeDouble(buy_lots,2),
                "\nSell lots: ",NormalizeDouble(sell_lots,2),
                "\nTotal lots: ",NormalizeDouble(buy_lots+sell_lots,2));
    }
    You're welcome.
    - CodeMonkey

  3. #13

    Default

    Quote Originally Posted by oshaban View Post
    Here is my code that I used in all my EAs to count the total lots of long and short positions ...

    Code:
    double TotalOpenLotsUP(string smbl){ 
       int cnt, total; 
       double lot = 0;
       total = OrdersTotal(); 
       for(cnt=0; cnt<total; cnt++){ 
          OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES); 
          if(OrderSymbol()==smbl && Order_Type() == OP_BUY && OrderMagicNumber()==MagicUP)
             lot = lot + OrderLots(); 
       }
       return(lot);
    }
    
    double TotalOpenLotsDN(string smbl){ 
       int cnt, total; 
       double lot = 0;
       total = OrdersTotal(); 
       for(cnt=0; cnt<total; cnt++){ 
          OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES); 
          if(OrderSymbol()==smbl && Order_Type() == OP_SELL && OrderMagicNumber()==MagicDN)
             lot = lot + OrderLots(); 
       }
       return(lot);
    }
    You may use same above code in this way ...

    double Total_lots = TotalOpenLotsUP(symbol()) + TotalOpenLotsDN(symbol());

    Change magic number according to yours ...

    That's all !.

  4. #14

    Default

    Hi ...
    I don't understand what you mean by the "rest of the lots !" ... would you please clarify that !.

  5. #15

    Default

    if you want to count the number of buy and sell orders but not the lots,
    You just need to replace

    Lots = Lots + OrderLots();

    with

    Lots ++;

    That's it.

  6. #16

    Default

    Everything is clear ... Please, just concentrate on what I wrote ... You can have all the options you like ...
    Profit for up, profit for down, lots for up, lots for down, total profit and total lots.

    It is a code, playing with it can give you the result you want.

    Good luck ...

Similar Threads

  1. Margin and Lots
    By painofhell in forum Trading discussion
    Replies: 1
    Last Post: 09-01-2014, 08:54
  2. Lots Multiplier( help Please)
    By joepayne in forum MQL programming
    Replies: 22
    Last Post: 02-12-2011, 04:35
  3. Nano Lots
    By JXBlack in forum Brokers
    Replies: 1
    Last Post: 07-23-2010, 20:36
  4. Change lots/multiplier to lots=0.01 gives OrderSend error 130?
    By sleepypipsCDN in forum MQL programming
    Replies: 7
    Last Post: 04-12-2009, 09:17
  5. Mini Lots - Micro Lots
    By funyoo in forum Trading discussion
    Replies: 0
    Last Post: 01-23-2009, 12:06

Tags for this Thread

100, breakout, change, eas, grid, magic number, profit, thank you

Posting Permissions

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