Watch how to download trading robots for free
Find us on Twitter!
Join our fan page
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
Experts

002 - Inside Bar - expert for MetaTrader 5

Sergey Ermolov
Sergey Ermolov
Hi,
I’m Sergey Yermolov — I’ve been developing trading systems and algorithms for over 15 years.
My approach to trading is not about chasing a “holy grail” or promising quick profits.
I don’t sell “money-making robots.”
Views:
183
Rating:
(1)
Published:
MQL5 Freelance Need a robot or indicator based on this code? Order it on Freelance Go to Freelance

Expert Advisor for testing the Inside Bar continuation hypothesis.

Strategy logic: the EA searches for a classic Inside Bar pattern consisting of a Main Bar and a Signal Bar.

  • Main Bar — the larger candle containing the pattern.
  • Signal Bar — the Inside Bar fully contained within the Main Bar range.

The Signal Bar must be completely inside the range of the Main Bar. If the Main Bar closes bullish, a Buy Stop order is placed above the Main Bar high. If the Main Bar closes bearish, a Sell Stop order is placed below the Main Bar low.

Stop Loss is calculated as a fraction of the Main Bar range.

Take Profit is calculated using a predefined Risk/Reward ratio.

An optional ATR filter can be applied to require the Main Bar to be significantly larger than recent market volatility.

This EA was built as a research tool for testing the statistical behavior of the Inside Bar pattern across different markets and timeframes.


Parameters

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

ATR Filter

  • ATR Filter (Main Bar Size) - Enables or disables the ATR filter.
  • ATR Period - ATR calculation period.
  • Min Main Bar Size (x ATR) - Minimum Main Bar size expressed as a multiple of ATR.

Example:

ATR = 100 points
Min Main Bar Size (x ATR) = 1.5

The Main Bar range must be at least 150 points for the setup to be considered valid.

Inside Bar Filter

  • Min Main Bar Body (% of Range) - Minimum Main Bar body size expressed as a percentage of the Main Bar range.
  • Max Inside Bar Size (% of Main) - Maximum Signal Bar size expressed as a percentage of the Main Bar range.

Example:

Main Bar range = 100 points
Max Inside Bar Size (% of Main) = 50

The Signal Bar range must not exceed 50 points.

Position Settings

  • StopLoss (x Main Bar Range) - Stop Loss distance expressed as a fraction of the Main Bar range.

Example:

Main Bar range = 100 points
StopLoss (x Main Bar Range) = 0.62

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

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

Example:

Stop Loss = 50 points
TakeProfit (Risk/Reward) = 2.5

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

Order Management

  • Cancel Pending Order After N Bars - Number of bars after which an unfilled pending order is automatically cancelled.


Important Notes

  1. The EA analyzes the currently selected chart timeframe.
  2. Pattern detection is performed only when a new bar appears.
  3. The Signal Bar must be fully contained within the range of the Main Bar.
  4. The direction of the Main Bar determines the trade direction.
  5. Buy Stop orders are placed above the Main Bar high.
  6. Sell Stop orders are placed below the Main Bar low.
  7. Only one position per symbol can be open at a time.
  8. Only one pending order per symbol can exist at a time.
  9. Pending orders are automatically removed after the number of bars specified in Cancel Pending Order After N Bars.
  10. When using % Risk from Start Balance, risk calculations are based on the account balance captured when the EA starts.


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 across the H1 and M15 timeframes.

The purpose of this Expert Advisor is research rather than optimization. The source code is published to allow independent verification, modification and testing of the hypothesis on other markets and datasets.

EURUSD M15 back test

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


Source code is open — feel free to modify it, test it on other instruments and build upon it.

This EA was created to test a trading hypothesis, not to trade real money without additional research and validation.

Geometric signal validation for indicator signals Geometric signal validation for indicator signals

A state engine to provide geometric signal validation for indicator signals

Multi Forex Scanner MT5 Multi Forex Scanner MT5

Instead of having to analyze each pair individually, you can see at a glance what are the most promising pairs according to your own criteria.

Accelerator Oscillator (AC) Accelerator Oscillator (AC)

The Acceleration/Deceleration Indicator (AC) measures acceleration and deceleration of the current driving force.

MACD Signals MACD Signals

Indicator edition for new platform.