A question for MQL experts - page 10

 
FAQ:
If your order opens, check for the opening of one order and if it opens, you may open the second order with a check...

I have written two functions that open differently depending on the situation and I will check at the end of each of them (I think they will be a separate function) what and how many orders are open and what orders will be missed and will be reopened.

If you are an expert in the field of positioning of the EA in terms of forex, you may be interested in finding out more about it and use it in your trading robot. I would like to reiterate my thanks (sorry for the lack of details).

 

Good morning.

A problem has arisen. I can't find the function that returns the size of the "aggregate" position of a given instrument! I searched the whole forum, including I.KIM's branch,https://www.mql5.com/ru/forum/131859 - there are - different functions for lots, except for the one I need!

For example, if there are several open "buy" deals on EUR, can you advise how to determine their total amount?

GetLot(EURUSD, OP_BUY, magic)

double GetLot(string sy="", int op=-1, int mn=-1) {// возвращает сувокупный размер поз.
   double   l=-1;
  int      i, k=OrdersTotal();

  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if (OrderSymbol()==sy || sy=="") {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (op<0 || OrderType()==op) {
            if (mn<0 || OrderMagicNumber()==mn) {

              I = ------  ???????????
              ------ ????????????
              

            }
          }
        }
      }
    }
  }
  return(l);
}
 

Question cleared! A function has been discovered:

//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 19.02.2008                                                     |
//|  Описание : Возвращает сумму лотов открытых позиций                        |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   (""   - любой символ,                   |
//|                                     NULL - текущий символ)                 |
//|    op - операция                   (-1   - любая позиция)                  |
//|    mn - MagicNumber                (-1   - любой магик)                    |
//+----------------------------------------------------------------------------+
double GetAmountLotFromOpenPos(string sy="", int op=-1, int mn=-1) {
  double l=0;
  int    i, k=OrdersTotal();
 
  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if (OrderSymbol()==sy || sy=="") {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (op<0 || OrderType()==op) {
            if (mn<0 || OrderMagicNumber()==mn) {
              l+=OrderLots();
            }
          }
        }
      }
    }
  }
  return(l);
}
 
That's not it )
 

How is it wrong? Then what does this function return?

"Returns the sum of lots of open positions " - isn't it written?

https://www.mql5.com/ru/code/9394

 
Rita:

"Returns the sum of the lots of open positions" - isn't it written?

That's right. It's never the total volume of a position. You can open a lot and check it.
 

I don't need to take locs into account. Or rather, here's how:

What I need is this. If there are several open Sell and Buy positions, I need to remove the counter (compensating) positions, so - to remain only in one direction.

I wanted to first calculate the sum of all "bays", then the sum of all "sells". After that, find the difference (i.e. whose total size is greater). And this "difference" should be left in the market, - and all the opposite ones removed!

So, this function GetAmountLotFromOpenPos will not work here? For example, if I set

GetAmountLotFromOpenPos(EURUSD,OP_SELL, -1)

-Won't it return the total amount of lots of all the sell positions?

 
Rita:

-won't she give me back the sum of the lots of all the sell positions?

Sorry if so, it's OK. Monday. My head isn't fully engaged yet :)
 
Rita:

I don't need to take locs into account. Or rather, here's how:

What I need is this. If there are several open Sell and Buy positions, I need to remove the counter (compensating) positions, so - to remain only in one direction.

I wanted to first calculate the sum of all "bays", then the sum of all "sells". After that, find the difference (i.e. whose total size is greater). And this "difference" should be left in the market, - and all the opposite ones removed!

So, this function GetAmountLotFromOpenPos will not work here? For example, if I set

GetAmountLotFromOpenPos(EURUSD,OP_SELL, -1)

-Won't it return the total amount of lots of all Sell positions?

In the general case:

SummLot = GetAmountLotFromOpenPos("0", OP_BUY, MagicNumber)- GetAmountLotFromOpenPos("0", OP_SELL, MagicNumber);

 
Yes, that's what I did to get a 'clean' balance.
Reason: