How to show total lot position size of all running sell orders (without pending orders)?

 

How can I show in MT4 the total LOT of all open sell orders (but not the pending orders)?

Below script works perfectly to see the amount of sell/buy orders. But now I'd like to modify so I only see the total sell LOT size. Could you please help me?

EA code: (this works for counting amount of orders, but now it needs to count the amount of total sell LOT)

int OnInit()
  {
//---
      // this is number of orders not the ammount
      // we can solve the ammount later.
      int nBuyOrders = 0;
      int nSellOrders = 0;
     
      for(int i=0; i < OrdersTotal(); i++)
      {
       
         if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == true)
         {
            // match the symbol EUR/USD or EUR/CHF, etc
            if(OrderSymbol() == Symbol())
            {
               if(OrderType() == OP_BUY)
                  nBuyOrders++;
               if(OrderType() == OP_SELL)
                  nSellOrders++;
            }
         }   
      }
     
      string sBuyText = "Total Buy = ";
      sBuyText += nBuyOrders;
      string sSellText = "Total Sell = ";
      sSellText += nSellOrders;
     
      ObjectCreate("ObjName", OBJ_LABEL, 0, 0, 0);
      ObjectSetText("ObjName", sBuyText, 7, "Verdana", Yellow);
      ObjectSet("ObjName", OBJPROP_CORNER, 0);
      ObjectSet("ObjName", OBJPROP_XDISTANCE, 20);
      ObjectSet("ObjName", OBJPROP_YDISTANCE, 20);
     
      ObjectCreate("ObjName2", OBJ_LABEL, 0, 0, 0);
      ObjectSetText("ObjName2", sSellText, 7, "Verdana", Yellow);
      ObjectSet("ObjName2", OBJPROP_CORNER, 0);
      ObjectSet("ObjName2", OBJPROP_XDISTANCE, 20);
      ObjectSet("ObjName2", OBJPROP_YDISTANCE, 40);
     
    
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
  
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---

  }


Below code we could implement in above EA. Do you see anything interesting to use?

int total=OrdersTotal();

double totalots=0;

for(int 1=0; i<total; i++)

{ OrderSelect(i, SELECT_BY_POS, MODE_TRADES)

totalots+=OrderLots(); //this gives the total no of lots opened in current ordes

}


Lots=(AccountBalance()/(CurrencyLotSize/100))/(Margin_Per_Lot/1000);

   Sum( OrderOpenPrice() * OrderLots() ) / Sum( OrderLots() ) = Weighted Average OrderOpenPrice()


if(OrderType()==OP_BUY)

for (int i = 0; i < OrdersTotal(); i++)
{
 if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == FALSE) break;//If no order then get outta here!

if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
{

if (OrderType() == OP_BUY)

}

 

You need OrderLots() function. Something like this:

 

      double totalBuyLots = 0;
      double totalSellLots = 0;
      
      for(int i=0; i < OrdersTotal(); i++)
      {
        
         if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == true)
         {
            // match the symbol EUR/USD or EUR/CHF, etc
            if(OrderSymbol() == Symbol())
            {
               if(OrderType() == OP_BUY)
                  totalBuyLots += OrderLots();
               if(OrderType() == OP_SELL)
                  totalSellLots += OrderLots();
            }
         }    
      }

 

In the indicators folder you will find "iExposure" indicator. It contains code for counting and summing orders. Check it out.

As a note, you should probably build this project as indicator instead of EA. Also, OnInit executes only when you start your EA. Lot summing code should go to the OnTick() function.

 

Hi Drazen, thank you. Thanks to you it's working now. This thread is closed. Below is the working code to check the lot size of all buy orders. And seperately all sell orders:


//+------------------------------------------------------------------+
//|                                                        testt.mq4 |
//|                        Copyright 2015, MetaQuotes Software Corp. | 
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, MetaQuotes Software Corp."
#property link      "https://www.mql5.com" 
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function                                   | 
//+------------------------------------------------------------------+
void PrintText(string object, string text, int x, int y) 
{
   ObjectCreate(object, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(object, text, 9, "Verdana", Yellow);
   ObjectSet(object, OBJPROP_CORNER, 0); 
   ObjectSet(object, OBJPROP_XDISTANCE, x);
   ObjectSet(object, OBJPROP_YDISTANCE, y);
}

void CalculateLots() 
{
      double totalBuyLots = 0;
      double totalSellLots = 0;
      
      for(int i=0; i < OrdersTotal(); i++) 
      {
         if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == true)
         {
            //if(OrderSymbol() == Symbol()) 
            {
               if(OrderType() == OP_BUY)
                  totalBuyLots += OrderLots(); 
               if(OrderType() == OP_SELL)
                  totalSellLots += OrderLots(); 
            }
         }    
      }
      
      string sBuyText = "Total Buy = "; 
      sBuyText += DoubleToString(totalBuyLots, 2);
      string sSellText = "Total Sell = ";
      sSellText += DoubleToString(totalSellLots, 2); 
      
      PrintText("BuyObject", sBuyText, 20, 20);
      PrintText("SellObject", sSellText, 20, 40); 
}

int OnInit()
  {
//---
   CalculateLots();
//---
   return(INIT_SUCCEEDED);
  } 
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 | 
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             | 
//+------------------------------------------------------------------+
void OnTick()
  {
//---
      CalculateLots(); 
  }
//+------------------------------------------------------------------+



  


 
Can some of you help me guys?

This indicator is not working... Can one of you sent me the working MQ4 file please?

Thanks.

Greets Hannes
 
Forex_FX_live:
Can some of you help me guys?

This indicator is not working... Can one of you sent me the working MQ4 file please?

Do not double post.

I have deleted your other post.

It is not an indicator, it is an EA

 
Yeah cool, but how do i get this thing running?
 
Forex_FX_live:
Yeah cool, but how do i get this thing running?

Put it in the EA folder not the indicator folder

 
So i also need to build it as an EA in metaeditor? 
 

Hi guys, I am looking for an indicator to show just one number (Currency account) for the profit of loss sum for all positions open .  Thanks.

 
John Cortes:

Hi guys, I am looking for an indicator to show just one number (Currency account) for the profit of loss sum for all positions open .  Thanks.

I think couldnt understand you 

could you explain little more 

 
Ahmet Metin Yilmaz: I think couldnt understand you could you explain little more 

What part of "Sum profit for all open positions" was unclear?