How to restrict trading times in a day?

 

Hello,


First of all, i apologize my English skills.


anyway, my question is same with title "how to restrict trading times in a day?"


i used things such like 'TimeDay(TIme[0]) != TimeDay(Time[1]' and 'OrdersHistoryTotal'.


BUT those aren't work very well.


if any ideas about restrict trading times, PLEASE speak to me.


Thanks.

 

The thing is not easy as you think specially when you use others code.

Ok. I will send you the whole code I used to use  and you try to solve the puzzle.


input bool        UseTimeFilter = true; 
input int             StartHour = 6;   
input int               EndHour = 18; 

bool EA_Activated;
string cTF = "";

void start(){
   ...
   ...
   ...

   if((Hour()>=StartHour && Hour()<EndHour && StartHour<EndHour) || ((Hour()>=StartHour || Hour()<EndHour) && StartHour>EndHour))
      {EA_Activated=true; cTF = "Trading Time !";}
   else
      {EA_Activated=false; cTF = "Not Trading Time !";}
   
   if(!UseTimeFilter) cTF = "Trading Time !";

   //From here, do whatever you want to do considering
   //EA_Activated is True or False.

   ...
   ...
   ...
}

 
I'd allow fractional hours.
#define HR2400 86400
#define SECONDS uint
SECONDS    time(datetime when=0){
      return SECONDS(when == 0 ? TimeCurrent() : when) % HR2400;               }
datetime   date(datetime when=0){
      return datetime( (when == 0 ? TimeCurrent() : when) - time(when) );      }
bool       isValidTime(SECONDS start, SECONDS end, datetime when=0){
   SECONDS now = time(when);
   return start < end ? start <= now && now < end 
                      : !isValidTime(end, start, when);
}
///////////////////////////////////////////////////////////////////////////////
#define HR0800 28800 // 8*3600
#define HR1345 49500 // (13*60+45)*60
if(isValidTime(HR0800, HR1345)) Print("time between 8AM and 1:45PM server time");
if(isValidTime(HR1345, HR0800)) Print("time outside 8AM and 1:45PM server time");
 
Osama Shaban:

The thing is not easy as you think specially when you use others code.

Ok. I will send you the whole code I used to use  and you try to solve the puzzle.



Thanks your elaborate comment that i never thought about.

i'm gonna use this code to solve my problem.

Have a nice day!
 
whroeder1:
I'd allow fractional hours.


As a beginner of mql4 and mql5, this code is little bit hard to understand to me so far.


but i'm sure it will be very useful to me when i totally understand.


i appreciate you comment.


Have a nice day!

Reason: