Discussing the article: "Using the MQL5 Economic Calendar for News Filtering (Part 2): Stop Management Positions During News Releases"

 

Check out the new article: Using the MQL5 Economic Calendar for News Filtering (Part 2): Stop Management Positions During News Releases.

In part 2, we extend the news filter to protect existing positions during news events. Instead of closing trades, we temporarily remove stop-loss and take-profit levels, storing them safely in memory. When the news window ends, stops are deterministically restored, adjusted if price has already crossed the original levels, while respecting broker minimum distance rules. The result is a mechanism that preserves trade integrity without interfering with entry logic, keeping the EA in control through volatility.

The objective of Part 2 is strictly defined to temporarily suspend stop-loss and take-profit levels during the restricted news window and restore them safely once the window ends.

This approach does not attempt to interpret the direction of the news. It only prevents premature stop-outs caused by abnormal market conditions.

Principles of stop restoration

The restoration logic is deterministic:

  • If price has not crossed the original stored stop-loss or take-profit level, the stop is restored exactly at its original value.
  • If price has already moved beyond the original stop-loss level, the stop is restored at the nearest valid level just in front of the current price.
  • The same logic is applied to take-profit levels.

This ensures:

  • no invalid stop placement,
  • no broker rejection due to crossed price levels,
  • no restoration of logically impossible values, and
  • preservation of original trade structure whenever technically feasible.

The mechanism remains rule-based.

Author: Solomon Anietie Sunday

 

How I intend to use these functions:

I intend to use article Part One - Stopping new trades from opening or closing trades during the restricted news window, on all my EAs I have running on Prop Firms.

However Part 2 & Part3 - removing SL/TP and then replacing SL/TP , before/after the restricted news window, I intend to use this on a separate EA. Since this code iterates through the entire accounts open positions. I might have more than 1 chart open and don't need to run this more times than necessary. I will manual override the symbol selection to "USD, GBP, EUR" , since that is the only red folder news I know from experience I already have to filter for (it will be different for you).

So made a 1 line edit to RestoreStops() Function. 

SuspendStops() function didn't need an edit.

From the looks of things I won't need to Change anything from Part3, as all I need is the; ticket number, sl and tp.

Thank you very much  @Solomon Anietie Sunday 

I'll test it out live on demo !

// I won't need this if statement, in the 2nd EA, as the 2nd EA only modifies trades, 
// only need this is statement in the first EA (that opens trades)

if(!CanOpenNewTrade(_Symbol))
    return;
 
//+------------------------------------------------------------------+
//| Restore Stops After News (edited read article for original)      |
//+------------------------------------------------------------------+
bool RestoreStops(ulong ticket, double sl, double tp)
{
    if (!PositionSelectByTicket(ticket))
      return(false);
    string   symbol= PositionGetString(POSITION_SYMBOL);  // swapped the original variable '_Symbol' for 'symbol'
    ENUM_POSITION_TYPE type = (ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE);
    double price = (type == POSITION_TYPE_BUY) ?
        SymbolInfoDouble(symbol, SYMBOL_BID) :  //e.g. "_Symbol" is now symbol
        SymbolInfoDouble(symbol, SYMBOL_ASK);
        
    double point = SymbolInfoDouble(symbol, SYMBOL_POINT);
    
    double minStopDist = SymbolInfoInteger(symbol, SYMBOL_TRADE_STOPS_LEVEL) * point;

    // Safety check: If price has moved past the saved SL/TP, adjust to a valid level
    if(type == POSITION_TYPE_BUY)
    {
        if(sl != 0 && price <= sl)
            sl = price - minStopDist;
        if(tp != 0 && price >= tp)
            tp = price + minStopDist;
    }
    else // SELL
    {
        if(sl != 0 && price >= sl)
            sl = price + minStopDist;
        if(tp != 0 && price <= tp)
            tp = price - minStopDist;
    }

    // Full restore of stops 
    if(trade.PositionModify(ticket, sl, tp))
    {
        PrintFormat("Restored SL/TP for #%I64u | SL=%.5f, TP=%.5f", ticket, sl, tp);
        return true;
    }
    else
    {
        PrintFormat("Failed to restore SL/TP for #%I64u | Error=%d", ticket, GetLastError());
        return false;
    }
}
Discussing the article: "Using the MQL5 Economic Calendar for News Filtering (Part 1): Implementing Pre- and Post-News Windows in MQL5"
Discussing the article: "Using the MQL5 Economic Calendar for News Filtering (Part 1): Implementing Pre- and Post-News Windows in MQL5"
  • 2026.02.18
  • www.mql5.com
Check out the new article: Using the MQL5 Economic Calendar for News Filtering (Part 1): Implementing Pre- and Post-News Windows in MQL5...
 
Yes!, that’s a very effective approach. You can also use a magic number to block your specific EAs. However, focusing on the three main instruments you trade, especially those with the highest volatility can be a strong way to protect your overall portfolio.
The implementation in this article series can become highly flexible and customizable when done properly.
Testing can be done on historically (backtest), but it's tricky and takes some work. I will try to make that available in coming article for people who wants to backtest with news events.

You’re welcome, Philip. I’m always available if you’d like to discuss anything related to algorithmic trading.

Reply coming a bit late, I get busy sometimes.. sorry.