BreakEven Script

ForexNewbie51

Active Trader
Sep 22, 2011
31
5
44
Hi, This is a script I use when my order is about 15 or 20 Pips in profit.

It sets the Stop Loss so if the price retraces it closes at Breakeven. I would like to know how to modify this to BreakEven plus x pips (say 3pips). The reason is price does retrace often and I have a lot of zero gain trades when I could have at least exited with a tiny profit. Is this an easy request?

This is the script. I use it selectively when I suspect a retrace. I agree it can reduce profits but if I had just 3 pips above breakeven the numbers are good. When the value gets higher than the point I engage it my trailing stop function of my EA kicks in. It's just these "grey area" trades that can suddenly turn that I want to protect myself from.

*** I attacheded the MQ4 file with the original post but it seems to have disappeared 🙁 I have re-sent below
 
Last edited:
Did you forget to attach the script?

Anyway, I wouldn't recommend using such trading technique. It ruins your strategy, while giving you illusion of "being right about the markets" by giving you many small profits.
 
Last edited:
Set to BE plus (re-sent)

I did attach the file but it seems to have disappeared. I have pasted it here and also re-attached file - see if this stays attached.

MQL4:
/+------------------------------------------------------------------+
//| script program start function |
//+------------------------------------------------------------------+
int start()
{
//----
string curr = Symbol();
int ot = OrdersTotal();
int ords[200], ordType[200], ordTicket[200]; double ordLots[200];
string ordComments[200];
int ix=0;
for (int i=0; i<ot; i++)
{
int o = OrderSelect(i, SELECT_BY_POS);
if (OrderSymbol() == Symbol())
if ((OrderType() == OP_BUY) || (OrderType() == OP_SELL))
{
double sl = 0;
if ((OrderType() == OP_BUY) && (OrderStopLoss() < OrderOpenPrice()))
sl = OrderOpenPrice() ;
if ((OrderType() == OP_SELL) && (OrderStopLoss() > OrderOpenPrice()))
sl = OrderOpenPrice() ;
 
if (sl != 0)
OrderModify(OrderTicket(), OrderOpenPrice(), sl, OrderTakeProfit(), 0);
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
 

Attachments

Last edited by a moderator:
Thanks for providing the code, but, please don't forget to use the highlighting when inserting big portions of MQL code.

If you want to modify the stop-loss from breakeven to breakeven + some pips, just change the following lines:
MQL4:
sl = OrderOpenPrice() ;
to this for BUY orders:
MQL4:
sl = OrderOpenPrice() + 10 * Point;
and this for SELL orders:
MQL4:
sl = OrderOpenPrice() - 10 * Point;

Of course, you can enter any amount of pips instead of 10.
 
Last edited:
Realise I am a few years too late with my reply 🙁 but others might pick up on it

Hi, This is a script I use when my order is about 15 or 20 Pips in profit.

It sets the Stop Loss so if the price retraces it closes at Breakeven. I would like to know how to modify this to BreakEven plus x pips (say 3pips). The reason is price does retrace often and I have a lot of zero gain trades when I could have at least exited with a tiny profit. Is this an easy request?

Why don't you just use a Trailing Stop (TS) set at 10 or 15 which you can start as soon as you place the trade - you don't have to wait for it to reach your chosen level before adding. Once it reaches your level your in the money 🙂
.