How to determine how a trade was made

 

Hello, I am new to MQL5 and I was trying to determine from an open trade how it was placed. 

Below is a screen shot of what I am looking for.  I cannot locate in any of the ENUMs for a trade or position.

Any help would be greatly appreciated.



 
find your position among open ones (if it's currently open, aka not in history) , and select it, then :
ENUM_POSITION_REASON REASON = (ENUM_POSITION_REASON)PositionGetInteger(POSITION_REASON);
if(REASON==POSITION_REASON_CLIENT)
{
        // probably (or definitely?) placed manually. (need confirmation)
}
else if(REASON==POSITION_REASON_EXPERT)
{
        // made by an EA
}
else if(REASON==POSITION_REASON_MOBILE)
{
        // bla bla bla
}
else if(REASON==POSITION_REASON_WEB)
{
        // bla bla bla
}
 
Code2219 or probably 2319:
find your position among open ones (if it's currently open, aka not in history) , and select it, then :

Thanks for your reply...

All of my positions are showing CLIENT, even the Manual orders ... I need to know which is MANUAL if that is available.

 
Eddi Rae Melton:

Thanks for your reply...

All of my positions are showing CLIENT, even the Manual orders ... I need to know which is MANUAL if that is available.

told you, CLIENTs are manually placed orders.
 
Code2219 or probably 2319:
told you, CLIENTs are manually placed orders.

That's not exact. A manually placed position (or order) is all what is not POSITION_REASON_EXPERT.

long REASON = PositionGetInteger(POSITION_REASON);
if(REASON!=POSITION_REASON_EXPERT)
  {
    //--- Manually opened position
  }
As a manual position can be open with the desktop Terminal, mobile Terminal or Web application.
 
Alain Verleyen:

That's not exact. A manually placed position (or order) is all what is not POSITION_REASON_EXPERT.

As a manual position can be open with the desktop Terminal, mobile Terminal or Web application.
Alain, I am getting a 0 for both the manual and the EA order.  Where are the ENUMs set up so I can see what values are for the POSITION_REASON?
 
Eddi Rae Melton:
Alain, I am getting a 0 for both the manual and the EA order.  Where are the ENUMs set up so I can see what values are for the POSITION_REASON?
Show your code if you need coding help.
 
Alain Verleyen:
Show your code if you need coding help.

long enumReason = PositionGetInteger(POSITION_REASON);

if (enumReason !=POSITION_REASON_EXPERT)
   {
      Print(my4CastObj.GetSymbol(),":  Trade was made outside of Expert Advisor");
      Alert(my4CastObj.GetSymbol(),":  Trade was made outside of Expert Advisor");
   }

 

Thanks all for helping with this.  I found my issue.  I wasn't placing this in the OnTick() subroutine and I wasn't selecting the position when running this.

It is now working like a champ!!

 
Code2219 or 2319 #:
find your position among open ones (if it's currently open, aka not in history) , and select it, then :
How do I get the same functions for mql4? I have gone through the mql4 reference for the ENUM_POSITION_REASON didn't see any related to that of MQL5. Will appreciate. 
 
Adebayo Bisiriyu Adewole #: How do I get the same functions for mql4?

Positions do not exist in MT4, only orders. Manually placed orders have a magic number of zero.

Reason: