Engineering note · Grid basket lifecycle
An MT5 Grid EA Needs One Basket State Before It Needs More Inputs
Define one two-sided basket, one-time grid levels, basket-profit closure and restart recovery before accepting a configurable MT5 grid EA.
Buyer question
What exactly counts as one basket when buy and sell grids run at the same time?
Failure pattern
A crossed level fires again after a tick, restart or partial close because used levels were only held in memory.
Acceptance rule
One basket owns its levels, closes as one unit and resets only after owned exposure is confirmed empty.
Inputs do not define the lifecycle
Independent lot sizes, grid distances and a basket-profit target make an EA configurable. They do not define how the EA behaves when price crosses one level twice, when only part of the basket closes or when MT5 restarts with exposure still open.
The smallest useful model gives every trading cycle one basket identity. Each accepted order belongs to that basket, each level moves from unused to used once, and the profit target moves the whole basket into a closing state before any new entry path can run.
Without that state, the code is forced to guess from position count and current price. Those facts are evidence, but they do not explain whether a level has already fired or whether a close-and-reset sequence is still in progress.
Source and public evidence
One basket owns every transition
The state must answer which positions belong to the basket, which levels have already activated, whether the target has locked new entries and whether the previous cycle is fully closed. Rebuild those answers before the first post-restart trading decision.
| State | Allowed behavior |
|---|---|
| IDLE | No owned basket exists. The EA may create the first buy and sell level once. |
| BUILDING | One basket owns every submitted level and records each accepted order identity. |
| ACTIVE | The EA may add only the next unused level on each side when its distance rule is met. |
| TARGET_REACHED | The basket-profit condition is true. New entries are locked before closure starts. |
| CLOSING | Owned positions and orders are being closed and reconciled. No new basket may start. |
| RESET_READY | The old basket is confirmed empty. One clean reset may return the EA to IDLE. |
What the buyer should freeze
- 1
Ownership
Freeze symbol, Magic Number, order types and the treatment of manual or foreign positions.
- 2
Level identity
Give every buy and sell level a stable index and record when the broker accepts its order.
- 3
Distance basis
State whether spacing uses points, ticks, price units or another normalized value for the named symbol.
- 4
Basket profit
Define the account currency, included costs and exact owned positions used in the target calculation.
- 5
Close precedence
Lock new entries before closing starts and define how rejected or partial closes are reconciled.
- 6
Restart source
Name whether used levels come from persisted state, owned orders and history, or a documented combination.
Three acceptance cases
These cases define a working basket without promising a trading result. They are small enough to inspect and strict enough to expose the most expensive lifecycle mistakes.
Test 1
One-time level activation
Input: Price crosses the same grid level several times while the basket remains active.
Pass: That level creates no more than one owned order. Later valid unused levels remain available.
Test 2
Basket target and reset
Input: Combined profit reaches the written basket target while both buy and sell positions exist.
Pass: Entries lock, every owned position closes, the empty state is confirmed and exactly one fresh cycle becomes available.
Test 3
Restart with open levels
Input: MT5 restarts after several levels have activated but before the basket target is reached.
Pass: The EA rebuilds ownership and used-level state from the agreed evidence without duplicating an order or resetting the basket.
What these tests do not prove
A correct basket lifecycle does not prove profit, drawdown, challenge passing or favorable live execution. It proves that the written grid, ownership, close and restart rules lead to observable, repeatable software behavior.
Broker stop levels, hedging permissions, minimum volume, symbol digits and execution costs remain separate inputs. Freeze the exact MT5 build, account mode, symbol and broker rules before implementation.
Free next step
Write the basket before listing every input
Use the free scope builder to record ownership, level activation, basket closure, reset behavior and the three pass cases. That gives a developer one bounded lifecycle to quote and build.