How to get number of deals.

 

Hello I am working on developing an EA, but have trouble with getting the right number of deals.

My EA needs to detect when there is an open deal and prevent it from getting another order or deal through, but I cannot get the number of deals or detect if there are any open deals? Can anyone advice me on it? I tried using what I found:

if (HistorySelect(0,TimeCurrent()))  
{
int tot_hist_orders = HistoryOrdersTotal();
} 

But it still does not detect the correct number of open deals.   Is there any easy way to detect the number of open deals accurately?

 

Thank you. 

Documentation on MQL5: Trade Functions / HistoryDealsTotal
  • www.mql5.com
Trade Functions / HistoryDealsTotal - Documentation on MQL5
 
noviceTrader:

Hello I am working on developing an EA, but have trouble with getting the right number of deals.

My EA needs to detect when there is an open deal and prevent it from getting another order or deal through, but I cannot get the number of deals or detect if there are any open deals? Can anyone advice me on it? I tried using what I found:

But it still does not detect the correct number of open deals.   Is there any easy way to detect the number of open deals accurately?

 

Thank you. 

You want to know the open deals, but you're looking to the closed "history" deals

 use   OrdersTotal()   not  ......     and then select      Symbol,....

 
deVries:

You want to know the open deals, but you're looking to the closed "history" deals

 use   OrdersTotal()   not  ......     and then select      Symbol,....

But doesn't that give me the number of orders and not the actual deals that it processes?
Documentation on MQL5: Trade Functions / OrdersTotal
  • www.mql5.com
Trade Functions / OrdersTotal - Documentation on MQL5
 

OrdersTotal

Returns the number of current orders.

int OrdersTotal();

Return Value

Value of the int type.

Note

Do not confuse current pending orders with positions, which are also displayed on the "Trade" tab of the "Toolbox" of the client terminal. An order is a request to conduct a transaction, while a position is a result of one or more deals.

For each symbol, at any given moment of time, only one position can be open, while there can be several pending orders for the same symbol.

See also

OrderSelect(), OrderGetTicket(), Order Properties

 
deVries:

OrdersTotal

Returns the number of current orders.

int OrdersTotal();

Return Value

Value of the int type.

Note

Do not confuse current pending orders with positions, which are also displayed on the "Trade" tab of the "Toolbox" of the client terminal. An order is a request to conduct a transaction, while a position is a result of one or more deals.

For each symbol, at any given moment of time, only one position can be open, while there can be several pending orders for the same symbol.

See also

OrderSelect(), OrderGetTicket(), Order Properties

Exactly it gives the number of orders not the actual deals. From my understanding, you can have asynchronous signals. So my EA can have multiple order requests but not all of the end up as actual deals. Orders are sent to server to generate deals correct? And deals are the actual trades, yes? I need the number of deals not orders.

I am maybe misunderstanding the concept of this but please if you can clarify it for me. I want to have just one deal open at all times so I need to check and make sure that I only have one actual deal not how many orders my EA has put with the server.

 

Thank you very much. 

 

This thread may have useful info to find current open deals.

https://www.mql5.com/en/forum/2018 

 

Thank you both, this made it more clear on what I need to do.