Discussing the article: "Using the MQL5 Economic Calendar for News Filtering (Part 2): Stop Management Positions During News Releases"
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; } }
- 2026.02.18
- www.mql5.com
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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:
This ensures:
The mechanism remains rule-based.
Author: Solomon Anietie Sunday