Incorrect order information sent into market

 

Hi,

I've a weired behaviour in my VPS MT5 compared to my local computer

the codes is used to reopen orders that I already stored into a database, the issue that I have is the values that I use in trade.OrderOpen function is the right one  buth in my VPS (where I only have my ex5 and my database) I get an incorrect instrument and buy price (the instrument from positions opening but always get a unkown price)


Here is the code

//+------------------------------------------------------------------+
//| Reopen orders                                                    |
//+------------------------------------------------------------------+
   if(!cDb.readOrdersFromDB("rollover.db", "orders", orderArray))
     {
      for(int i=0; i < orderArray.Size(); i++)
        {
         // calculate the order price using the saved difference with urrent price
        
         double reopenPrice=0.0, reopenSL=0.0, reopenTP=0.0;
         double ask = SymbolInfoDouble(orderArray[i].orderSymbol,SYMBOL_ASK);
         double bid = SymbolInfoDouble(orderArray[i].orderSymbol,SYMBOL_BID);
         // i noticed, at the begining of the session for unliquid instruments the ASK/BID prices returns sometimes 0
         // I use last tick value to ensure I have a reference to place my orders
         //-------------------
         ArrayFree(tick);
         SymbolInfoTick(orderArray[i].orderSymbol, tick[0]); // get the last tick data 
         if(ask == 0)
            ask = tick[0].ask;
         if(bid == 0)
            bid = tick[0].bid;
         //-------------------  
         
         if(orderArray[i].orderPrice > 0)  // sell limit/stop
           {
            // adjust price, TP SL bu the difference recored when the order is closed and take in account if it's buy limit (below price) or sell limit (above price) and the spread
            reopenPrice =  NormalizeDouble(orderArray[i].orderPrice + ask, 2);
            if(orderArray[i].orderSL != 0)
               reopenSL    =  NormalizeDouble(orderArray[i].orderSL + ask, 2);
            if(orderArray[i].orderTP != 0)
               reopenTP    =  NormalizeDouble(orderArray[i].orderTP + ask, 2);
           }
         else // buy limit/stop
           {
            reopenPrice =  NormalizeDouble(orderArray[i].orderPrice + bid, 2);
            if(orderArray[i].orderSL != 0)
               reopenSL    =  NormalizeDouble(orderArray[i].orderSL + bid, 2);
            if(orderArray[i].orderTP != 0)
               reopenTP    =  NormalizeDouble(orderArray[i].orderTP + bid, 2);
           }
         PrintFormat("symbol:%s\nreopenPrice:%.2f\nreopenSL:%.2f\nreopenTP:%.2f", orderArray[i].orderSymbol,reopenPrice, reopenSL, reopenTP);

         bool orderOpenResult = trade.OrderOpen(orderArray[i].orderSymbol, (ENUM_ORDER_TYPE)orderArray[i].orderType, orderArray[i].orderVolume, reopenPrice, reopenPrice, reopenSL, reopenTP, ORDER_TIME_GTC, 0, orderArray[i].orderComment);
         if(orderOpenResult)
           {
            msg = StringFormat("\nOrder %lu re-opened successfully", orderArray[i].orderTicket);
            mailReport += "\n"+msg;
            if(cDebug)
               PrintFormat(msg);
            cDb.updateReOpenFlag("rollover.db","orders", 0, orderArray[i].orderTicket); // update the reopen flag to disable the order
           }
         else
           {
            // Unable to reopn orders
            msg = StringFormat("Unable to re-open %lu, ERR: %u", orderArray[i].orderTicket, trade.ResultRetcode());
            errorMessages +=msg+"\n";
            PrintFormat(msg);
            bool reopenErrors = true;

           }
         msg = StringFormat("OrderTicket: %lu\n    Instrument: %s\n    Price:    %.2f\n    Order time:    %s\n    Order type:    %d\n    Order SL = %.2f\n    Order TP = %.2f\n    Volume   = %.2f\n    Comment= %s",
                            orderArray[i].orderTicket, orderArray[i].orderSymbol, reopenPrice, TimeToString(OrderGetInteger(ORDER_TIME_SETUP)-TimeGMTOffset(),TIME_DATE|TIME_MINUTES|TIME_SECONDS), orderArray[i].orderType, reopenSL, reopenTP, orderArray[i].orderVolume, orderArray[i].orderComment);
         mailReport += "\n"+msg;
         if(cDebug)
            PrintFormat(msg);
        }      
     }

 

if I execute this code in my local computer I get

2024.07.14 23:19:00.319    Trades    '1471576': buy stop 1 MNQZ24 at 21041.00 (21041.00)
2024.07.14 23:19:00.367    Trades    '1471576': accepted buy stop 1 MNQZ24 at 21041.00 (21041.00)
2024.07.14 23:19:00.368    Trades    '1471576': order #264238644 buy stop 1 / 1 MNQZ24 at 21041.00 done in 49.116 ms

the same code compiled in ex5 executed in my VPS computer I get :

2024.07.14 23:49:00.208    Trades    '1471449': buy stop 1 MNQZ24 at 20874.25 (20874.25)
2024.07.14 23:49:00.233    Trades    '1471449': accepted buy stop 1 MNQZ24 at 20874.25 (20874.25)
2024.07.14 23:49:00.233    Trades    '1471449': order #264238745 buy stop 1 / 1 MNQZ24 at 20874.25 done in 25.090 ms
2024.07.14 23:49:00.270    Trades    '1471449': failed exchange buy 1 MNQU24 at 20534.88 [Invalid price]


in the code attached I put print the values that I pass to the OrderOpen function to be suure and here is the print


2024.07.14 23:49:00.208    rollover (MNQU24,M1)    symbol:MNQZ24
2024.07.14 23:49:00.208    rollover (MNQU24,M1)    reopenPrice:20874.25
2024.07.14 23:49:00.208    rollover (MNQU24,M1)    reopenSL:0.00
2024.07.14 23:49:00.208    rollover (MNQU24,M1)    reopenTP:0.00

so completely different from what the function sends into market


I suspect that OrderOpen send something from a cash or an old transaction? Did I forget to clear something before sending the order open?

Any idea ?

 

even If I send a seell order, for some reason the MT5 send buy order with the same values, crazy thing :o( 


2024.07.15 00:28:00.381    Trades    '1471449': sell stop 1 MNQZ24 at 20818.50 (20818.50)
2024.07.15 00:28:00.406    Trades    '1471449': accepted sell stop 1 MNQZ24 at 20818.50 (20818.50)
2024.07.15 00:28:00.406    Trades    '1471449': order #264238885 sell stop 1 / 1 MNQZ24 at 20818.50 done in 25.210 ms
2024.07.15 00:28:00.427    Trades    '1471449': failed exchange buy 1 MNQU24 at 20534.88 [Invalid price]

 
Translator

I found the issue, it's due to the fact  that orders and position opening need to use ask and bid prices to avoid wrong prices, in my cas the opening process failed to open a position, the database was not updated and thus the position opening get stuck in wrong value

Thanks