Check order status

 

Hello to everybody,

I have a little problem, because of my little knowledge of MQL5 language... Once I open an order, using OrderOpen() of Ctrade class, now I want to know to check its status at every tick; i.e. I want to know if it is still opened or instead closed because of TakeProfit or StopLoss level is reached.

How to do ?

Pls., help me !!!
Davide

 
I want to know if it is still opened

PositionSelect() will tell you if a position is still open.

https://www.mql5.com/en/docs/trading/positionselect

or instead closed because of TakeProfit or StopLoss level is reached.

Look at the OnTradeTransaction() event.

https://www.mql5.com/en/docs/event_handlers/ontradetransaction

 

Hello Antony,

Thanks for your reply... but PositionSelect returns only true or false.

I do not know how manage opened oreder or check.

 
DeltaElectronics:

Hello Antony,

Thanks for your reply... but PositionSelect returns only true or false.

I do not know how manage opened oreder or check.

You've probably figured it out by now, but if not, PositionSelect is only used to select the position, then if it returns true, you would want to get information about that position previously selected with another function call. 

https://www.mql5.com/en/docs/trading/positiongetdouble

https://www.mql5.com/en/docs/trading/positiongetinteger

if(PositionSelect(Symbol()){
        if(PositionGetDouble(POSITION_VOLUME) == 0){
        
        }
}       

This is just an example on how to access positions information.  

Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Position Properties
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Position Properties
  • www.mql5.com
Position ticket. Unique number assigned to each newly opened position. It usually matches the ticket of an order used to open the position except when the ticket is changed as a result of service operations on the server, for example, when charging swaps with position re-opening. To find an order used to open a position, apply the...