Expert Advisors • Indicators • Scripts • Libraries

MQL.RobotFX.org is the biggest collection of MetaTrader expert advisors (MT5 & MT4), indicators, scripts and libraries that can be used to improve trading results, minimize risks or simply automate trading tasks

Metatrader 5 Expert Advisor | 003 - Weekly Day Reversal | Source Code Included

RobotFX curates the best open-source MetaTrader code to inspire your trading automation.

Expert Advisor for testing day-of-week market patterns.

Strategy logic: the Expert Advisor analyzes the direction of the previous trading day and can open positions either in the direction of continuation or in the direction of reversal on the following day. Any combination of weekdays can be tested, allowing the evaluation of recurring market behavior and calendar-based effects.

Positions can be closed at the end of the trading day to isolate the raw day-of-week effect, or managed using optional Stop Loss, Take Profit, and additional filters. This makes it possible to compare the underlying pattern with optimized trade management rules.

The EA was developed as a research framework for systematically testing day-of-week hypotheses across different markets, including Forex, commodities, and stock indices.

Never miss news-driven moves – use the News OCO Expert Advisor to place pending orders safely around economic releases. Find out more.


Parameters

  • LotType - Position sizing method.
    Fixed Lot — fixed trade volume.
    % Risk from Start Balance — position size calculated from a predefined risk percentage.
  • Lots - Fixed lot size used when Fixed Lot mode is selected.
  • Risk - Risk per trade in percent. (Used only when risk-based position sizing is enabled.)

Weekly Day

  • Day Of Week - The day of the week whose direction we are evaluating
  • Direction - Direct or Revers trade

ATR Filter

  • FilterATR - Enables or disables the volatility filter.
  • DailyATRPeriod - ATR period calculated on the daily timeframe.
  • MinCheckDayATR - Minimum Monday range expressed as a multiple of ATR.

Example:

ATR = 100 points
MinCheckDayATR = 1.5

A trade will only be opened if Monday's range exceeds 150 points.

Position Settings

  • kDailyATR - Stop Loss distance expressed as a multiple of the daily ATR (0 disables Stop Loss).

Example:

ATR = 100 points
kDailyATR = 0.5

The Stop Loss will be placed 50 points away from the entry price.

  • rrTP - Risk/Reward ratio used to calculate Take Profit (0 disables Take Profit).

Example:

Stop Loss = 50 points
rrTP = 2.0

The Take Profit will be placed 100 points away from the entry price.

Close Position

  • CloseHour - Hour when all open positions are force-closed.
    If neither Stop Loss nor Take Profit has been reached, the position will be closed at market price.


  • MagicNumber - Unique identifier used for the EA's positions.


Important Notes

  1. The EA analyzes daily candles regardless of the chart timeframe.
  2. Entry conditions are checked only when a new daily bar appears.
  3. ATR values are taken from the daily timeframe (PERIOD_D1).
  4. Only one position per symbol can be open at a time.
  5. All positions are force-closed at the hour specified in CloseHour.
  6. If Stop Loss is disabled (kDailyATR = 0), risk-based position sizing cannot be calculated. In this case, the minimum allowed lot size is used.


Risk Calculation

When using % Risk from Start Balance, position size is calculated from the account balance captured when the EA starts, not from the current account balance.

This behavior is intentional and was designed to make strategy testing more consistent. Risk remains constant throughout the test and does not change as the balance grows or declines.

If you prefer the traditional approach based on current balance or equity, the position sizing logic can be modified in the CalcLot() function.


Backtest Results

The strategy was tested on EURUSD, XAUUSD and SP500 over the 2016–2026 period.

XAUUSD after adding the ATR filter and position management rules, the results changed:

  • Profit factor: 1.31


Image for 003 - Weekly Day Reversal


Full research report, equity curves and test results: https://www.mql5.com/en/blogs/post/771715


Source code is open — feel free to modify it, test it on other instruments and build upon it.
This EA was created to test trading hypotheses, not to trade real money without additional research and validation.

Build better strategies with RobotFX professional tools – check them out.

74137

Best MetaTrader Indicators + Profitable Expert Advisors