How to remove tp from active position that does not have a stop loss ?

 

Hi Everyone,

My EA code open a position using  Trade.Buy(lotsize,_Symbol,Ask,0,tp) without any stop loss  but having a tp price.                

When certain conditions are met, i would like to remove the tp by using Trade.PositionModify(ticket,0,0) but EA keep producing failed modify [Invalid stops] error.

Does anyone have any solution to this ? My requirement is straight forward but does not seems to have a solution.



 
You should post all the relevant code for help.
 
Andrew SK:

Hi Everyone,

My EA code open a position using  Trade.Buy(lotsize,_Symbol,Ask,0,tp) without any stop loss  but having a tp price.                

When certain conditions are met, i would like to remove the tp by using Trade.PositionModify(ticket,0,0) but EA keep producing failed modify [Invalid stops] error.

Does anyone have any solution to this ? My requirement is straight forward but does not seems to have a solution.



Traders and coders are working for free:

  • if it is interesting for them personally, or
  • if it is interesting for many members on this forum.

Freelance section of the forum should be used in most of the cases.

Trading applications for MetaTrader 5 to order
Trading applications for MetaTrader 5 to order
  • 2025.06.23
  • www.mql5.com
The largest freelance service with MQL5 application developers
 
Andrew SK:

Hi Everyone,

My EA code open a position using  Trade.Buy(lotsize,_Symbol,Ask,0,tp) without any stop loss  but having a tp price.                

When certain conditions are met, i would like to remove the tp by using Trade.PositionModify(ticket,0,0) but EA keep producing failed modify [Invalid stops] error.

Does anyone have any solution to this ? My requirement is straight forward but does not seems to have a solution.



you probably forgot to select the position first with PositionGetTicket() and then PositionSelectByTicket(). After that then you can feed Trade.PositionModify(ticket, 0,0 or whatever)