How to put Stop Loss in ths EA?

How to put Stop Loss in ths EA?

I just get this from internet, it work well.

The problem is it didn’t have stop loss and cannot control lots size.

So please anyone tell me how? Thanks

//---- input parameters
extern int min_gapsize = 1;
extern double lotsize_gap = 0.1;
//----
datetime order_time = 0;
//±-----------------------------------------------------------------+
//| expert initialization function |
//±-----------------------------------------------------------------+
int init()
{
//----
return(0);
}
//±-----------------------------------------------------------------+
//| expert deinitialization function |
//±-----------------------------------------------------------------+
int deinit()
{
//----
return(0);
}
//±-----------------------------------------------------------------+
//| expert start function |
//±-----------------------------------------------------------------+
int start()
{
/*
Thing to be done in future in this program to make it more efficient
and more powerful:

  1. Make the dicission of the quantity of lots used according to
    the scillators;
  2. This program will catch the gaps.
    Things to ware of:
  3. the spread;
  4. excuting the order not on the gap ends a little bit less.
    */
    // Defining the variables to decide.
    Print(“order time”, order_time);
    double current_openprice = iOpen(Symbol(), PERIOD_M15, 0);
    double previous_highprice = iHigh(Symbol(), PERIOD_M15, 1);
    double previous_lowprice = iLow(Symbol(), PERIOD_M15, 1);
    double point_gap = MarketInfo(Symbol(), MODE_POINT);
    int spread_gap = MarketInfo(Symbol(), MODE_SPREAD);
    datetime current_time = iTime(Symbol(), PERIOD_M15, 0);
    // catching the gap on sell upper gap
    if(current_openprice > previous_highprice + (min_gapsize + spread_gap)point_gap &&
    current_time != order_time)
    {
    int ticket = OrderSend(Symbol(), OP_SELL, lotsize_gap, Bid, 0, 0,
    previous_highprice + spread_gap
    point_gap,
    "", 4, 0, Red);
    order_time = iTime(Symbol(), PERIOD_M15, 0);
    Print(“I am inside (sell) :-)”, order_time);
    //----
    if(ticket < 0)
    {
    Print(“OrderSend failed with error #”, GetLastError());
    }
    }
    //catching the gap on buy down gap
    if(current_openprice < previous_lowprice - (min_gapsize + spread_gap)point_gap &&
    current_time != order_time)
    {
    ticket = OrderSend(Symbol(), OP_BUY, lotsize_gap, Ask, 0, 0,
    previous_lowprice - spread_gap
    point_gap,
    "", 5, 0, Green);
    order_time = iTime(Symbol(), PERIOD_M15, 0);
    Print(“I am inside (buy) :-)”, order_time);
    if(ticket < 0)
    {
    Print(“OrderSend failed with error #”, GetLastError());
    }
    }
    //----
    return(0);
    }
    //+

Hallo,

Here you go! => Free File Hosting - Online Storage; Upload Mp3, Videos, Music. Backup Files

Notes:

  1. Lot size and SL can be modified after putting the EA on the chart.

extern int min_gapsize = 1;
extern double lotsize_gap = 0.1; -----------> this is the LOT SIZE
extern double stop_loss = 50; --------------> this is the STOP LOSS in proper pips (e.g 50pips)

  1. This will NOT work on an ECN-style broker ( where the SL and TP are set [B]after[/B] opening the trade using OrderModify )

Cheers

PS: you are right, this little gem has some potential :slight_smile:

I modified yours a bit and came up with the attached (see below)

Main difference: instead of a TP, I’ve put a JUMPING STOP (default: every 10pips). SL is 50pips. [ I know, SL sounds crazy, but for EURUSD and USDCHF, no loss this entire year, and decent returns ( +40% ) ]

Cheers

Gappy dudest version: Free File Hosting - Online Storage; Upload Mp3, Videos, Music. Backup Files

Cheers

1 Like

PS: from the original you posted, I deduced that the working Timeframe is M15. That is what I have also tested on

.

Wow man its good.

Thanks you very much.

I think this EA is great and profitable

ya,the 3rd floor on. this got some mistake. The Stop Loss fix on 0.0050 which it should be 1.2250.

Hello please I couldn’t get the EA from the link you posted can you help me out please