Classes for setting and checking trading time - MetaTrader 5 Library | MT5 EA Download - MetaTrader 5 Resources
The CTimeControl class is included into your EA to easily set and check your own trading times.
Usage example:
#include "timecontrol.mqh"
Default constructor:
CTimeControl time control;
Or a constructor with a number of days:
CTimeControl time control ( wrong , true , true , wrong , wrong , wrong , wrong );
Or a constructor with an array of days settings and an array of trading hours per day:
Boolean value arrDaysSetting[7] = { false , true , true , false , false , false , false };
Integer arrStartHours[7] = {0, 15, 14, 0, 0, 0, 0};
Double arrStartMinutes[7] = {0, 15, 14, 0, 0, 0, 0};
Integer arrStopHours[7] = {23, 13, 21, 23, 23, 23, 23};
Double arrStopMinutes[7] = {0, 15, 14, 0, 0, 0, 0};
CTimeControl timeControl2( arrDaysSetting, arrStartHours, arrStartMinutes, arrStopHours, arrStopMinutes);
For daily get/set parameters, you can use functions with the ENUM_DAY_OF_WEEK index to get the date you want to set/get:
Boolean bMonday = timeControl.GetDay( Monday );
timeControl.SetDay( Monday , true ); // enable on Monday
timeControl.EnableDay( Monday ); // enable on Monday
timeControl.DisableDay( Monday ); // disable Monday
Integer iStartHour, iStopHour;
Double d starts minutes, d stops minutes;
timeControl.GetTradingTime( Monday , iStartHour, dStartMinute, iStopHour, dStopMinute);
Or you can check every day using a defined function:
Boolean value bMonday = timeControl.GetMonday();
timeControl.SetMonday( true ); //Enable on Monday
timeControl.EnableMonday(); //Disable Monday
timeControl.DisableMonday(); //Disable Monday
Main function to check if trading time is enabled (using current server time)
if (timeControl.IsTradingTime() == true )
{
//do something
}
{
//do something
}
Or you can check your own datetime:
datetime date = D'24.02.2015 12:30:27' ;
if (timeControl.IsTradingTime(date) == true )
{
//do something
}
Others
{
//do something
}
Attachment download
📎 timecontrol.mqh (19.99 KB)
Source: MQL5 #12484
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •