Code Library / Order Management
MQL5 Order Modify Helper
Helper functions for modifying SL and TP on positions.
Language: MQL5 · Category: Order Management · Tags: order modification, MQL5, stop loss, take profit, position
Source code
#include <Trade/Trade.mqh>
CTrade trade;
bool ModSL(ulong t,double sl) {
if(!PositionSelectByTicket(t)) return false;
return trade.PositionModify(t,NormalizeDouble(sl,_Digits),PositionGetDouble(POSITION_TP));
}
bool ModTP(ulong t,double tp) {
if(!PositionSelectByTicket(t)) return false;
return trade.PositionModify(t,PositionGetDouble(POSITION_SL),NormalizeDouble(tp,_Digits));
}How to use this snippet
This is a building block, not a finished trading system. Paste it into your own MQL5 project, compile it, and test it on a demo account with your broker's real spreads before relying on it. If MetaEditor reports errors, the compilation error fixer can help.