OrderSelect behaviour

 
In the manual it is said that
The OrderSelect() function copies order data into program environment and all further calls of OrderClosePrice(), OrderCloseTime(), OrderComment(), OrderCommission(), OrderExpiration(), OrderLots(), OrderMagicNumber(), OrderOpenPrice(), OrderOpenTime(), OrderPrint(), OrderProfit(), OrderStopLoss(), OrderSwap(), OrderSymbol(), OrderTakeProfit(), OrderTicket(), OrderType() functions return the data, copied earlier. It means that in some cases the order details (open price, SL/TP levels or expiration date) may change and the data become non-actual. It is strongly recommended to call the OrderSelect() function before request the order data.

I've faced with a problem when in the OrderSelect function some calculations are being made before the order is modified or before new order is opened according to the returned info of mentioned above calls. EA is attached on each pair and is prohibited to trade all the pairs except the only one that it is attached to via comparison of OrderSymbol()==Symbol(). Most of the time everything is done correctly but there're some situations when the EA's from different charts are operating with different orders at the same time and by mistake, let's say the EURUSD order is being modified from the EA that is attached to AUDUSD chart or the EA logic may copy the OrderOpenPrice() from the other pair. In the quote from the documentaion that I've posted above it's only mentioned that OrderSelect copies data in program environment. So does it mean that although the EA on each chart is prohibited to operate with orders of other pairs there may occur such a situation because the program environment means that it is applied to all the MT4 terminal?
 
.roman.: So does it mean that although the EA on each chart is prohibited to operate with orders of other pairs
  1. No it selects orders. It is up to your code to filter out other orders.
  2. order accounting - MQL4 forum
 
the code is
for(int i=OrdersTotal()-1;i>=0;i--)
        {
            if(OrderSelect(i,SELECT_BY_POS) && OrderSymbol()==Symbol() && OrderMagicNumber()==magic)
               {
                  if(OrderType()==OP_BUY)
                     {
                        double openPrice = 0;
                        openPrice = OrderOpenPrice();
                        if(Ask>openPrice)
                           {
                              //trading logic
                              //For current visualization I've implemented a Print function that is showing OrderSymbol() and OrderOpenPrice()
                              //and occasionally it returns other pairs with the open prices of orders on these pairs
                           }
                     }
                  if(OrderType()==OP_SELL)
                     {
                        //opposite logic
                     }
               }
        }
99% of the time it's doing its job but sometimes as mentioned above it can Select orders from other pairs.
 
.roman.:
the code is99% of the time it's doing its job but sometimes as mentioned above it can Select orders from other pairs.
It's not possible. Please post some clues of your problem.
 
angevoyageur:
It's not possible. Please post some clues of your problem.

As mentioned in the first post the EA is attached to several charts. In the code that I've posted the EA is checking for existence of Buy\Sell orders of the same Symbol that the EA is attached to and according to its Open Price is doing something. After getting some incorrect results I've implemented a Print function in it that is showing the OrderSymbol and OrderOpenPrice and rarely (I suppose it happens when at the same time EA on other symbol is managing the orders via OrderSelect function and "copies order data into program environment") there occured a situation like that:


despite the fact that on the current chart there is an exceptional comparison of OrderSymbol and Symbol.

 

The code that you have posted actually does nothing.

Show the code that creates the print 

 
GumRai:

The code that you have posted actually does nothing.

Show the code that creates the print 

Print("OrderSymbol ",OrderSymbol()," OrderTicket ",OrderTicket()," OrderOpenPrice ",OrderOpenPrice());
 

That reveals nothing.

You need to show the whole block of code that incorporates the print 

 
GumRai:

That reveals nothing.

You need to show the whole block of code that incorporates the print 

for(int i=OrdersTotal()-1;i>=0;i--)
        {
            if(OrderSelect(i,SELECT_BY_POS) && OrderSymbol()==Symbol() && OrderMagicNumber()==magic)
               {
                  if(OrderType()==OP_BUY)
                     {
                        double openPrice = 0;
                        openPrice = OrderOpenPrice();
                        if(Ask>openPrice)
                           {
                              Print("OrderSymbol ",OrderSymbol()," OrderTicket ",OrderTicket()," OrderOpenPrice ",OrderOpenPrice());
                           }
                     }
                  if(OrderType()==OP_SELL)
                     {
                        double openPrice = 0;
                        openPrice = OrderOpenPrice();
                        if(Bid<openPrice)
                           {
                              Print("OrderSymbol ",OrderSymbol()," OrderTicket ",OrderTicket()," OrderOpenPrice ",OrderOpenPrice());
                           }
                     }
               }
        }


That's everything that is related to the topic and the mentioned problem.

 
And you are absolutely certain that you have no other similar print functions elsewhere in your code?
 
GumRai:
And you are absolutely certain that you have no other similar print functions elsewhere in your code?
Yes, absolutely.
Reason: