Range Scalper EA
The range is the highest high and lowest low over InpRangeBars bars. An entry only fires when the previous close sits within InpEntryBandPercent of the range width from either edge, with a stop InpStopBeyondPercent beyond that edge and a target InpTargetPercent back into the range - all three distances scale with the range's own width, so they widen and narrow with it automatically rather than using a fixed pip distance that would be too tight in a wide range and too loose in a narrow one. Range strategies are reliably destroyed by trends: a market that stops ranging and starts trending runs straight through a mean-reversion entry and out the far side of its stop. Most examples in this catalogue gate entries on a regime filter and then leave the exit entirely to a fixed stop and target once the trade is open. This EA instead keeps checking ADX(InpAdxPeriod) every bar while a position is open, and if it climbs to InpFlattenAdx or above, closes the trade immediately rather than waiting to find out whether the fixed stop was wide enough for a trend that was not supposed to be there. Position sizing can run as a fixed lot or, with InpUseRiskSizing on, as a percentage of equity risked to the range-scaled stop distance, computed from MODE_TICKVALUE and MODE_TICKSIZE rather than a hardcoded contract size. Notes and limitations - The ADX flatten check only runs once per closed bar, the same as everything else in this EA - a fast intrabar trend break can still outrun it before the next bar closes. - Entering near a range edge is not the same as the range holding; a scalp can still be stopped out on the very move the ADX filter was meant to catch, simply because ADX had not yet risen when the entry fired. - No separate trailing stop - exit is the fixed stop/target, the ADX flatten check, or manual intervention. - 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, though the ADX flatten check on an existing position still requires trading to be allowed to act on it.
Expert advisor · MT4 · v1.0 · Free
About Range Scalper EA
Range Scalper EA is an expert advisor (trading robot) for MetaTrader 4 based on ADX. It can size trades from your balance and risk percent and is built for short scalping trades. It has 14 settings, such as Range bars, Adx period and Max adx to enter. MQL source code included.
Files in the download: RangeScalperEa.ex4, RangeScalperEa.mq4, RangeScalperEa.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 |
|---|---|---|
| Range bars | 24 | Bars used to define the current range (high/low) |
| Adx period | 14 | ADX period used as the trend/range regime filter |
| Max adx to enter | 22.0 | Maximum ADX allowed to open a new scalp |
| Flatten adx | 30.0 | ADX level that flattens an open scalp early (trend emerging) |
| Entry band percent | 20.0 | How close to the range edge price must be to enter, percent of range width |
| Stop beyond percent | 15.0 | Stop distance beyond the range edge, percent of range width |
| Target percent | 50.0 | Take profit distance back into the range, percent of range width |
| Use risk sizing | false | Size by percent risk instead of a fixed lot |
| Risk percent | 0.5 | 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 | 20260710 | 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: Scalping · ADX · Trend · Risk & Lot Size · MT4 Expert Advisor · MQL4 Source Code