Selecting last order opened - page 3

 
Fernando Carreiro:

Thanks Fernando 

I opened a trade to try the code , and I had a large number  12054 

I though it should be somewhere from 1 to 6 ?

 
Alpha Beta: I opened a trade to try the code , and I had a large number  12054 I though it should be somewhere from 1 to 6 ?
Show your code! We can't just guess what you are doing wrong if you don't show it.
 
  
    int x = OrdersTotal();
    for (int i = 0; i < x; i++)
    {
        if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
        {
            if ( OrderMagicNumber() == magic &&  OrderType() < 2 && OrderOpenTime() > 0)
                {
                    
                    int_OrderOpenDayOfWeek = TimeDayOfWeek( OrderOpenTime());
                    db_OrdOpenPrice        = OrderOpenTime();
                    OpenOrdertype          = OrderType();
                    OpenOrderLot           = OrderLots();
                }
        }
    }

Fernando Carreiro:
Show your code! We can't just guess what you are doing wrong if you don't show it.

I added the code 

 
Alpha Beta: I added the code 

That is incomplete. Show how you are testing it's value or printing it out.

EDIT: There is also another problem with your code:

db_OrdOpenPrice = OrderOpenTime(); // Assigning a datetime to a Price variable?????
 
Alpha Beta: I added the code 
  1. That's not the code you used to get the bogus number. No print statement.
  2. Show all relevant code. We have no idea what int_OrderOpenDayOfWeek, OpenOrderLot, etc. are.
  3. If the OrderType is less than 2, it is an open order (Buy or Sell). No need to check the OpenTime.
  4. Why are you assigning the time to a double price?
  5.     int x = OrdersTotal();
        for (int i = 0; i < x; i++)

    In the presence of multiple orders (one EA multiple charts, multiple EAs, manual trading), while you are waiting for the current operation (closing, deleting, modifying) to complete, any number of other operations on other orders could have concurrently happened and changed the position indexing and count:

    1. For non-FIFO (non-US brokers), (or the EA only opens one order per symbol), you can simply count down, in a position loop, and you won't miss orders. Get in the habit of always counting down.
                Loops and Closing or Deleting Orders - MQL4 programming forum
    2. For In First Out (FIFO rules — US brokers), and you (potentially) process multiple orders per symbol, you must find the earliest order (count up), close it, and on a successful operation, reprocess all positions.
                CloseOrders by FIFO Rules - Strategy Tester - MQL4 programming forum - Page 2 #16
                MetaTrader 5 platform beta build 2155: MQL5 scope, global Strategy Tester and built-in Virtual Hosting updates - Best Expert Advisors - General - MQL5 programming forum #1.11


 

My bad I was printing the line of the code next to the day 

Alert( int_OrderOpenDayOfWeek , __LINE__);

this solve it 

Alert( int_OrderOpenDayOfWeek + " | ", __LINE__);

Thanks a lot Fernando and William

 
Alpha Beta:

My bad I was printing the line of the code next to the day 

Alert( int_OrderOpenDayOfWeek , __LINE__);

this solve it 

Alert( int_OrderOpenDayOfWeek + " | ", __LINE__);

Thanks a lot Fernando and William

You are welcome!
Reason: