CTrade Stop Loss trigger

 

Hi, I have a question about the CTrade library.


When I have opened a position with a stop loss, one of two things can happen.

     1.    A condition is met and the position will be closed with the OrderClose() function.

     2.    A Stop Loss will be triggered, and the position will be closed automatically.


If case 2 happened:

      When my EA wants to close an opened position, how do I know that the position was already closed by the Stop Loss, so that I don't have to re-close that same position with my own OrderClose() call?


So how do I know if a position is open or closed?

 
Just check if position for the currency pair exists before trying to close it.
 

Thanks, which position property will have that information?


Position properties link:

https://www.mql5.com/en/docs/constants/tradingconstants/positionproperties#enum_position_property_integer

Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Position Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / Position Properties - Documentation on MQL5
 
Armand:

Thanks, which position property will have that information?

Position properties link:

https://www.mql5.com/en/docs/constants/tradingconstants/positionproperties#enum_position_property_integer 

In fact, instead of using the class CPositionInfo, you could use directly the trade function PositionSelect(string symbol).

Example: 

bool isOpened = PositionSelect("EURUSD");

 

 
enivid:
Just check if position for the currency pair exists before trying to close it.

Sorry enivid, I have answed Armand in wrong place, I did'nt realize the Armand posted again his doubt. 

 
Jin:

In fact, instead of using the class CPositionInfo, you could use directly the trade function PositionSelect(string symbol).

Example: 

bool isOpened = PositionSelect("EURUSD");

 

Thank you very much, that would work.
Reason: