Code Library / Risk Management
Break Even Stop Loss
Move SL to break even once in profit.
Language: MQL4 · Category: Risk Management · Tags: break even, stop loss, MQL4
Source code
void BreakEven(int ticket, double pips) {
if(!OrderSelect(ticket,SELECT_BY_TICKET)) return;
double pt = MarketInfo(OrderSymbol(),MODE_POINT);
if(OrderType()==OP_BUY && Bid-OrderOpenPrice()>=pips*pt)
if(OrderStopLoss()<OrderOpenPrice())
OrderModify(ticket,OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0);
}How to use this snippet
This is a building block, not a finished trading system. Paste it into your own MQL4 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.