Skip to content
All library documents

Two-Sided Martingale Grid with Basket Profit Exits

Article MQL5 code base

Summary

The document describes a two-sided pending-order grid with three stages. It begins with a symmetric ladder, increases the opposite side’s pending size after the nearest level fills, and switches to a doubling sequence after either side has two fills. Filled orders remain unchanged, while additional levels are added as the grid expands. The system closes all positions and cancels pending orders when combined floating profit, swap, and commission reach a basket target; an optional basket loss cutoff can trigger the same action.

Operational details include per-tick order reconciliation, market fills when price has already crossed a pending level, recovery after a terminal restart, and separate settings for metals and index CFDs. The document is a description of a specific implementation, not evidence of tested performance. It warns that sustained moves against the grid can escalate exposure and drawdown, with no default per-trade stop and the basket loss cutoff disabled by default. Broker constraints, spread, lot sizing, and account equity materially affect behavior.

Key ideas

  • The grid starts with pending orders on both sides and increases lot sizes as fills accumulate.
  • A basket profit target closes all open positions and cancels remaining orders.
  • An optional basket loss cutoff is disabled by default, while individual trades have no default stop loss.
  • Per-tick reconciliation can replace missed pending orders with market fills when price has crossed their levels.
  • Sustained directional moves can cause rapidly growing exposure and drawdown in this martingale design.

Tags

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