Market Versus Limit Router
Most EAs pick market or limit entries once, in the code, and never revisit the choice. The right route actually depends on conditions at the moment of the signal: a wide spread makes a market fill expensive, a resting limit inside a widened spread can capture a much better price, but a genuinely fast market can leave that same limit unfilled while the setup runs away. This router evaluates spread against a configurable ceiling, checks current ATR against its own recent average to judge whether the market is moving unusually fast, and combines both with an urgency setting (patient, normal, or impatient) to choose the route per signal. A resting limit that has not filled within a configurable timeout is cancelled and re-sent as a market order automatically, so a stale setup never sits waiting for a price that already left. The entry signal itself is a plain fast/slow EMA cross, kept deliberately simple - the EA's value is the routing decision after the signal fires, not the signal generation. Every fill on both routes is compared against the signal price at the moment it fired, and a running scoreboard on the chart reports which route currently gives the better average price on this instrument. Notes and limitations The entry signal is intentionally simple and is not the point of the tool - it exists so the routing logic has real signals to act on. Only one position is tracked at a time. The volatility check needs at least 21 bars of history on the chart's timeframe before it can evaluate. The scoreboard resets when the EA is removed from the chart; it does not persist across restarts.
Expert advisor · MT5 · v1.0 · Free
About Market Versus Limit Router
Market Versus Limit Router is an expert advisor (trading robot) for MetaTrader 5 based on Moving Average and ATR. It places pending buy/sell stop or limit orders. It has 15 settings, such as Fast ma period, Slow ma period and Lots. MQL source code included.
Files in the download: MarketVersusLimitRouter.ex5, MarketVersusLimitRouter.mq5, MarketVersusLimitRouter.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 |
|---|---|---|
| Fast ma period | 10 | Fast EMA period for the demo entry signal |
| Slow ma period | 30 | Slow EMA period for the demo entry signal |
| Lots | 0.01 | Fixed lot size per trade |
| Urgency | URGENCY_NORMAL | How eager the router is to get filled now |
| Max spread for market points | 20 | Spread (points) above which a market fill is judged too expensive |
| Atr period | 14 | ATR period used for the volatility check |
| High volatility ratio | 1.5 | Current ATR / its own 20-bar average above this counts as "high volatility" |
| Limit offset pips | 2 | Distance from current price for the resting limit order |
| Limit timeout minutes | 15 | Cancel an unfilled limit and fall back to market after this long |
| Stop loss pips | 30 | Stop loss per trade, in pips |
| Take profit pips | 45 | Take profit per trade, in pips (0 = none) |
| Slippage pips | 3 | Slippage tolerance for market fills, in pips |
| Magic number | 20261207 | Magic number for orders opened by this EA |
| Max retries | 5 | Attempts per order 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 5 open File → Open Data Folder, then go to MQL5 → Experts.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 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: Buy/Sell Arrows · Pending Orders · Moving Average · ATR · MT5 Expert Advisor · MQL5 Source Code