mql4mt4

'Hour' - wrong parameters count - mql4


I am attempting to restrict the hours during which trading can occur, but I have not been successful with my attempts so far. I would appreciate any input or suggestions on how to accomplish this.

// Function to Check if Trade Time is Valid
bool IsTradeTime() {
    datetime now = TimeCurrent();
    int hour = Hour(now);

Error: 'Hour' - wrong parameters count


Solution

  • //Global Variable
    input string baslangicZamani= "08:00";
    input string bitisZamani="23:00";
    //+------------------------------------------------------------------+
    bool ZamanFiltresi()
      {
       datetime _mevcutZaman = TimeCurrent();
       datetime _zamanIlk = StringToTime(TimeToString(_mevcutZaman,TIME_DATE) + " " + baslangicZamani);
       datetime _zamanSon = StringToTime(TimeToString(_mevcutZaman,TIME_DATE) + " " + bitisZamani) + 60;
       if(_zamanIlk>_zamanSon)
         {
          if(_mevcutZaman >= _zamanIlk || _mevcutZaman <= _zamanSon)
             return (true);
          else
             return (false);
         }
       if(_zamanIlk<_zamanSon)
         {
          if(_mevcutZaman >= _zamanIlk && _mevcutZaman <= _zamanSon)
             return (true);
          else
             return (false);
         }
       return (false);
      }