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.
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.
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.
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.
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.
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 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.
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.