Loading…

Trailing Pending Order

A breakout order set once and left alone can end up a long way from price by the time momentum finally arrives, either missing the move entirely or filling at a far worse price than intended once it does trigger. This EA manages that gap the way a trailing stop manages an open position's exit, just applied to the entry side instead: it keeps a Buy Stop or Sell Stop order at a fixed distance from the current market price, tightening the gap as price approaches. The move is deliberately one-directional. The order price is only ever pulled closer to the market, never pushed back out on a pullback. Without that rule the order would widen again every time price retreated, and "enter on the next small breakout from here" would silently turn into "enter on whatever eventually reaches a stale old level" - precisely the problem trailing exists to prevent on the exit side, mirrored here on entry. Limit orders are deliberately left untouched. Trailing a limit order toward price the same way would chase the entry away from the better price it exists to wait for - the opposite of what a limit order is for - so only the two stop order types are managed. When InpKeepStopDistanceConstant is on, any stop loss or take profit already attached to the order shifts by the same amount as the entry price, so the distance the trader originally set from entry stays fixed rather than silently drifting every time the order is trailed. Notes and limitations - Manages Buy Stop and Sell Stop orders only (OP_BUYSTOP/OP_SELLSTOP on MQL4, ORDER_TYPE_BUY_STOP/ORDER_TYPE_SELL_STOP on MQL5). Buy Limit and Sell Limit orders matching the magic number are left completely alone; see the full description for why. - Does not place the initial pending order - attach it to one that already exists. - If the order triggers or is deleted elsewhere, the next sweep simply stops finding it; no error is raised. - Requires AutoTrading enabled (IsTradeAllowed() on MQL4, the three-way check described above on MQL5), since modifying a pending order is a trade action.

Expert advisor · MT5 · v1.0 · Free

About Trailing Pending Order

Trailing Pending Order is an expert advisor (trading robot) for MetaTrader 5. It places pending buy/sell stop or limit orders and moves the stop loss behind price (trailing stop / break-even). It has 6 settings, such as Magic number, Trail distance pips and Min adjust pips. MQL source code included.

Files in the download: TrailingPending.ex5, TrailingPending.mq5, TrailingPending.txt.

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

Settings

SettingDefaultWhat it does
Magic number20260412Magic number of the pending order(s) to manage
Trail distance pips15Distance kept between the order and current price
Min adjust pips1.0Minimum improvement before modifying the order
Keep stop distance constanttrueShift SL/TP with the order so their distance from entry stays fixed
Max retries5Attempts per modification 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 5 open File → Open Data Folder, then go to MQL5 → Experts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 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: Breakout · Momentum · Trailing Stop & Break-even · Pending Orders · MT5 Expert Advisor · MQL5 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria