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

Channel Breakout EA with ATR trailing stop and risk-percent sizing - expert for MetaTrader 5

Bolot Aliev
Bolot Aliev
I build trading tools that do exactly what the specification says — and I test them before delivery.
- MQL5 Expert Advisors and indicators: entries/exits by your rules, ATR/fixed stops, trailing, partial take-profit, break-even, risk-per-trade sizing, news/time filters.
Views:
49
Published:
MQL5 Freelance Need a robot or indicator based on this code? Order it on Freelance Go to Freelance

A simple, fully commented trend-following Expert Advisor for MetaTrader 5. It opens a trade when a bar closes beyond the highest high or the lowest low of the previous N bars (Donchian channel breakout). An optional EMA filter allows longs only above the EMA and shorts only below it.

Signals are calculated once per bar on the closed bar, so testing with "Open prices only" and "Every tick" gives the same entries. The EA keeps one position per symbol and magic number, so it can run on several charts at once.

Risk and exits

  • The initial stop-loss is k x ATR and is sent together with the order.
  • The lot size is calculated so that the loss at the stop equals the chosen percentage of the balance. The volume is rounded down to the volume step; if it is below the minimum lot, the trade is skipped.
  • The stop moves to break-even after the price closes +R in profit (R = the initial stop distance).
  • The ATR trailing stop follows the bar close and only moves in the trade's favour.

Inputs

  • InpChannel (20) - channel length in bars
  • InpUseEMA (true), InpEMA (200) - EMA trend filter on/off and its period
  • InpATR (14) - ATR period
  • InpStopATR (1.5) - initial stop in ATR
  • InpTrailATR (3.0) - trailing stop in ATR, 0 = off
  • InpBE_R (1.0) - move the stop to break-even after +R, 0 = off
  • InpRiskPct (0.5) - risk per trade, % of balance
  • InpMagic - magic number; InpLongs, InpShorts - allowed directions

Example: XAUUSD H1, January 2024 - October 2026, default inputs, 0.5% risk per trade: 428 trades, profit factor 1.40, maximum equity drawdown 7.8% (balance chart attached). A large part of this result comes from the 2024-2026 gold rally; other symbols and periods will differ. H1-H4 timeframes on trending instruments suit the idea best. Past results do not guarantee future results; test on a demo account first.

InputRules: Rules Between Inputs and the Share of Passes They Reject InputRules: Rules Between Inputs and the Share of Passes They Reject

A library for MetaTrader 5 that declares rules between the inputs of an Expert Advisor once in the code. OnInit rejects a combination that breaks a rule, with the reason in the Journal; before an optimization starts, OnTesterInit estimates which share of its passes the rules would reject and warns above a limit you set.

Prop Firm Equity Guard Prop Firm Equity Guard

Protects prop firm challenge and funded accounts: watches equity in real time and closes all trades before the daily loss or maximum loss limit is broken, with an optional profit target lock and a live progress panel.

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.