BreakEven Script

Discussion in 'MetaTrader Scripts' started by ForexNewbie51, Jan 9, 2012.

  1. ForexNewbie51

    ForexNewbie51 Active Trader

    31
    2
    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: Jan 10, 2012
  2. Enivid

    Enivid Administrator Staff Member

    8,361
    289
    114
    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: Jan 11, 2012
  3. ForexNewbie51

    ForexNewbie51 Active Trader

    31
    2
    44
    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.

    Code (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);
    }
    //+------------------------------------------------------------------+
     

    Attached Files:

    Last edited by a moderator: Sep 28, 2015
  4. Enivid

    Enivid Administrator Staff Member

    8,361
    289
    114
    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:
    Code (MQL4):
    to this for BUY orders:
    Code (MQL4):
    sl = OrderOpenPrice() + 10 * Point;
    and this for SELL orders:
    Code (MQL4):
    sl = OrderOpenPrice() - 10 * Point;
    Of course, you can enter any amount of pips instead of 10.
     
    Last edited: Sep 28, 2015
  5. ForexNewbie51

    ForexNewbie51 Active Trader

    31
    2
    44
    Mnay thanks.

    I tried something close to this (and failed several times). Many thanks yet again for your help
     
  6. Maverick

    Maverick Master Trader

    323
    2
    59
    Realise I am a few years too late with my reply :( but others might pick up on it

    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 :)
    .
     
  7. slowpoison

    slowpoison Newbie

    4
    0
    2
    Yeah trailing stop would ideally do the job :p
     

Share This Page