How to Close All Open Trades on MT4 at Specific Time

A man with the clock and numbers

In this blog post I will explain how you can program your MetaTrader 4 platform to close all open positions at a desired time. It is easier than you might think, but MT4 by default does not have such option. This is why we will need a special tool for that called “Timed Exit EA”.

The Timed Exit EA is the most simple and easy to use app to close all trades automatically at specific time each day. You simple attach the EA to the chart window, input the time and EA will do the rest when that time comes.

The main idea of this EA is to automatically close trades every day at specified time. So once you set the EA it will repeat the same every day at the same time over and over again until you stop it. For example if you set EA to close all trades at 15:29:30, EA will do this each day when markets are open.

Download the Timed Exit EA

You can set the EA to close all trades before the news or any other event. You can set it to close all trades at the end of your trading session or just before the beginning of the trading session. Basically, you can set any time you want, so this gives you complete freedom.

Click here to download the Timed Exit EA from MT4 App Market. You can also install the EA directly from your MT4 platform, just like the Partial Close EA.

If you do not know how to get apps from the MT4 market there are quite a lot of useful information on their website. Here’s the one that explains how to download Forex robots from the market. And this one explains how to test an Expert Advisor before buying.

Once you’ve downloaded the Timed Exit EA on your MT4 platform, it should appear in the Navigator window, under the “Expert Advisors -> Market” section.

Timed Exit EA in MT4 Navigator window

Timed Exit EA in MT4 Navigator window

Running the Timed Exit EA

To run the EA you need to attached it to a separate chart of any time frame on your MT4, and it will start monitoring trades immediately. By default EA has “Time Exit” function disabled. This is for your own protection. Trade closing is a very responsible thing to do, so you might want to learn and test the EA first on a demo account to get used to it before you use it on your live trading account.

Here are the EA Input settings in the image below. As you can see the EnableTimedExit option is set to FALSE, which means “Time Exit” function is disabled.

Time Exit function disabled by default in the Timed Exit EA Inputs

Time Exit function disabled by default in the Timed Exit EA Inputs

So obviously, when you attach the EA to the chart and want it to start monitoring your trades, you need to set the EnableTimedExit option to TRUE.

On EA startup it could be that the time to close the trades has passed already. For example EA is set to close the trades at 08:00 and EA is launched at 09:30. In this case EA will check if there are any open trades that should have been closed and ask if you want them to be closed or not. If you answer YES, then obviously EA will close these trades. If you answer NO, the EA will leave those trades running until next exit time.

On startup, Timed Exit EA asks a user whether it should close open positions or not, because the exit time has passed already.

On startup, Timed Exit EA asks a user whether it should close open positions or not, because the exit time has passed already.

EA can be used with any other Expert Advisors, indicators or scripts simultaneously. Just note, that you need to open a separate chart for each Expert Advisor. MT4 does not allow to run more than one EA on the same chart window, so you will have to open additional chart for each additional EA you want to run. This seems to be confusing to some people as I keep getting this question a lot. That’s why I wrote this blog post which explains how to run multiple EA on the same MetaTrader 4 platform.

When you attach the EA to the chart, it will only see the trades of that currency pair (instrument) that it is attached to. This means if you attach the EA on the EURUSD chart, then it will monitor only EURUSD positions. Important to mention, that if your broker has multiple names for the same currency pairs, like EURUSD and EURUSDc, positions for these pairs will be treated individually. Means that if you open a trade on EURUSD, the EA running on EURUSDc will not see it. You will have to run EA on EURUSDc to manage these trades. Obviously you can run EA on both pairs if you need to. EA can also be applied to a non-Forex pairs/instruments like Indices, Commodities, etc.

There’s also an option to set in the EA to manage the trades of any currency pair. By default EA will close all market/pending orders on the currency pair (instrument) it is attached to, but with the help of the option ManageOnlyCurrentPair you can control how EA should work. If you set this option to FALSE, then EA will monitor the trades of any currency pair (instrument).

With the settings below EA would close all open trades you have of any financial instrument at 16:59.

Timed Exit EA scheduled to close all open trades of any pair at 16:59

Timed Exit EA scheduled to close all open trades of any pair at 16:59

It is also possible to filter trades by magic number. By default EA is programmed to monitor trades of any magic number – ManageMagicNumber is set to -1 (negative one). But obviously you can change this if needed. If you set ManageMagicNumber to zero, EA will see only manually opened trades. If you set this value to anything above zero, EA will only monitor and close the trades of that specific magic number.

Magic number is assigned to positions only by other EA. MT4 does not allow to choose what magic number to use when you’re opening the trade manually, but if you use app like Trade on Chart – it becomes possible. ToC allows you to set what magic number it should use when opening the trade.

With the settings below EA would close all manually open trades 30 seconds before the London trading session open (having in mind that our broker clock is in the UK time zone). Note the EA is set to manage positions only with the magic number of zero. This means only manually open trades will be closed. If there will be any positions opened by Trader on Chart app or any other MT4 EA, Timed Exit EA will not touch them and leave as they are.

Timed Exit EA scheduled to close all manually open positions 30 seconds before London open

Timed Exit EA scheduled to close all manually open positions 30 seconds before London open

Timed Exit EA Inputs explained

  • EnableTimedExit – this tells the EA whether the EXIT function is enabled or disabled. By default it is disabled for security reasons. You can to turn it on by setting the value to TRUE.
  • ExitTime – this tells the EA at what time exactly the trades should be closed. Input format is HH:MM:SS or HH:MM and EA will not work if you enter anything else. Note that EA uses broker time, which is also displayed in the dashboard and your MT4 Market Watch window.
  • ManageMagicNumber – this tells the EA to close trades only with certain magic number you choose. If this value is set to zero EA will see only manually opened trades. If you set this to -1 (negative one) EA will see all of the trades running on the account (default value).
  • ManageOnlyCurrentPair – this tells the EA if it should monitor trades only of the currency pair (instrument) it is currently running on, or it should monitor trades of any currency pair. By default it is set to TRUE and EA will see only trades of the currency pair it is running on.
  • SlippageClosePips – this is the slippage setting EA will use to exit the market (close the trade). Note that not all brokers use this and this has no effect on ECN/STP accounts. If you do not know what that is simply leave it as is.
  • DashboardDisplay – this options controls how the EA dashboard is displayed. 0 = hide the dashboard; 1 = show only text without background; 2 = show text with background (default value).
  • DashboardColor – this is where you can set background color or the EA dashboard.

Closing trades at multiple times

You can run multiple instances of the Timed Exit EA if you open additional chart window for each EA instance. This way you can have any combinations of EA settings you want and this is how you set the EA to close trades at multiple times, on multiple currency pairs, and multiple choices of magic numbers.

In the image below you can see 3x Timed Exit EA running on 3x separate chart windows.

First EA will close all positions of any instrument at 08:00 every day.

Second EA will close all positions of any instrument at 17:00 every day.

Third EA will close positions of only USDCHF currency pair every day at midnight and only those positions I will open using the Trader on Chart app.

Fourth EA is the Trader on Chart app which is set to use the magic number of 123, which is exactly the same number as set in the third instance of the Timed Exit EA.

3x instances of Timed Exit EA on the same MT4 platform with Trader on Chart

3x instances of Timed Exit EA on the same MT4 platform with the “Trader on Chart”


Even though there is no option in the MT4 to schedule the time at which your open positions should be closed, you can always do this with the Timed Exit EA. I receive quite a lot requests to create such trading tool and finally it is available for anyone to use.

How will you use it? Post your ideas in the comments below.

About the author

Rimantas Petrauskas

First I am a father, a husband and then the author of the book “How to Start Your Own Forex Signals Service”. I am also a Forex trader, a programmer, an entrepreneur, and the founder of Forex blog. I have created two of the most popular trade copiers and other trading tools for MT4 that are already used world wide by hundreds of currency traders.


Leave a comment

Leave a Reply to Rimantas Petrauskas Cancel Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Copyright © 2009-2020. Rimantas Petrauskas | Terms and ConditionsPrivacy PolicyEarnings Disclaimer
Trading foreign exchange on margin carries a high level of risk, and may not be suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with foreign exchange trading, and seek advice from an independent financial advisor if you have any doubts.
The purchase, sale or advice regarding a currency can only be performed by a licensed Broker/Dealer. Neither us, nor our affiliates or associates involved in the production and maintenance of these products or this site, is a registered Broker/Dealer or Investment Advisor in any State or Federally-sanctioned jurisdiction. All purchasers of products referenced at this site are encouraged to consult with a licensed representative of their choice regarding any particular trade or trading strategy. No representation is being made that any account will or is likely to achieve profits or losses similar to those discussed on this website. The past performance of any trading system or methodology is not necessarily indicative of future results.
Clearly understand this: Information contained in this product are not an invitation to trade any specific investments. Trading requires risking money in pursuit of future gain. That is your decision. Do not risk any money you cannot afford to lose. This document does not take into account your own individual financial and personal circumstances. It is intended for educational purposes only and NOT as individual investment advice. Do not act on this without advice from your investment professional, who will verify what is suitable for your particular needs & circumstances. Failure to seek detailed professional personally tailored advice prior to acting could lead to you acting contrary to your own best interests & could lead to losses of capital.

Copyright © 2009-2021. Rimantas Petrauskas | Terms and Conditions | Privacy Policy | Earnings Disclaimer
Malcare WordPress Security