Scalping EA in MetaTrader 5: How to Judge One, Test It and Build Your Own
Short answer: a scalping EA is an Expert Advisor that opens and closes trades within minutes on M1 or M5 charts, aiming for a few pips each time. Whether one can work on your account is decided mostly by costs: spread, commission and slippage are a large share of a few-pip target. So judge any scalper, bought, free or your own, before it trades: measure its costs against its target, test it on real ticks with your broker's spread and commission, check the broker's stop and freeze levels, and run it on a demo account. This guide shows each check, the MT5 settings, and how to build the same rules without code in the AlfaTactix Strategy Builder, with the MQL5 it generates.
No scalper's past results promise future ones, and this page shows none. It shows how to test.
Part of the MQL5 and Expert Advisors academy.
What Is a Scalping EA, and Does One Work on MT5?
A scalping EA trades often and holds briefly. Most search results for "scalping EA MT5" are product listings and "best EA" lists that show a past equity curve. A curve says little about your account: it was made with someone else's spread, commission, execution speed and test mode. The useful question is not "which scalper is best" but "what does this scalper need from my broker, and does my broker give it?"
In MQL5 the event that reacts to new prices is OnTick() [1]; many scalpers check their rules on every tick, others once per closed M1 or M5 bar. Either way, the quality of each fill decides the result more than on any slower strategy.
How to Judge Any Scalping EA Before You Run It
| Check | What to look at | Why it decides a scalper |
|---|---|---|
| 1. Costs as a share of the target | Spread + commission + expected slippage, in pips, divided by the take-profit distance | A 5-pip target with 1.5 pips of costs gives 30 % of the target away before the market moves |
| 2. Tick mode of the test | "Every tick based on real ticks", not "1 minute OHLC" or "Open prices only" | Coarse modes guess which came first inside a bar: the stop or the target |
| 3. Slippage and deviation | The EA's maximum deviation in points and the account's execution mode | A fast market fills market orders away from the quoted price |
| 4. Stop and freeze level | SYMBOL_TRADE_STOPS_LEVEL and SYMBOL_TRADE_FREEZE_LEVEL of the symbol | A stop closer than the stop level is refused (error 10016); inside the freeze level an order cannot be changed |
| 5. Latency | The ping from the terminal (or the VPS) to the broker's server | Each millisecond between signal and fill is price the scalper does not control |
| 6. Demo forward run | The same EA on a demo account, at least through a few London and New York sessions | It shows real spreads and real fills, which no backtest has |
Spread. In MQL5, SymbolInfoInteger (opens in a new tab) with SYMBOL_SPREAD [2] returns the current spread in points. A scalper that does not read it, and refuse to enter when it is too wide, trades through the widest spreads of the day: the rollover, thin sessions, news.
Tick mode. The MetaTrader 5 tester can use real or generated ticks (opens in a new tab) [3]. "Every tick" rebuilds ticks from minute bars; "Every tick based on real ticks" replays the broker's recorded prices. For a few-pip target, use real ticks when the broker provides the history. The tester's settings, including execution delays, are on the Strategy Testing help page [4].
Stop and freeze level. Both are symbol properties (opens in a new tab) [5] in points. A scalper with an 8-point stop on a symbol whose stop level is 10 points cannot place that stop at all. Read them at start-up, never assume them: see MT5 error 10016 (invalid stops).
Deviation. The deviation field of MqlTradeRequest (opens in a new tab) [6] is the largest price difference, in points, the EA accepts for a fill. It does not apply in every execution mode, so check your account's mode and compare the EA's fills with its requested prices in the trade history.
Latency. A VPS close to the broker's server shortens the distance; see VPS for an Expert Advisor.
What Costs Do to a Small Target
The table is arithmetic, not a broker quote. "Round-trip cost" is the spread plus the commission (converted to pips) plus the slippage you expect. "Hits needed" is the share of trades that must reach the target before the stop just to cover costs, when the stop is as far as the target: hits needed = (target + cost) ÷ (2 × target).
| Target | Cost share at 1 pip | Cost share at 2 pips | Hits needed at 1 pip | Hits needed at 2 pips |
|---|---|---|---|---|
| 3 pips | 33 % | 67 % | 67 % | 83 % |
| 5 pips | 20 % | 40 % | 60 % | 70 % |
| 10 pips | 10 % | 20 % | 55 % | 60 % |
| 20 pips | 5 % | 10 % | 52.5 % | 55 % |
How to get your own cost in pips: take the spread you see during the hours the EA trades; divide the commission per lot for a full round trip by the value of one pip per lot (for EURUSD that is 10 × SYMBOL_TRADE_TICK_VALUE on a 5-digit quote); add the slippage you see on demo fills. For example, a commission of 7 per lot round trip and a pip worth 10 per lot add 0.7 pips. Replace every number with your broker's.
The table explains why tight targets need tight costs, and why a scalper that looks fine on a zero-spread test can fail on a real account.
What Are the Best MT5 Settings for a Scalping EA?
There is no setting that is best on every broker; these are the starting points that make a test honest.
| Setting | Starting point | Why |
|---|---|---|
| Timeframe | M1 or M5 | M1 gives more signals and more noise; M5 is often cleaner |
| Positions | One at a time | Overlapping scalps multiply the costs of one idea |
| Spread limit | A share of the stop, or a fixed limit for your broker's normal spread | Skips the rollover and thin hours |
| Sessions | London and New York | The usual hours of the tightest spreads on major pairs |
| Stop loss | At least the stop level, plus the spread | Below it the order is refused |
| Tester mode | Every tick based on real ticks | Fills inside the bar in the real order |
| Before live | Demo through several sessions | Real spreads and fills |
Build Your Scalping Rules Without Code
The AlfaTactix Strategy Builder is a form in 7 steps. One set of rules, built for MQL5 or Pine Script v6: a strategy is built for one platform at a time, and Step 1 switches it. Here is the M5 scalping recipe from the demo, step by step:
| Step | What you set for this recipe |
|---|---|
| 1. Information and platform | Name, MetaTrader 5 (MQL5), market: currency pairs |
| 2. Timeframes | M5 as the Trading timeframe |
| 3. Entry rules | Buy rule: SMA(10) crosses above SMA(20); switch on Sell mirrors Buy for the sell rule |
| 4. Filters | Market sessions: London and New York, When any of them is open; a Spread limit (see below) |
| 5. Exits | Stop loss and Take profit, in pips or as an ATR multiple; optional Close after N bars |
| 6. Risk and money management | Risk per trade (% of the account) or Fixed lots; Open positions: 1; optional Entries per day and Daily loss limit |
| 7. Review and save | Fix anything in the Check list, Save strategy, then Backtest this strategy or Get the code |

