trading in a certain time

 
Can anyone please help me code for my EA to only trade between 7am and 11am /1PM and 4PM GMT. please could you explain the code so I can learn. much appreciated 
 
Hello you can find some examples here: https://www.mql5.com/en/docs/dateandtime
Documentation on MQL5: Date and Time
Documentation on MQL5: Date and Time
  • www.mql5.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).
 
Why do you want to trade on those hours ? Are gold hours or.. ?:)
 
Adam Woods:
Can anyone please help me code for my EA to only trade between 7am and 11am /1PM and 4PM GMT. please could you explain the code so I can learn. much appreciated 

You can copy and paste this function into your EA. but this code is for MT4.

bool enableTrade(){
  if(Hour() >= 7 && Hour() <= 11){
     return true;
  }
  return false;
}

7 and 11 is server time. You can change it accordingly.

After that, you use it to initiate a trade for example:

if(enableTrade() == true){
  //do your thing here...
}

Easy.

Good luck.

 
Ahmad Zuhairdi Noh:
  1. Simplify your code
    bool enableTrade(){
      return Hour() >= 7 && Hour() < 11;
    }

  2. OP asked for "between 7am and 11am" your code was [7am … 11:59:59]
 

i wrote something related to this and i discover that

 
this
   datetime c_Trade_1CloseTrades=StrToTime(Trade_1CloseTrades);
   datetime c_Trade_2CloseTrades=StrToTime(Trade_2CloseTrades);

work on strategy tester but not on Live Market .

so i use

this

string   today = TimeToStr(TimeCurrent(), TIME_DATE);
datetime c_Trade_1CloseTrades=StringToTime(today+" "+TimeToStr(StringToTime(Trade_1CloseTrades), TIME_MINUTES));
datetime c_Trade_2CloseTrades=StringToTime(today+" "+TimeToStr(StringToTime(Trade_2CloseTrades), TIME_MINUTES));
 
Ahmad Zuhairdi Noh:

You can copy and paste this function into your EA. but this code is for MT4.

7 and 11 is server time. You can change it accordingly.

After that, you use it to initiate a trade for example:

Easy.

Good luck.

thanks. I'll give it a try. 
Reason: