Loading…

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 · MT4 · v1.0 · Free

About Market Versus Limit Router

Market Versus Limit Router is an expert advisor (trading robot) for MetaTrader 4 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.ex4, MarketVersusLimitRouter.mq4, MarketVersusLimitRouter.txt.

Trading robots can lose money. Check every setting and test on a demo account before using real funds.

Settings

SettingDefaultWhat it does
Fast ma period10Fast EMA period for the demo entry signal
Slow ma period30Slow EMA period for the demo entry signal
Lots0.01Fixed lot size per trade
UrgencyURGENCY_NORMALHow eager the router is to get filled now
Max spread for market points20Spread (points) above which a market fill is judged too expensive
Atr period14ATR period used for the volatility check
High volatility ratio1.5Current ATR / its own 20-bar average above this counts as "high volatility"
Limit offset pips2Distance from current price for the resting limit order
Limit timeout minutes15Cancel an unfilled limit and fall back to market after this long
Stop loss pips30Stop loss per trade, in pips
Take profit pips45Take profit per trade, in pips (0 = none)
Slippage pips3Slippage tolerance for market fills, in pips
Magic number20261207Magic number for orders opened by this EA
Max retries5Attempts per order action before giving up
Retry wait ms500Pause between attempts, milliseconds

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Experts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
  6. Test it first on a demo account or in the Strategy Tester.

Download the PDF guide

Tags: Buy/Sell Arrows · Pending Orders · Moving Average · ATR · MT4 Expert Advisor · MQL4 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria