HotForex Partners Solutions

Seri hàm chức năng cho Meta Trader

- Advertisement -HotForex PAMM

Hàm Time management được sử dụng trong Expert Advisors and Scripts. Tập tin này chứa các hàm và các biến đầu vào để kiểm tra thời gian và ngày trong tuần.

Hàm chức năngMô tả
bool CheckTime()Chức năng kiểm tra thời gian hiện tại và trả về giá trị true khi được phép, false khi kết quả trả về là sai.

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

Các biến đầu vào:

  • 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.

 

Cách sử dụng:

#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;
   }
}

Code:

//+------------------------------------------------------------------+
//|                                               TimeManagement.mqh |
//|                                               Forex Support 2017 |
//|                                          support@forexsupport.vn |
//+------------------------------------------------------------------+
#property copyright "Forex Support 2017"
#property link      "support@forexsupport.vn"
#property strict

input bool    UseTimeManagement    = true; //Enable/disable time management
input int     StartHour            = 10;   //Start hour (0-24) of trade
input int     StartMinutes         = 00;   //Start minutes (0-59) of trade
input int     EndHour              = 21;   //End hour (0-24) of trade
input int     EndMinutes           = 00;   //End hour (0-24) of trade
input bool    UseDayManagement     = false;//Enable/disable day management
input bool    TradeMonday          = true; //On/off trade on monday
input bool    TradeTuesday         = true; //On/off trade on tuesday
input bool    TradeWednesday       = true; //On/off trade on wednesday
input bool    TradeThursday        = true; //On/off trade on thursday
input bool    TradeFriday          = true; //On/off trade on friday
//+-------------------------------------------------------------------+
//|  The function checks time for a trade.                            |
//|  It returns true - trade is allowed, false - trade is not allowed |                                                             
//+-------------------------------------------------------------------+
bool CheckTime()
  {
   bool result=false;

   if(UseTimeManagement)
     {
      datetime curr_time=TimeCurrent(),start_time=StrToTime(StringConcatenate(StartHour,":",StartMinutes)),
      end_time=StrToTime(StringConcatenate(EndHour,":",EndMinutes));

      if((end_time>start_time && start_time<=curr_time && end_time>=curr_time)
         || (end_time<=start_time && (start_time<=curr_time || end_time>=curr_time)))
         result=true;
     }
   else
      result=true;

   return result;
  }
//+-------------------------------------------------------------------+
//|  The function checks week day for a trade.                        |
//|  It returns true - trade is allowed, false - trade is not allowed |                                                             
//+-------------------------------------------------------------------+
bool CheckDayOfWeek()
  {
   bool result=false;

   if(!UseDayManagement)
      result=true;
   else
     {
      int day_week=DayOfWeek();

      if(TradeMonday && day_week==1)
         result=true;
      if(TradeTuesday && day_week==2)
         result=true;
      if(TradeWednesday && day_week==3)
         result=true;
      if(TradeThursday && day_week==4)
         result=true;
      if(TradeFriday && day_week==5)
         result=true;
     }

   return result;
  }
//+------------------------------------------------------------------+
HotForex Bonus