OrderCloseTime() writing incorrect time with other Order Functions are writing correctly

 

Hello - I have copied a snippet of my code below. It is attempting to write a bunch of order information to file upon closing a trade. The order functions I use (OrderTicket(),OrderSymbol(),Order_Type,OrderOpenPrice(),OrderClosePrice(), etc) all write the correct values to file. However OrderCloseTime() is writing 1970.01.01 00:00:00 for every trade, even as the OrderOpenTime returns the correct value. Note that I am running this in the strategy tester, not on a live account.

      if(OrderSelect (x, SELECT_BY_POS, MODE_TRADES)) {

      

         if(OrderMagicNumber() != MagicNumber) 

            continue;

         if(OrderSymbol() != Symbol())

            continue;

            

            //Update profit valve with the OrderProfit trade function

            Profit += OrderProfit();

            

            //Update the trade count

            TotalNumberOfTrades = TotalNumberOfTrades + 1;

            

            //Set the buy and sell prices to the open price of selected order, + or - our pip spread. 

            if(OrderType() == 1) {

               Order_Type = OrderType(); 

               SellPrice = OrderOpenPrice() + (TradeToPipSpread * PointValue);

            }

            if(OrderType() == 0) {

               Order_Type = OrderType(); 

               BuyPrice = OrderOpenPrice() - (TradeToPipSpread * PointValue);

            }

         }

      }



      if(TotalNumberOfTrades == 1 && Profit >= LOneProfit) {

         Print("Profit is "+DoubleToStr(Profit, 3));

         CloseTrades();

                              

         long TradeDuration = OrderOpenTime() - OrderCloseTime();

                     

                     int FileHandle = FileOpen("Tester Sells Data.csv", FILE_READ|FILE_WRITE|FILE_CSV, ',');

                     if(FileHandle != INVALID_HANDLE)

                        {

                        FileSeek(FileHandle, 0, SEEK_END);

                  

                        //write data by column

                        FileWrite(FileHandle, OrderTicket(),OrderSymbol(),Order_Type,OrderOpenPrice(),OrderClosePrice(), OrderOpenTime(), OrderCloseTime(), TradeDuration);                   

                        FileClose(FileHandle);

                        Print("FileOpen Successful");

                        }

                           else Print("Operation FileOpen failed, error ",GetLastError());

         return;

         }
The Fundamentals of Testing in MetaTrader 5
The Fundamentals of Testing in MetaTrader 5
  • www.mql5.com
The idea of ​​automated trading is appealing by the fact that the trading robot can work non-stop for 24 hours a day, seven days a week. The robot does not get tired, doubtful or scared, it's is totally free from any psychological problems. It is sufficient enough to clearly formalize the trading rules and implement them in the algorithms, and...
 
Noka720: However OrderCloseTime() is writing 1970.01.01 00:00:00 for every trade,
  1. Why did you post your MT4 question in the MT5 EA section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum?
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum 2019.05.06
              Messages Editor

  3. Of course, it is. You are reading open orders, therefor there is no OrderCloseTime.
 
William Roeder:
  1. Why did you post your MT4 question in the MT5 EA section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum?
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum 2019.05.06
              Messages Editor

  3. Of course, it is. You are reading open orders, therefor there is no OrderCloseTime.
Thanks Will - I just took TimeCurrent() when I closed the trade and used that and am good to go now. I'll make sure and post in the right spot next time.
 
William Roeder:
  1. Of course, it is. You are reading open orders, therefor there is no OrderCloseTime.
Will - While I solved the original issue and what I was trying to do, as I think more about your response it isn't making sense to me. The function OrderClosePrice() is returning the price I closed at. How can I get the close price of an order but not the close time? Can you elaborate on what I am missing?
 
Noka720:
Will - While I solved the original issue and what I was trying to do, as I think more about your response it isn't making sense to me. The function OrderClosePrice() is returning the price I closed at. How can I get the close price of an order but not the close time? Can you elaborate on what I am missing?

You are not making any sense!

The function OrderClosePrice() is returning the price I closed at.

What do you expect it to return??

If the order is closed, it returns the close price.

If the order is open it returns the current price (Ask for a sell, Bid for a buy).

 
Noka720 How can I get the close price of an order but not the close time? Can you elaborate on what I am missing?

You are reading open orders. OrderClosePrice is the current market. OrderCloseTime is zero. What part of “open orders” is unclear?

      if(OrderSelect (x, SELECT_BY_POS, MODE_TRADES)) {
Reason: