Wicked out in a single tick microsecond on GBPJPY for -45 pips on June 1st.

 

2023.06.01 20:13:41.782 '4117408': order #67975146 buy stop 0.02 GBPJPY.pro at 174.085 activated at price 174.090

2023.06.01 20:13:41.782 '4117408': order #67940641 sell 0.02 GBPJPY.pro at 172.947 closed due stop-loss at price 174.090

Note: order numbers change when a pending order is filled.


I think there was News at this time with a yellow code? not sure.

In any case the spread must have spiked to around 12 pips and filled it at the Ask price and immediately hit the stop for -45pips or 450 points.

The tester in MT4 was not able to test for such an incident, not sure if MT5 can either.


But are there any countermeasures that could be employed by a robot?

Perhaps checking the spread and closing pending orders out when above a threshold value? 

Unfortunately not able to test the theory in the MT4 tester.

Just asking for any input or thoughts.

Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Order Properties - Trade Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

Some options are ...

  • Don't use pending orders. Use Market orders instead. Given that its an EA and not a human, it can easily monitor prices 24/7 and carry out the actions as programmed.
  • Monitor spread and volatility and apply whatever rules are required.
  • Analyse news calender and don't trade during events that could affect volatility of the symbol in question.

EDIT: On MT5, you can back-test with real tick data, including during historical news events with high volatility where spread widened.

Given that this is a MT4 question, your topic has been moved to the section: MQL4 e MetaTrader 4 — In the future, please consider which section is most appropriate for your query.
 
As discussed with user in private, the topic has been moved to the section: Expert Advisors and Automated Trading.
 

I performed another test and that trade eventually closed in loss anyway, so I probably don't need to do anything.  Just accept the risks.