Stop Loss to Breakeven code verification

 

Hi Experts,

The open position stop loss is not modified for some reason. Am I doing it wrong? Here is my current breakeven code.

  //Runner Breakeven
  if(PositionsTotal()==1)
  {
  ulong  positionticket=PositionGetInteger(POSITION_TICKET);
  double Openprice=PositionGetDouble(POSITION_PRICE_OPEN);
  double PositionTP=PositionGetDouble(POSITION_TP);
  
  trade.PositionModify(positionticket,Openprice,PositionTP); 
  }

Thanks,
M Amir

 

You need to select the position first (Positions Totals would not be needed if you only have 1 position)

  //Runner Breakeven
  if(PositionSelect(Symbol())) // if(PositionGetTicket(0)>0)
  {
        ulong  positionticket=PositionGetInteger(POSITION_TICKET);
        double Openprice=PositionGetDouble(POSITION_PRICE_OPEN);
        double PositionTP=PositionGetDouble(POSITION_TP);
  
        trade.PositionModify(positionticket,Openprice,PositionTP); 
  }

PositionSelect gets the first trade of that symbol (if I remember correctly) and PositionGetTicket gets the ticket of the position at that index. For more complex things it's better to use the standard library (CTrade, CPositionInfo...)

 
M. Amir: Am I doing it wrong?
How about selecting a position before trying to get position information. via CPositionInfo, directly, or by 'MT4Orders' library (2016)
 
Manuel Alejandro Cercos Perez #:

You need to select the position first (Positions Totals would not be needed if you only have 1 position)

PositionSelect gets the first trade of that symbol (if I remember correctly) and PositionGetTicket gets the ticket of the position at that index. For more complex things it's better to use the standard library (CTrade, CPositionInfo...)

  //Runners Breakeven
  if(TimeCheck()==true && PositionsTotal()==1)
  {
  ulong  positionticket=PositionGetTicket(0);
  double Openprice=PositionGetDouble(POSITION_PRICE_OPEN);
  double PositionTP=PositionGetDouble(POSITION_TP);
  
  trade.PositionModify(positionticket,Openprice,PositionTP); 
  }

Thanks man, that fixed it

Reason: