no-image

Implementation method that does not enter except weekends or set times

◎ Functional specifications

  1. No entry after Friday's scheduled time or on Saturdays and Sundays.
  2. Do not enter outside of the specified time.

◎ Detailed specifications

XNUMX. Declare variables.

// Entry start time
extern int EntryStartHour = 18;
// Entry end time (can be set up to 32)
extern int EntryEndHour = 32;
// weekend end time
extern int WeekendHour = 20;
// GMTOffset time of local PC running MT4
extern int LocalGMTOffset = 9;
// MT4 server GMTOffset time
extern int ServerGMTOffset = 2;
// local PC time
int LocalHour;

XNUMX. Define the function.

int CheckTradeOffTime () {

// get local time
datetime LocalDateTime = TimeLocal ();

// get day of week from local time
int LocalWeek = TimeDayOfWeek (LocalDateTime);
if (WeekendHour == 0) {
// do not trade on weekends
if (LocalWeek == 6 || LocalWeek == 0) {
return (1);
}
}
else {
// Do not trade on Fridays or on weekends
if ((LocalWeek == 5 && LocalHour> WeekendHour) || LocalWeek == 6 || LocalWeek == 0) {
return (1);
}
}

// get time from local time
LocalHour = TimeHour (LocalDateTime);
if (IsTesting () == true) {
// In test mode, LocalHour contains server time instead of local time, so convert to local time.
LocalHour = LocalHour + (LocalGMTOffset-ServerGMTOffset);
}
// If the entry end time is set after 24:XNUMX, convert the local time.
if (LocalHour <= (EntryEndHour-24)) {
LocalHour = LocalHour + 24;
}

// Trade only from EntryStartHour to EntryEndHour
if ((LocalHour <EntryStartHour) || (LocalHour> EntryEndHour)) {
return (1);
}

return (0);
}

XNUMX. Describe in the Start function.

// TRADE OFF
ret = CheckTradeOffTime ();
if (ret == 1) {
return (0);
}

Translate »