Files
conversation-history/Trading/MT5/2026-04-29 OrdersEA Smart Grid - Band Edge & Set Cleanup Design.md

3.9 KiB
Raw Permalink Blame History

2026-04-29 OrdersEA Smart Grid — Band Edge & Set Cleanup Design

Status: Decision pending — do not implement until design question is resolved.


Context

Session on 2026-04-29 picking up from the Apr 23 fix checklist and Apr 27 set file updates. Two issues surfaced:

1. Lingering trades on set changes (low priority)

When .set files are reloaded in MT5, existing positions placed under the old parameters remain open — they're not closed or re-evaluated. The Apr 27 session updated all 16 grid-*.set files (fixing GetOut=Y → GetOut=N on usdjpy, xauusd, gbpusd, gbpjpy). Any positions open at that time were left as-is.

Cleanest fix when ready: run GetOut=A on each chart before reloading a new set, or add an OnDeinit option to close positions on parameter change.


2. Band edge management (higher priority — blocked on design decision)

Current behavior

  • At GridHigh/GridLow (R1/S1 or ATR-derived edge): IsRangingMarket() cancels pending limit orders but leaves open positions running.
  • At R2/S2 (wider breakout): IsBreakout() closes everything via CloseAllPositions().

The gap: positions stranded at the edge (e.g. buy positions near GridLow when price pushes to that wall and sits there) — not wrong enough to trigger the R2/S2 close, but directionally trapped.

Three options discussed

Option Mechanism Trade-off
Side-close at edge When price > GridHigh, close all buy-side positions; when price < GridLow, close all sell-side Surgical, fits existing code path at line 1263. May exit early on wicks.
Timeout at edge If price stays outside [GridLow, GridHigh] for N bars, close stranded side Avoids wick panic-close. Adds state (bar counter).
ATR buffer zone InpEdgeBufferPoints: when price enters within buffer of either wall, tighten stops on approaching side Softest. Gives positions room to recover. More complex.

Recommended: Option 1 (side-close at edge) — targeted extension of the "Range filter tripped" path in OnTick() around line 1263. No new input needed if "at the edge = wrong side" is accepted as the rule.


Blocker: Unresolved Design Question (from Apr 23 checklist)

The band edge implementation depends on which model the EA is running:

Is OrdersEA a true multi-level averaging grid or a one-fill-per-side range system?

This was flagged as a decision point in the Apr 23 Fix Checklist and is still open.

What the code currently does (lines 1312–1335)

After the first fill on either side, it cancels remaining same-side pending limits — not opposite-side as the comment says. This means in practice it behaves like a one-fill-per-side system, even though the parameters (MaxLevels, multi-level grid placement) suggest it was designed as a true averaging grid.

Why this matters for edge cleanup

  • One-fill-per-side: hitting the edge = one open position against you → close it and reset. Side-close option is correct.
  • True averaging grid: hitting the edge means all levels filled → averaging down → you only bail at R2/S2 breakout. Closing at the edge would cut the recovery leg.

Decision needed before implementing

  1. Confirm the intended model: true averaging grid vs one-fill-per-side range system.
  2. Fix the cancellation logic (lines 1312–1335) to match that intent — currently the code and comment contradict each other.
  3. Then implement the chosen edge-cleanup strategy.


Session recorded: 2026-04-29