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.
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.
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.
What is Metatrader 4? MetaTrader 4 is one of the leading platforms in the world…
In this MT4 tutorial, Rimantas explains how to download MetaTrader 4 and open Forex demo…
There you'll find video tutorials for the Equity Sentry software for MT4. (more…)
There you'll find video tutorials on how to install and use the Trader On Chart…
There you'll find video tutorials on how to install and use the Trendline Trader EA…
Installing and running multiple MT4 client terminal instances on the same machine is easier than…
View Comments
Thank you RIMANTAS this EA looks interesting i might use it in the near future, well done you're an artist programmer
Thanks for your feedback ;-)
I would like to buy ur timed exit EA.
However, i can't find it in the mql5 markets?
Pls advice how to purchase this EA, tq.
Dear Ken,
there is this big red button saying "Download the Timed Exit EA" on this page. Click it and you'll go straight to the EA download/purchase page on MQL4 Market.
Regards,
Rimantas
Is it possible to delete pending orders only? Not close open positions. I am happy to pay extra for a modified version.
Hi, this EA does not have such option. It will close and delete all positions and orders it will find on the account. You can filter by magic number, so if your pending orders have different magic number then you could set EA to delete only them.
See my policy for custom programming here and contact me here if you want to order.
Regards,
Rimantas
Hello, is it possible to set an EA or paste code into an existing EA that will trigger all trades to close if ATR (Average True Range) reaches below or above a specific level?
Thank you,
Hi, this is not possible with my app, but it is sure possible if you hire a programmer to create this for you. Try http://www.mrmetatrader.com/
Do i need any vps for the system for running the system??
VPS is not required for Timed Exit EA.
HOW TO CLOSE ORDERS MATCHING THE SAME COMMENT ?
You need to use MT4 App that can do that. My app does not have such option.
Will orders close at the set time when my PC is in hibernate or sleep mode?
Hi, if your PC is in sleep/hibernate mode it means no computer application is running including MT4 and EA. In other words, it is not possible to make it work in sleep/hibernation mode.
Solution is to have a VPS server from company like vpsforextrader.com and then host your MT4 in there, where it will run 24 hours per day, even while your computer is off, sleeping or hibernating.
hi, 2nd question. It appears the exit order is within a 24hr period based on the MT4 machine time. As i am in australia, this time kicks over to a new 24 hour period mid day my time, meaning i can only set an exit order via your EA after mid day. Is this correct...or is there anyway to set my exit time in the morning (in prior 24 hr period) to exit in afternoon (next 24 hr period)?
Thanks
Would be better if you send me an email to support@ea-coder.com and include exact time and EA settings you use.
Can this be used to start trades at specific times? I would need a similar feature but to start trades on specific times.
Trader On Chart app for MT4 has a trade "scheduler" that you can use for that.
Thank you RIMANTAS! I think I am asking the impossible, but can another option be added that will not only close trades, but also switch off/disable live trading for the other EA's? I know this is a catch 22 as you EA would probably have to turn itself off. But if it did that after closing trades and disabling all other EA's, then that would do it. But as I say, I think this would be impossible.
Te reason I ask is that the EA's I am using will often open another trade if the the existing one is shut down, so the closing of trades only would be pointless. Thanks.
Hi, yes, you can already do this with my equity protection EA.