Download MetaTrader 5

OrdersTotal doesn't appear to work

To add comments, please log in or register
We have launched Spanish and Portuguese versions of the website. Try them!
strontiumDog
286
strontiumDog 2013.10.23 10:42 

Hello

This is probably a simple fix, but I've got a cold.

In my buy function I have

		OrderSend(mrequest,mresult);
and then
if(mresult.retcode==10009 || mresult.retcode==10008) { // Request is completed or order placed
                        Alert("SELL order has been successfully placed with Ticket #",mresult.order,".");
                        Print("OrdesTotal=",OrdersTotal());

 

So I'm expecting one open position (short), with, in this case - as I run the back tester to the first order point - one sell order.  This is what the journal says:

 

2013.10.23 09:31:49     2012.01.05 09:00:05   OrdesTotal=0
2013.10.23 09:31:49     2012.01.05 09:00:05   Alert: SELL order has been successfully placed with Ticket #2.
2013.10.23 09:31:49     2012.01.05 09:00:05   order performed sell 0.30 at 1.28665 [#2 sell 0.30 EURUSD at 1.28665]
2013.10.23 09:31:49     2012.01.05 09:00:05   deal performed [#2 sell 0.30 EURUSD at 1.28665]
2013.10.23 09:31:49     2012.01.05 09:00:05   deal #2 sell 0.30 EURUSD at 1.28665 done (based on order #2)

 So I don't understand why the OrdersTotal() function returns 0 when the very previous instant, it has just opened a SELL order.

I've read the article about orders and deals and positions, so I think I'm doing this right.  This sell order is open at that point, so I'm expecting OrdersTotal() to return the integer 1.

Can anyone tell me why this is not the case please?

Thanks 

Documentation on MQL5: Trade Functions / OrdersTotal
Documentation on MQL5: Trade Functions / OrdersTotal
  • www.mql5.com
Trade Functions / OrdersTotal - Documentation on MQL5
Simon Gniadkowski
Moderator
18001
Simon Gniadkowski 2013.10.23 10:49  
strontiumDog:

Hello

This is probably a simple fix, but I've got a cold.

In my buy function I have

and then

 

So I'm expecting one open position (short), with, in this case - as I run the back tester to the first order point - one sell order.  This is what the journal says:

 

 So I don't understand why the OrdersTotal() function returns 0 when the very previous instant, it has just opened a SELL order.

I've read the article about orders and deals and positions, so I think I'm doing this right.  This sell order is open at that point, so I'm expecting OrdersTotal() to return the integer 1.

Can anyone tell me why this is not the case please?

Thanks 

You said it yourself . . .   "So I'm expecting one open position (short)" . . .  how many Orders are you expecting ?  zero and that is what you get.  Why don't you try PositionsTotal()
Alain Verleyen
Moderator
30743
Alain Verleyen 2013.10.23 11:29  
strontiumDog:
...

I've read the article about orders and deals and positions, so I think I'm doing this right.  This sell order is open at that point, so I'm expecting OrdersTotal() to return the integer 1.

Can anyone tell me why this is not the case please?

Thanks 

Seems you have to read it again See documentation of OrdersTotal() also.

You sent a market order (sell), so when to order is executed, it doesn't exist anymore. OrdersTotal() is related to pending orders.

strontiumDog
286
strontiumDog 2013.10.23 17:59  

Thanks for the clarification.

I saw reference in the docs to pending orders and confused it with deals.  If I send an order to buy EURUSD, I see an up arrow on the terminal chart.  If I open three others *on the same chart*, that's four arrows, 4 sent - and processed - buy orders, and 4 deals.  I'm interested in using a function which returns the integer 4 as a result of this.  PositionsTotal will return 1.  HistoryDealGetInteger() is thus what I (think I) am looking for.

cheers
Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Order Properties
Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / Order Properties - Documentation on MQL5
Alain Verleyen
Moderator
30743
Alain Verleyen 2013.10.23 18:13  
strontiumDog:

Thanks for the clarification.

I saw reference in the docs to pending orders and confused it with deals.  If I send an order to buy EURUSD, I see an up arrow on the terminal chart.  If I open three others *on the same chart*, that's four arrows, 4 sent - and processed - buy orders, and 4 deals.  I'm interested in using a function which returns the integer 4 as a result of this.  PositionsTotal will return 1.  HistoryDealGetInteger() is thus what I (think I) am looking for.

cheers
You probably have to use HistorySelectByPosition() and then HistoryDealsTotal().
strontiumDog
286
strontiumDog 2013.10.23 18:26  

So I'm looking at all the functions with names starting 'HistoryDeals...'.  If I run aground, I'll come back to this post.


strontiumDog
286
strontiumDog 2013.10.23 18:26  
angevoyageur:
You probably have to use HistorySelectByPosition() and then HistoryDealsTotal().
Ah good - I'm on the right track.  Thanks again.
Alain Verleyen
Moderator
30743
Alain Verleyen 2013.10.23 18:52  
strontiumDog:
HistorySelectByPosition() requires the POSITION_IDENTIFIER.  This is a unique number assigned presumably when it is created.  Is the most efficient way of doing this by using PositionSelect(SYMBOL)?

No.

You have this code:

if(mresult.retcode==10009 || mresult.retcode==10008) { // Request is completed or order placed
                        Alert("SELL order has been successfully placed with Ticket #",mresult.order,".");
                        Print("OrdesTotal=",OrdersTotal());

mresult gives you the deal ticket number, so you can use it to get your information :

HistoryDealSelect(mresult.deal);
HistoryDealGetInteger(mresult.deal,DEAL_POSITION_ID);              

I don't include error checking.

To add comments, please log in or register