MQL5 - Questions about Position Close and Modify

 

Hi,
-------------------------------------------------------
Question 1:
somewhere inside position-managing parts of my EA, i need to close an open position.
Since I have the ticket of that position, I can easily close it using standard class function Ctrade bool RES =  PositionClose(ticket, ULONG_MAX);
in order to see if the position was closed successfully, if I check the bool and that's true, and if ResultRecode() is 10009, does that mean the position is 100% closed ?

  • A : is it possible to get a 10009 return code from server, but the position isn't closed?
  • B : is it possible to receive a non-10009 retcode , while the position is closed successfully ? (due to connection delay or something)
  • C : can a false return from PositionSelectByTicket indicate it is closed? (is this way reliable to check if a position with known ticket is still open/close ?)

I know to be sure, I can check all open positions and see if the ticket can be found among the active open positions, but actually the whole question was to avoid this (probably time-consuming) procedure.


-------------------------------------------------------

Question 2:
When Modifying an already open position,I should consider both stops_level and freeze_level ?
in an article (EA checkups) the method for avoiding stoplevel and freezelevel errors, is the same. so can I adjust my calculated SL and TP based on MathMax(stoplevel, freezelevel) before Modifying?
instead of taking care of both ? (not sure if both of these considerations are needed to be taken into account in my EA trading in MarketExecution mode)

 
Anyone ?
 
Code2219 or probably 2319:

Hi,
-------------------------------------------------------
Question 1:
somewhere inside position-managing parts of my EA, i need to close an open position.
Since I have the ticket of that position, I can easily close it using standard class function Ctrade bool RES =  PositionClose(ticket, ULONG_MAX);
in order to see if the position was closed successfully, if I check the bool and that's true, and if ResultRecode() is 10009, does that mean the position is 100% closed ?

  • A : is it possible to get a 10009 return code from server, but the position isn't closed?
  • B : is it possible to receive a non-10009 retcode , while the position is closed successfully ? (due to connection delay or something)
  • C : can a false return from PositionSelectByTicket indicate it is closed? (is this way reliable to check if a position with known ticket is still open/close ?)

I know to be sure, I can check all open positions and see if the ticket can be found among the active open positions, but actually the whole question was to avoid this (probably time-consuming) procedure.


-------------------------------------------------------

Question 2:
When Modifying an already open position,I should consider both stops_level and freeze_level ?
in an article (EA checkups) the method for avoiding stoplevel and freezelevel errors, is the same. so can I adjust my calculated SL and TP based on MathMax(stoplevel, freezelevel) before Modifying?
instead of taking care of both ? (not sure if both of these considerations are needed to be taken into account in my EA trading in MarketExecution mode)


Question one. I never had problem on closing open position. The result always correct. If there is problem executing the command due to lagging, usually the return code will not misleading as the code need the server to return the ResultRetcode.

if(type==POSITION_TYPE_BUY || type==POSITION_TYPE_SELL)
         {
            // close the current position          
            if (!trading.PositionClose(_Symbol,Deviation_))
            {
               //--- failure message
            Print("PositionClose() method failed. Return code=",trading.ResultRetcode(),
                  ". Code description: ",trading.ResultRetcodeDescription());
            }
            else
            {
                Print("PositionClose() method executed successfully. Return code=",trading.ResultRetcode(),
                  " (",trading.ResultRetcodeDescription(),")");
            }
         }                           

Question 2: You can always modify the only parameter you want to modify as long the price valid with spread rule. 


 
Zamzuri Saad:
Please do not answer inside the quote. It's confusing.
 
Alain Verleyen:
Please do not answer inside the quote. It's confusing.

Noted

 

Ok, to ZamZuri : what you mean by "spread rules" ?

my EA is never gonna set SL and TP when sending order for opening a new position.
so, all my positions are set in two step : opening a position with SL=0, and TP=0, then modifying the open position with SL and TP.
So all the considerations should be made when modifying a open position only. (No Pending order)

I've seen many different comments about what are the checks before modifying SL/TP of an open position.
when we say Distance of SL/TP should be >= FreezeLevel (or Stops Level), what is the other end of distance ? ( OpenPrice of position or Current Bid or Current Ask ?)

Remind you, I'm always only modifying an already open position. No other situation.