How to prevent EA open new trade when previous trade hit sl?

To add comments, please log in or register
Eng Keat Ang
2016
Eng Keat Ang  
How to prevent EA open new trade when previous trade hit sl?

My ea code :

    double D110RecentBarHighest;
    double D110RecentBarLowest;
    D110RecentBarHighest = iHigh(Symbol(),0,iHighest(NULL,0,MODE_HIGH,110,5));
    D110RecentBarLowest = iLow(Symbol(),0,iLowest(NULL,0,MODE_LOW,110,5));
    
    if (Close[1] > D110RecentBarHighest && buytotal==0 ){
        openBuyTrade();
    }
    
    if (Close[1] > D110RecentBarLowest && selltotal==0){
        openSellTrade();
    }

Soewono Effendi
2142
Soewono Effendi  
Eng Keat Ang:
How to prevent EA open new trade when previous trade hit sl?

My ea code :




Trades hitting stoploss would normally have "sl" in trade history comment, maybe you can check that before opening new trade ?

William Roeder
20233
William Roeder  
  1. Soewono Effendi: Trades hitting stoploss would normally have "sl" in trade history comment, maybe you can check that before opening new trade ?
    Some brokers do not put SL in the comment. Not a good idea to use comments, brokers can change comments, including complete replacement.

  2. Eng Keat Ang: How to prevent EA open new trade when previous trade hit sl?
        if (Close[1] > D110RecentBarHighest && buytotal==0 ){
    You are looking at a signal. Act on a change of signal.
              MQL4 (in Strategy Tester) - double testing of entry conditions - Strategy Tester - Expert Advisors and Automated Trading - MQL5 programming forum
Seng Joo Thio
1216
Seng Joo Thio  
Eng Keat Ang:
How to prevent EA open new trade when previous trade hit sl? 

Iterate through all closed trades (OrdersHistoryTotal()), get the most recent one (OrderCloseTime()), check it's close price (OrderClosePrice()) against open price (OrderOpenPrice()) to determine whether it was stopped out by stop loss, then pass this information on to supplement the trade opening conditions in your existing EA code.

To add comments, please log in or register