MT5 Scalping EA Guide: Settings, Spread Filters, and MQL5 Example

How scalping EAs work: timeframes, spread, entry/exit logic, and risk. Build or adapt a simple scalping EA for M1/M5 in MQL5.

📖 16 min read

📝 3,042 words

🏷️ MQL5 and Expert Advisors

Share this article:

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

CheckWhat to look atWhy it decides a scalper
1. Costs as a share of the targetSpread + commission + expected slippage, in pips, divided by the take-profit distanceA 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 deviationThe EA's maximum deviation in points and the account's execution modeA fast market fills market orders away from the quoted price
4. Stop and freeze levelSYMBOL_TRADE_STOPS_LEVEL and SYMBOL_TRADE_FREEZE_LEVEL of the symbolA stop closer than the stop level is refused (error 10016); inside the freeze level an order cannot be changed
5. LatencyThe ping from the terminal (or the VPS) to the broker's serverEach millisecond between signal and fill is price the scalper does not control
6. Demo forward runThe same EA on a demo account, at least through a few London and New York sessionsIt 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).

TargetCost share at 1 pipCost share at 2 pipsHits needed at 1 pipHits needed at 2 pips
3 pips33 %67 %67 %83 %
5 pips20 %40 %60 %70 %
10 pips10 %20 %55 %60 %
20 pips5 %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.

SettingStarting pointWhy
TimeframeM1 or M5M1 gives more signals and more noise; M5 is often cleaner
PositionsOne at a timeOverlapping scalps multiply the costs of one idea
Spread limitA share of the stop, or a fixed limit for your broker's normal spreadSkips the rollover and thin hours
SessionsLondon and New YorkThe usual hours of the tightest spreads on major pairs
Stop lossAt least the stop level, plus the spreadBelow it the order is refused
Tester modeEvery tick based on real ticksFills inside the bar in the real order
Before liveDemo through several sessionsReal 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:

StepWhat you set for this recipe
1. Information and platformName, MetaTrader 5 (MQL5), market: currency pairs
2. TimeframesM5 as the Trading timeframe
3. Entry rulesBuy rule: SMA(10) crosses above SMA(20); switch on Sell mirrors Buy for the sell rule
4. FiltersMarket sessions: London and New York, When any of them is open; a Spread limit (see below)
5. ExitsStop loss and Take profit, in pips or as an ATR multiple; optional Close after N bars
6. Risk and money managementRisk per trade (% of the account) or Fixed lots; Open positions: 1; optional Entries per day and Daily loss limit
7. Review and saveFix anything in the Check list, Save strategy, then Backtest this strategy or Get the code
AlfaTactix Strategy Builder, Step 3 Entry rules: buy when SMA(10) on M5 crosses above SMA(20); the sell rule mirrors it
AlfaTactix Strategy Builder, Step 3 Entry rules: buy when SMA(10) on M5 crosses above SMA(20); the sell rule mirrors it

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.

AlfaTactix Strategy Builder, Step 4 Filters: trade only when the London or New York session is open
AlfaTactix Strategy Builder, Step 4 Filters: trade only when the London or New York session is open

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.

mql5
//| 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_SPREAD at 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.

SettingStarter for EURUSD M5
Entry ruleSMA(10) crosses above / below SMA(20)
Spread limitA fixed number: 1 pip to start, then your broker's normal spread in the trading hours
SessionsLondon and New York; outside them EURUSD M5 often moves in narrow ranges where crosses come and go
Stop loss8 to 15 pips to start, never closer than the stop level plus the spread
ExitTake profit at 1R, or Exit by signal on the opposite cross
SizeFixed lots of 0.01 on demo, then Risk per trade (% of the account)
TesterEURUSD, 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:

  1. Test with the spread limit on.
  2. Zero trades? Check the spread in the data before you blame the strategy: a limit below the data's spread blocks every entry.
  3. Run it on demo and compare the live SYMBOL_SPREAD with 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:

