Getting the day of when an order was open

 

Hello,

I am trying to make a simple panel that will allow me to see the open trades taken today, but I can't seem to find code to do this. How can I determine the day a trade was opened, assuming it is still an open trade and in the terminal. I know I can use OrderOpenTime() to get the full date/time that the trade was opened on, but I'm looking to isolate only the day. Is this something we can do?


Thanks for the help.

 
yes MQL4 or MQL5 ?
 
Marco vd Heijden:
yes MQL4 or MQL5 ?
MQL4, sorry, didn't specify
 

Hello you can take the OrderOpenTime(), and then compare it with the desired target timing interval by using one of the following functions:

https://docs.mql4.com/dateandtime

Function

Action

TimeCurrent

Returns the last known server time (time of the last quote receipt) in the datetime format

TimeLocal

Returns the local computer time in datetime format

TimeGMT

Returns GMT in datetime format with the Daylight Saving Time by local time of the computer, where the client terminal is running

TimeDaylightSavings

Returns the sign of Daylight Saving Time switch

TimeGMTOffset

Returns the current difference between GMT time and the local computer time in seconds, taking into account DST switch

TimeToStruct

Converts a datetime value into a variable of MqlDateTime structure type

StructToTime

Converts a variable of MqlDateTime structure type into a datetime value

Day

Returns the current day of the month, i.e., the day of month of the last known server time

DayOfWeek

Returns the current zero-based day of the week of the last known server time

DayOfYear

Returns the current day of the year i.e., the day of year of the last known server time

Hour

Returns the hour of the last known server time by the moment of the program start

Minute

Returns the current minute of the last known server time by the moment of the program start

Month

Returns the current month as number, i.e., the number of month of the last known server time

Seconds

Returns the amount of seconds elapsed from the beginning of the current minute of the last known server time by the moment of the program start

TimeDay

Returns the day of month of the specified date

TimeDayOfWeek

Returns the zero-based day of week of the specified date

TimeDayOfYear

Returns the day of year of the specified date

TimeHour

Returns the hour of the specified time

TimeMinute

Returns the minute of the specified time

TimeMonth

Returns the month number of the specified time

TimeSeconds

Returns the amount of seconds elapsed from the beginning of the minute of the specified time

TimeYear

Returns year of the specified date

Year

Returns the current year, i.e., the year of the last known server time

Date and Time - MQL4 Reference
Date and Time - MQL4 Reference
  • docs.mql4.com
This is the group of functions for working with data of datetime type (an integer that represents the number of seconds elapsed from 0 hours of January 1, 1970).
 
#include <Tools\DateTime.mqh>
void OnStart()
{
   CDateTime time;
   time.DateTime(TimeCurrent());
   Print(time.DayName());
   Print(time.day);
   Print(time.day_of_week);
   Print(time.day_of_year);
}

Reason: