TimeManagement – library MetaTrader 4

Time management functions are often used in Expert Advisors and Scripts. This header file contains functions and input variables for checking time and day of week.

Function Description
bool CheckTime()

The function checks current time and returns true when trade is allowed, false – trade is not allowed.

It uses input variables:

  • UseTimeManagement – Enable/disable time management. If true is enabled, false – disabled
  • StartHour – Trading start hour (0-24)
  • StartMinutes – the trading start minutes (0-59)
  • EndHour – End hour (0-24) of trade
  • EndMinutes – End hour (0-24) of trade.
bool CheckDayOfWeek()

The function checks week day returns true when trade is allowed, false – trade is not allowed.

It uses input variables:

  • UseDayManagement – Enable/disable day management. If true is enabled, false – disabled
  • TradeMonday – On/off trade on Monday. True – on, false – off.
  • TradeTuesday – On/off trade on Tuesday.
  • TradeWednesday – On/off trade on Wednesday.
  • TradeThursday – On/off trade on Thursday.
  • TradeFriday – On/off trade on Friday.
Alternative:  Example of Commodity Channel Index Automated - EA MetaTrader 4

Example

#include <TimeManagement.mqh>

void OnTick()
{
   if( !CheckTime() )
   {
      Print("The trade is not allowed by time management");
      return;
   }

   if( !CheckDayOfWeek() )
   {
      Print("The trade is not allowed in this day of week");
      return;
   }
}
📈 ROBOTFX MetaTrader Expert Advisors and Indicators to maximize profits and minimize the risks