Time-Based Expert Advisor
Info
The Time-Based Expert Advisor is a Expert Advisor for MetaTrader 5 that a simple expert advisor that opens a position of the specified type at a user-defined time and closes it at another user-defined time. The purpose of this EA is to allow users to select the position type (long or short) and set precise opening and closing times in hours and minutes.
Usage
This tool is typically used for automated trading on major forex pairs and gold.
Platform
This Expert Advisor works exclusively on MetaTrader 5 (both build 600+ and newer versions).
Setup
Place the downloaded file in MQL5/Experts folder via File ? Open Data Folder in MetaTrader 5.
How to Install and Use Time-Based Expert Advisor
1. Installation: Open the "File" menu, select "Open Data Folder," navigate to MQL/Experts, paste your file, and restart the terminal.
2. Activation: Drag the EA from the Navigator onto a chart, ensure "Allow live trading" is checked in the Common tab, and verify the AutoTrading button is green.
3. Optimization: Right-click your chart, choose "Expert List," click "Properties" to adjust inputs, and save your preferred setup as a set file for future use.
4. Maintenance: Regularly check the "Experts" tab in the terminal window to monitor trade logs and potential execution errors.
Frequently Asked Questions
Q: Why is my EA not opening trades? A: Check the "AutoTrading" button, ensure "Allow live trading" is enabled, and verify your broker allows automated trading on your account type.
Q: Can I run multiple EAs on one chart? A: No, each chart can only host one active EA; however, you can open multiple charts for different currency pairs to run several EAs.
Q: What does the "smiley face" icon mean? A: A smiley face in the top-right corner of the chart indicates the EA is successfully running; a frowny face means it is disabled.
What this tool does
A simple Expert Advisor that opens a position of the specified type at a user-defined time and closes it at another user-defined time.
Typical Use Case
This Expert Advisor excels in automated trading and technical analysis on MetaTrader 5.
Compatible Platform & Setup
This Expert Advisor works on MetaTrader 5. Place the file in the MQL5/Experts folder and restart the terminal.
Description & Settings
Related: VPS Toolkit: Secure Order Sending and Restart-Safe State for Expert Advisors - another powerful expert for MetaTrader 5 traders.
A simple Expert Advisor that opens a position of the specified type at a user-defined time and closes it at another user-defined time.Also recommended: Automated Live Testing for Expert Advisors on Demo Accounts - similar expert with strong performance on MetaTrader 5.
The purpose of this EA is to allow users to select the position type (long or short) and set precise opening and closing times in hours and minutes. Users can also specify Stop Loss and Take Profit levels in points. If invalid Stop Loss or Take Profit values are provided, the EA will automatically adjust them to the minimum allowed level for the specific symbol.
The EA also intelligently manages lot size. If an incorrect lot value is entered, the EA will adjust it to a valid amount to ensure a position can be opened. If insufficient funds exist to open even the minimum lot size, the trade signal for that period will be skipped.
A unique feature of this EA is its handling of stop orders. If stop orders are used and triggered, a new position can be opened within the same trading bar if it was initially opened at the time signal. This means if a position is opened and then closed by a stop order, and a new position is subsequently opened before the current bar closes, this process will continue until a new bar begins on the current timeframe.
Please note that this Expert Advisor is intended for educational and strategy testing purposes.
The EA features 11 input parameters:
- Expert Magic Number: A unique identifier for the EA's trades.
- Hour of Position Open: The hour for opening positions.
- Minute of Position Open: The minute for opening positions.
- Hour of Position Close: The hour for closing positions.
- Minute of Position Close: The minute for closing positions.
- Position Type: Select whether to open a long or short position.
- Lots: The trading volume for the position.
- Stop Loss in Points: The Stop Loss level in points.
- Take Profit in Points: The Take Profit level in points.
- Slippage of Price: The maximum allowable price slippage.
- Multiplier Spread for Stops: A multiplier for the spread used to calculate the correct distance for stop orders. For stop loss, take profit, and pending orders, there is a minimum allowed distance from the current price. If this value is set to zero, it implies a dynamic distance, typically based on the spread, but potentially larger if the spread alone is insufficient. This parameter allows for a custom multiplier of the spread to determine this minimum distance.
Two tests were conducted in 'Every Tick' mode on EURUSD H1, using data from 2026.01.02 to 2026.01.19. Tests were performed for both long and short positions. The EA demonstrated strong performance in long position mode. This mode was further optimized for position opening and closing hours.
The results of the EA testing, with the opening hour set to 15 and closing hour set to 8, using default parameters, are presented below:
You may also like: Programmatically Attach Expert Advisors with Custom Inputs to MetaTrader 5 Charts - excellent alternative for expert users on MetaTrader 5.
Source Code
/
.......
⚠ Limitations & Risk Warning
- This tool is provided for educational and testing purposes only.
- Past performance does not guarantee future results.
- Trading involves substantial risk of loss. Use on a demo account first.
- Results may vary depending on market conditions, broker, and settings.
- We recommend thorough backtesting and forward testing before using with real funds.