$ £ ¥
¥ £ $

AutoTrading Scheduler

AutoTrading Scheduler is a MetaTrader expert advisor that lets you control the status of AutoTrading button in your MetaTrader platform based on a weekly schedule. In addition to enabling and disabling AutoTrading, this EA can also attempt to close all trades when disabled AutoTrading period is reached. The expert advisor is available for both MT4 and MT5.

This scheduler requires DLL imports to work properly. It imports one function from the standard Windows DLL file (user32.dll). Do not forget to allow DLL imports when attaching this expert advisor to a chart.


The panel controls are pretty straightforward. The Switch button lets you turn the scheduler on and off. The group of radio buttons to the right lets you switch between the local and server time. The status will inform you if DLL's are turned off, if connection is missing, or if AutoTrading is already disabled. The seven entry fields, each for every day of the week, serve to enter time ranges when you want AutoTrading to be enabled. The Set to all empty button will set the value entered for Monday to all other empty days of the week — this can be useful to quickly set the same schedule for each day. The first checkbox below the days of the week lets you make the EA to attempt closing all trades before disabling AutoTrading. Finally, the checkbox at the bottom sets whether the scheduler works in a strict enforcing mode (ticked; the EA will always try to enable/disable AutoTrading according to the schedule) or not (unticked; the EA will only enable/disable AutoTrading when the next period starts or ends).

AutoTrading Scheduler - Interface


When Scheduler is off, it will do nothing. You have to turn it on for it to operate.

Changing the time from Local to Server can be useful if you want Scheduler to work based on your broker's trading server time, for example, during daylight saving time switching weeks.

The status can be OK, No autotrading, No connection, or DLLs disabled. The first and the second one don't affect anything — they just inform you. No connection means that the EA won't be able to close any trades before disabling AutoTrading, but it will disable AutoTrading without a problem. DLLs disabled is a real problem because enabling/disabling AutoTrading will be impossible.

The main part of working with the Scheduler is to set a valid weekly schedule. AutoTrading will be enabled during the time periods you set.

The time input fields work with time ranges given in 24-hour format with start and finish time separate with a hyphen. For example, the range 9-17 will be interpreted as "from 9:00 till 17:00" (or "from 9 a.m. till 17 p.m.").

More than one range can be given for the day using comma as a separator. For example, the range 13:30-16:30, 19:30-20:05 will enable AutoTrading during two periods: from 13:30 till 16:30 and from 19:30 till 20:05.

By default, the scheduler will always try to switch AutoTrading off outside of allowed periods and on inside such periods. Even if you switch AutoTrading on or off yourself, the scheduler will override. To avoid this, you can untick the checkboox at the bottom of the panel — this will make the scheduler toggle AutoTrading only when the allowed period starts or ends and only once per each start or end.

The main objective of AutoTrading Scheduler is to control the status of the AutoTrading button in MetaTrader. However, it can also be used to close the trades before disabling AutoTrading. This is attained by ticking the checkbox below the days of the week. The expert advisor will attempt to close the positions and delete pending orders, but there is no guarantee that it will succeed in doing so. It will not re-try closing the trades because its first priority is to disable AutoTrading and after AutoTrading is disabled, managing trades becomes impossible.

Input parameters


    • EnableNativeAlerts (default = false) — if true, a native MetaTrader popup alert will be used when AutoTrading is toggled.
    • EnableEmailAlerts (default = false) — if true, an email message will be sent when AutoTrading is toggled Email should be properly configured in MetaTrader via Tools->Options->Email.
    • EnablePushAlerts (default = false) — if true, an email message will be sent when AutoTrading is toggled Notifications should be properly configured in MetaTrader via Tools->Options->Notifications.


    • DefaultTurnedOn (default = false) — default state of the scheduler's 'on/off' switch.
    • DefaultTime (default = Local) — default time type to use — either Local time or Server time.
    • DefaultMonday (default = "") — default periods to enable AutoTrading on Monday.
    • DefaultTuesday (default = "") — default periods to enable AutoTrading on Tuesday.
    • DefaultWednesday (default = "") — default periods to enable AutoTrading on Wednesday.
    • DefaultThursday (default = "") — default periods to enable AutoTrading on Thursday.
    • DefaultFriday (default = "") — default periods to enable AutoTrading on Friday.
    • DefaultSaturday (default = "") — default periods to enable AutoTrading on Saturday.
    • DefaultSunday (default = "") — default periods to enable AutoTrading on Sunday.
    • DefaultClosePos (default = false) — default state of the 'Close all trades' checkbox.
    • DefaultEnforce (default = false) — default state of the 'Always enforce schedule' checkbox.


  • Slippage (default = 2) — slippage value given in broker's pips to be used when closing positions.

Downloads (ver. 1.01, 2023-06-06)

AutoTrading Scheduler is being developed via a dedicated GitHub repository. You are encouraged to actively participate in the improvement of this expert advisor by submitting your own features via pull-requests and by reviewing existing suggestions, changes, fixes, and so on.

AutoTrading Scheduler for MetaTrader 4 AutoTrading Scheduler for MetaTrader 5

To install — unzip and copy the entire AutoTrading Scheduler folder to MQL4/Experts/ or MQL5/Experts/ (if you are on MetaTrader 5) of your terminal's data folder.


Do you have any suggestions or questions regarding this expert advisor?

Discuss AutoTrading Scheduler with other traders and MQL coders on the forum.


1.01 — 2023-06-06

  • Added optional alerts when AutoTrading is toggled.
  • Added non-enforced schedule mode to only toggle AutoTrading when a new period stats or ends.
  • Added input parameters with default values for all panel fields. This will simplify setup and copying the panel settings from one platform to another.
  • Optimized processing of chart timeframe/symbol change.
  • Fixed a bug that prevented the panel from maximizing after minimization.
  • Fixed a bug that could cause multiple triggers when the scheduler was set to close trades.
  • Fixed a bug with deletion of leftover chart objects from a previously crashed ATS panel.
  • Removed the PanelOnTopOfChart parameter. This should be handled by chart settings.