I finally found a MT3-style super-bug in the MT4 backtester. Remember how in MT3 an stop/limit order placed at an invalid price would be accepted as a market order? Well MT4 fixed that, but they forgot to fix the same problem with modifying existing stop/limit orders. So until this is fixed (I've reported it to MQ), be very careful when modifying stop/limit orders in backtest. And until it's fixed, enjoy the attached sample code.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
//+------------------------------------------------------------------+ //| BadOrders.mq4 | //| Copyright © 2005, MetaQuotes Software Corp. | //| http://www.metaquotes.net | //+------------------------------------------------------------------+ #property copyright "Copyright © 2005, MetaQuotes Software Corp." #property link "http://www.metaquotes.net" double asdf; double ticket, t2; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- //This section closes any positions opened on the last tick OrderSelect(1,SELECT_BY_POS); OrderClose(OrderTicket(),1,Bid,8,Red); ticket=OrderSend(Symbol(),OP_BUYSTOP,1,Bid+100*Point,3,0,0,"asdfasdf",16384,0,Green); t2=OrderSelect(ticket,SELECT_BY_TICKET); OrderModify(OrderTicket(),Bid-100*Point,0,0,0,Green); //OrderClose(OrderTicket(),1,Bid,8,Red); // OrderSend(Symbol(),OP_BUYSTOP,1,Bid-100*Point,3,0,0,"asdfasdf",16384,0,Green); //---- return(0); } //+------------------------------------------------------------------+