mql5
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

StepOn the phone (MT5 app)On the desktop
1Algo trading on; the EA is attachedThe right .ex5 on the right chart
2The symbol matches the broker's name (suffixes such as EURUSD.pro)The symbol in Market Watch; note its stop level
3The Journal shows no repeated 10016Fix stops with the 10016 guide
4The spread looks normal for the hourThe spread limit is set
5Demo before liveTester on real ticks, MetaTrader 5 Strategy Tester [8]
6Funded 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

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].

Frequently Asked Questions

Start on M1 or M5 with one position at a time, a spread limit, and a stop that clears the broker's stop level. Test with Every tick based on real ticks when your broker has tick history, then on a demo account. "Best" settings depend on your broker's spread and commission, so measure those first: see the cost table in this guide and Backtest in the Strategy Tester.

A scalper aims for a few pips, so the spread is a large share of each target. SymbolInfoInteger(_Symbol, SYMBOL_SPREAD) returns the current spread in points; the EA skips an entry when it is above your limit. A limit tied to the stop (for example "spread at most 10 % of the stop") follows the trade's own size instead of a fixed number.

Scalping entries and exits happen inside a bar. "Every tick" rebuilds ticks from minute bars; "Every tick based on real ticks" replays the broker's recorded prices, so spread changes and the order of highs and lows are the ones that happened. "1 minute OHLC" and "Open prices only" are too coarse for a few-pip target.

Usually because of costs and fills, not the signal: the spread widens at news and at the daily rollover, market orders slip, and a test with zero spread or on "1 minute OHLC" guesses the order of prices inside each bar. Test on real ticks with your broker's spread and commission, add a spread limit, and run the EA on a demo account before live.

Start with a fixed limit of 1 pip (10 points on a 5-digit quote), then set it just above your broker's normal spread in the hours the EA trades. If a test shows zero trades, compare the limit with the spread in the data before you loosen it, and raise it (for example to 1.5 pips) only if your normal spread is wider.

No page can promise that, and a sales page is not evidence. Judge any scalper, free or paid, with the checks in this guide: its costs as a share of the target, a real-tick test with your broker's spread and commission, a demo run, and no grid or martingale. Or build your own rules in the Strategy Builder demo, so you know exactly what the EA does.

In the AlfaTactix Strategy Builder: Step 2 sets M5 as the trading timeframe, Step 3 the entry rule (for example SMA(10) crosses above SMA(20), with Sell mirrors Buy), Step 4 the sessions and the spread limit, Steps 5 and 6 the stop, target and risk, and Step 7 saves the strategy, backtests it and gives the .mq5 file. Try it in the demo first.

References

  1. MetaQuotes, MQL5 Reference. OnTick. https://www.mql5.com/en/docs/event_handlers/ontick
  2. MetaQuotes, MQL5 Reference. SymbolInfoInteger. https://www.mql5.com/en/docs/marketinformation/symbolinfointeger
  3. MetaQuotes, MetaTrader 5 Help. Real and Generated Ticks. https://www.metatrader5.com/en/terminal/help/algotrading/tick_generation
  4. MetaQuotes, MetaTrader 5 Help. Strategy Testing. https://www.metatrader5.com/en/terminal/help/algotrading/testing
  5. MetaQuotes, MQL5 Reference. Symbol Properties. https://www.mql5.com/en/docs/constants/environment_state/marketinfoconstants
  6. MetaQuotes, MQL5 Reference. The Trade Request Structure (MqlTradeRequest). https://www.mql5.com/en/docs/constants/structures/mqltraderequest
  7. MetaQuotes, MQL5 Reference. SymbolInfoTick. https://www.mql5.com/en/docs/marketinformation/symbolinfotick
  8. MetaQuotes. MetaTrader 5 Built-in Trading Strategy Tester. https://www.metatrader5.com/en/automated-trading/strategy-tester