4-Hour Range Strategy: Coded and Tested

4-Hour Range Strategy: Coded and Tested
Download ALL MT5 experts (1731)
YouTube Video Thumbnail



Similar MetaTrader Tools

4-Hour Range Strategy: Coded and Tested

Info

The 4-Hour Range Strategy: Coded and Tested is a Expert Advisor for MetaTrader 5 that this strategy is provided for educational purposes and is not trading advice. Backtests on EURUSD under specific conditions were unprofitable.

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 4-Hour Range Strategy: Coded and Tested

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

This strategy is provided for educational purposes and is not trading advice.

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: Fx Craft Example EA: Range Breakout with Pending Orders - another powerful expert for MetaTrader 5 traders.

This strategy is provided for educational purposes and is not trading advice. Backtests on EURUSD under specific conditions were unprofitable.

Also recommended: Opening Range Breakout with NR4 / NR7 Contraction Filters (2026 Update) - similar expert with strong performance on MetaTrader 5.


The strategy operates based on the following logic:

It first marks the high and low of the initial 4-hour candle, using the New York time zone. After this candle is formed, the strategy waits for a 5-minute candle to close outside the range.

If a 5-minute candle closes above the high and then another 5-minute candle closes back within the range, a sell signal is generated. Conversely, if a 5-minute candle closes below the low and then another 5-minute candle closes back within the range, a buy signal is triggered.

A time filter was introduced to address a vague rule regarding the order block. This filter ensures that if the price stays above the high or below the low for more than 75 minutes, the trade is marked as invalid, preventing trades after the price has overextended beyond the range.

Accurate specification of the broker's GMT offset times and the dates for switching between summer and winter time zones is crucial. Since the strategy relies on the New York local time, a single error in these settings can significantly impact its performance.

Here are the input parameters for the strategy:

- servergmtoffsetwinter: GMT offset of the broker's server in winter time.
- servergmtoffsetsummer: GMT offset of the broker's server in summer time. (Can be the same as the winter offset for brokers with a fixed GMT offset)
- serverswitchtosummermonth: Month when the broker switches to summer time zone.
- serverswitchtosummerday: Day of the month for the switch to summer time zone.
- serverswitchtowintermonth: Month when the broker switches to winter time zone.
- serverswitchtowinterday: Day of the month for the switch to winter time zone.
- lots: Lot size

Backtest results for EURUSD:

- (Results to be added here)

You may also like: ORB Risk Managed: Opening Range Breakout with Account Protection - excellent alternative for expert users on MetaTrader 5.

Source Code

#property copyright "RobotFX"
#property link "https://robotfx.org"
#property version   "1.01"
#include <Trade\Trade.mqh>
input int  ServerGMTOffsetWinter = 2;   // Server GMT offset in Winter time
input int  ServerGMTOffsetSummer = 3;   // Server GMT offset in Summer time (can be the same as winter)
input int  ServerSwitchToSummerMonth = 3;   // Month when broker's server switches to Summer time
input int  ServerSwitchToSummerDay   = 1;   // Day of month when broker's server switches to Summer time
input int  ServerSwitchToWinterMonth = 11;  // Month when broker's server switches to Winter time
input int  ServerSwitchToWinterDay   = 1;   // Day of month when broker's server switches to Winter time

.......

Leave your opinion, ask a question, share some knowledge

⚠ 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.
© ROBOTFX Free educational tools by RobotFX. Use entirely at your own risk; we are not liable for any financial losses incurred.