In an EA, how to determine the difference between a position (filled) and an open order (not filled)

 
Hi everyone, I am coding my first EA (so MQL4 newbie, but I have decent experience in VBA) and I need a way to distinguish existing positions (filled orders) from pending (unfilled) orders.  I imagine there is a way to do this using one of the parameters of the OrderSelect() function, but the documentation and everything else I can find refers to "open orders" without distinguishing between positions and pending orders.  Can someone point me in the right direction?  I don't need code, just a parameter that will allow me to make that distinction.  Thank you!
 
jeffkotnik:
Hi everyone, I am coding my first EA (so MQL4 newbie, but I have decent experience in VBA) and I need a way to distinguish existing positions (filled orders) from pending (unfilled) orders.  I imagine there is a way to do this using one of the parameters of the OrderSelect() function, but the documentation and everything else I can find refers to "open orders" without distinguishing between positions and pending orders.  Can someone point me in the right direction?  I don't need code, just a parameter that will allow me to make that distinction.  Thank you!
You can do that by looking at the order type with the function OrderType().
OrderType - Trade Functions - MQL4 Reference
OrderType - Trade Functions - MQL4 Reference
  • docs.mql4.com
OrderType - Trade Functions - MQL4 Reference
 
Fernando Carreiro #:
You can do that by looking at the order type with the function OrderType().
Hi Fernando, thank you so much.  I did read somewhere that OrderType() of OP_BUYSTOP, OP_SELLSTOP, OP_BUYLIMIT, or OP_SELLLIMIT indicates a pending (unfilled) order.  Is that your understanding as well?  So my code needs to test for those four types, and if OrderType() returns false (I believe OrderType() is boolean), that means it is a position (filled order)?
 
jeffkotnik #: Hi Fernando, thank you so much.  I did read somewhere that OrderType() of OP_BUYSTOP, OP_SELLSTOP, OP_BUYLIMIT, or OP_SELLLIMIT indicates a pending (unfilled) order.  Is that your understanding as well?  So my code needs to test for those four types, and if OrderType() returns false (I believe OrderType() is boolean), that means it is a position (filled order)?

Did you even read the documentation at the link I provided? Where does it say that it returns a boolean true/false. It states that it returns an "int" with an enumeration of sorts that identifies the order operation properties.

Order Properties - Trade Constants - Constants, Enumerations and Structures - MQL4 Reference
Order Properties - Trade Constants - Constants, Enumerations and Structures - MQL4 Reference
  • docs.mql4.com
Order Properties - Trade Constants - Constants, Enumerations and Structures - MQL4 Reference
 
Fernando Carreiro #:

Did you even read the documentation at the link I provided? Where does it say that it returns a boolean true/false. It states that it returns an "int" with an enumeration of sorts that identifies the order operation properties.

I didn't even notice the link (I'm new to the forum) but thought I read somewhere that it was boolean.  I very much appreciate your help.