Step 3 shows the rule in plain words before any code exists: "Buy when SMA(10) · M5 crosses above SMA(20) · M5", and the mirrored sell rule. A cross is true only on the bar where it happens; to accept a cross from the last few bars, use the time window Happened within the last N bars.

Step 4 adds the session filter. Each session runs on its own city's time, and summer time is handled for you. When any of them is open trades from the London open to the New York close; Only when all are open at the same time keeps only the hours when both are open.
The spread limit. Step 4's Spread limit offers A fixed number (in points, or pips on currency pairs), A share of the stop or A share of the ATR. A share of the stop is the scalper's version of check 1: "skip the trade when the spread is more than 10 % of this trade's stop". The spread limit is not on every plan; the form marks a locked control with the plan that opens it, and the screenshots above, taken in the public demo, show none.
If you prefer to describe the idea in a sentence, Tactix Studio fills the same form: it never writes code, you see every change and save it yourself. More on the form: MT5 EA builder.
What the Generated MQL5 Looks Like
The code generators are fixed programs with no AI model inside: the same strategy document and the same generator release always produce the same file, byte for byte. Every generated file names the generator version in its header. Below are lines copied unchanged from the .mq5 file the generator writes for one of our golden test strategies, "Relative spread", by generator version 1.0.0; it has three spread limits, and // … marks where we skipped lines.
//| AlfaTactix Strategy Builder v2 - MQL5 Expert Advisor
//| Strategy: Relative spread
// …
//| generator version: 1.0.0
// …
// f_1: spread x 100 <= 10 x the side's initial stop distance (relative spread, of: stop)
bool ATV2_Filter0(const double spread_price, const double stop)
{
if(stop == ATV2_NONE)
return false;
return spread_price * 100.0 <= 10.0 * stop;
}
// …
// f_3: spread <= 2 pips
bool ATV2_Filter2(const long spread_points)
{
return (double)spread_points <= 2.0 * (double)ATV2_PipPoints(g_state.digits);
}
// …
long spread_points = k == count - 1 ? SymbolInfoInteger(_Symbol, SYMBOL_SPREAD) : (long)r[k].spread; // at the order instant
// …
// entries = rules AND filters, never inside the warm-up
g_pending.enter[side] = !warmup && ATV2_EntrySignal(side, shift) && ATV2_FiltersAllow(side, shift);
What this shows:
- The spread limit is a plain comparison you can read: "spread × 100 ≤ 10 × the stop distance" is "the spread is at most 10 % of the stop".
- The spread is read with
SYMBOL_SPREADat the order instant; an entry needs the rules and every filter. - The generated code uses no platform indicator built-ins: every indicator is written out in the code you download, so you can read it.
- All 29 golden Expert Advisors compile in MetaEditor with 0 errors and 0 warnings.
- The EA recovers its state after a restart, a crash or being removed from the chart, with the same trades as a run without the restart (tested in the MetaTrader 5 tester). That matters for a scalper on a VPS that restarts.
How we check the generators: How we test and MQL5 and Pine generators.
Backtest the Rules on Your Own Data
In Step 7, Backtest this strategy opens the AlfaTactix backtest, which tests the same rules on the site with your own data. For a scalper, three settings matter:
- Mode. "Bars only" uses each bar's open, high, low and close (when the stop and the target are both in one bar, the stop counts). "1-minute data inside each bar" works like MT5's "1 minute OHLC". "Real ticks" works like "Every tick based on real ticks".
- Costs. Set the spread, the commission per lot or per order, and the slippage in points on stop, gap and market fills. Use your broker's numbers from the cost section above.
- Length. A run can use any timeframe down to one minute; how many days one run covers depends on your plan (Pricing). On M5, test a recent stretch and repeat it on another one.
How the engine compares with the MetaTrader 5 tester, and its limits: Backtest engine.
A backtest is hypothetical: it uses past prices and perfect rules. Past results don't predict future results.
For a scalper, the last word stays with the MetaTrader 5 tester on real ticks and a demo account: Backtest in the Strategy Tester.
EURUSD Scalping Starter Settings
EURUSD is the pair most scalping examples use: deep liquidity and, on many accounts, a spread near one pip in the main sessions. Liquidity only means lower friction; it is not an edge.
| Setting | Starter for EURUSD M5 |
|---|---|
| Entry rule | SMA(10) crosses above / below SMA(20) |
| Spread limit | A fixed number: 1 pip to start, then your broker's normal spread in the trading hours |
| Sessions | London and New York; outside them EURUSD M5 often moves in narrow ranges where crosses come and go |
| Stop loss | 8 to 15 pips to start, never closer than the stop level plus the spread |
| Exit | Take profit at 1R, or Exit by signal on the opposite cross |
| Size | Fixed lots of 0.01 on demo, then Risk per trade (% of the account) |
| Tester | EURUSD, M5, Every tick based on real ticks, a sample that covers both sessions |
Five-minute spread check. In Market Watch, write down the EURUSD spread at the London open, at the New York open and during one high-impact news hour, when it can jump to two or three pips. Set the tester's spread to the worst of the three, never zero. If the EA still trades, switch the spread limit on and check that the hours it blocks are the ones you would have skipped by hand.
Validation loop:
- Test with the spread limit on.
- Zero trades? Check the spread in the data before you blame the strategy: a limit below the data's spread blocks every entry.
- Run it on demo and compare the live
SYMBOL_SPREADwith the spread of the test.
If You Code It Yourself
If you write the scalper by hand, read the broker's limits once in OnInit() and check the spread before each entry:
input int MaxSpreadPoints = 15; // your broker's normal spread in the trading hours, in points
bool SpreadAllows()
{
long spread = SymbolInfoInteger(_Symbol, SYMBOL_SPREAD); // current spread, points
return spread <= MaxSpreadPoints;
}
double MinStopDistance()
{
long stopsLevel = SymbolInfoInteger(_Symbol, SYMBOL_TRADE_STOPS_LEVEL); // points
double point = SymbolInfoDouble(_Symbol, SYMBOL_POINT);
return stopsLevel * point; // price distance a stop must clear
}
If you need the bid, the ask and the time of the last tick together, SymbolInfoTick() [7] returns them in one call. Set MqlTradeRequest.deviation to the most slippage you accept, and log the fill price of each trade next to the requested price. Every error code these calls can return is in Common MQL5 EA errors.
Pre-Live Checklist
| Step | On the phone (MT5 app) | On the desktop |
|---|---|---|
| 1 | Algo trading on; the EA is attached | The right .ex5 on the right chart |
| 2 | The symbol matches the broker's name (suffixes such as EURUSD.pro) | The symbol in Market Watch; note its stop level |
| 3 | The Journal shows no repeated 10016 | Fix stops with the 10016 guide |
| 4 | The spread looks normal for the hour | The spread limit is set |
| 5 | Demo before live | Tester on real ticks, MetaTrader 5 Strategy Tester [8] |
| 6 | Funded account? | Add the prop firm rules: daily loss, max drawdown |
A well-known rule behind many "scalping" searches. People who search for a scalping robot often mean a short intraday rule. The closest well-known one in our strategy library is the London session range breakout: a 5-minute rule, not a tick scalper, and it needs the Trader plan or higher. Its history and rules.
Next Steps
- Learn: Risk management for an EA: position size from the stop, daily loss limits.
- Build: the rules in the Strategy Builder demo, or start from the MA crossover recipe and the SMA indicator.
- Test: Backtest in the Strategy Tester.
- Run: VPS for an Expert Advisor and deploy and maintain an EA.
- Gold: scalping XAUUSD has its own sizing and stop rules: EA for Gold (XAUUSD).
- TradingView: build these rules for Pine Script v6: Scalping strategy in Pine, no code.
References: OnTick [1], SymbolInfoInteger [2], Real and Generated Ticks [3], Strategy Testing [4], symbol properties [5], MqlTradeRequest [6], SymbolInfoTick [7], MetaTrader 5 Strategy Tester [8].

