Keltner Channel Breakout EA
MQL4 has no built-in Keltner Channel indicator - only Bollinger Bands and Envelopes ship natively - so the basis and bands here are computed by hand every bar from iMA and iATR: an EMA basis, plus and minus an ATR multiple for the upper and lower band. A close beyond either band opens a position in the breakout direction. The stop is not a fixed pip distance. It starts at the EMA basis and trails with it every closed bar, moved only in the trade's favour, using OrderModify. The logic is straightforward: a breakout that falls back through its own moving average has failed on its own terms, so that line is both a tighter and a more honest exit than an arbitrary fixed distance would be. If price closes back through the basis before the trail can protect it, the EA closes the position outright rather than waiting for the broker-side stop to be hit. Position sizing can run as a fixed lot or, with InpUseRiskSizing on, as a percentage of equity risked to the initial stop distance, using MODE_TICKVALUE and MODE_TICKSIZE rather than a hardcoded contract size so it prices correctly on gold, indices and JPY crosses as well as plain FX pairs. Notes and limitations - No trend or volatility filter beyond the channel itself - in a choppy, range-bound market this will breakout, fail, and re-enter repeatedly, which is the well-documented weakness of naive channel breakout systems. - The trailing stop only tightens; if the broker's minimum stop distance blocks a particular bar's trail, it is simply skipped and retried next bar rather than forced. - Signals and the trail are evaluated once per closed bar, not on every tick. - One position at a time, tracked by InpMagicNumber. It will not manage or interfere with trades opened manually or by another EA. - Requires AutoTrading enabled and IsTradeAllowed() true; if trading is disabled the EA logs it and skips the entry.
Expert advisor · MT4 · v1.0 · Free
About Keltner Channel Breakout EA
Keltner Channel Breakout EA is an expert advisor (trading robot) for MetaTrader 4 based on Moving Average. It increases the lot size after a losing trade (martingale), moves the stop loss behind price (trailing stop / break-even) and can size trades from your balance and risk percent. It has 11 settings, such as Ma period, Atr period and Atr multiplier. MQL source code included.
It also has a news filter and trades breakouts.
Files in the download: KeltnerBreakoutEa.ex4, KeltnerBreakoutEa.mq4, KeltnerBreakoutEa.txt.
Trading robots can lose money. Check every setting and test on a demo account before using real funds.
Settings
| Setting | Default | What it does |
|---|---|---|
| Ma period | 20 | Keltner basis EMA period |
| Atr period | 10 | ATR period used for the band width |
| Atr multiplier | 2.0 | Band distance from basis, in ATR multiples |
| Take profit atr mult | 0.0 | Take profit, in ATR multiples from entry (0 = none, ride the trail) |
| Use risk sizing | false | Size by percent risk instead of a fixed lot |
| Risk percent | 1.0 | Percent of equity risked per trade, when risk sizing is on |
| Fixed lots | 0.10 | Lot size when risk sizing is off, or as a fallback |
| Magic number | 20260703 | Magic number for orders opened by this EA |
| Slippage pips | 3 | Slippage tolerance, in pips |
| Max retries | 5 | Attempts per trade action before giving up |
| Retry wait ms | 500 | Pause between attempts, milliseconds |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Experts.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
- Test it first on a demo account or in the Strategy Tester.
Tags: Breakout · Moving Average · Bollinger Bands · ATR · Channels & Envelopes · Martingale · Trailing Stop & Break-even · Risk & Lot Size · MT4 Expert Advisor · MQL4 Source Code