Skip to content
All library documents

Safely Moving Pending Orders Across Stop and Limit Types

Article MQL5 articles

Summary

This article describes an implementation problem in a MetaTrader expert advisor: dragging a pending entry price can change the order’s required type, but modifying the existing server order may leave the chart and server out of sync or trigger an unintended fill. The author’s basic remedy is to remove the old order, create a replacement at the new price, and update the associated chart indicator. For limit orders, the example checks the current ask for buys or bid for sells before deciding whether to modify or recreate the order.

The discussion emphasizes that order handling depends on order type and current market price. It gives concrete code paths and a diagram-based explanation of how orders can leave and re-enter the order book, but does not provide comparative execution tests or a universally safe solution. Some cases remain imperfect, and the article explicitly warns that moving a limit order across the market can cause immediate execution and potentially an immediate stop-out. Its scope is order-management implementation, not a trading entry strategy.

Key ideas

  • Changing a pending order’s price can require changing its type as well as its price.
  • Removing and recreating an order can keep server state aligned when a direct modification cannot safely cross order types.
  • The example compares a moved buy limit with the ask and a moved sell limit with the bid.
  • A limit order moved through the market may fill immediately and can be closed quickly if its stop level is invalid.
  • The proposed implementation addresses specific cases but is not a perfect solution for every broker or order configuration.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.