ENVO HQ
Command Center
Tuesday, March 24
0
Projects
0
Agents
βœ—
Gateway
0%
Live
11:05 AM
ENVO HQ
← Docs
hq/agents/agt_trading/2026-02-11/EA_EXECUTION_PLAN_MT5

EA EXECUTION PLAN MT5

Updated: 3/24/2026, 3:04:20 PM

EA Execution Plan (MT5) β€” Execution-Truth Bridge for V2.7 Alerts

Scope: engineering plan + test checklist. Not trading advice.

0) Goal

Turn TradingView V2.7 JSON alerts into deterministic, auditable MT5 actions with replay safety:

  • Parse β†’ validate β†’ dedupe β†’ (optionally) place/modify orders
  • Persist an execution journal for every alert

1) System components

  1. Alert source: TradingView script (Indicator or Strategy) sending JSON (see ALERTS_SPEC_V2_7.md).
  2. Transport: TradingView Webhook POST to your endpoint (or PineConnector-style bridge).
  3. Receiver (server): validates + stores + forwards to MT5.
  4. MT5 EA: receives commands, executes using broker symbol/precision, reports fills + errors.

If you skip the server and use PineConnector directly, you still need validation, idempotency, and journaling somewhere.

2) Execution-truth principles

  • Idempotent: same alert must not create multiple positions.
  • State machine: EA decisions depend on explicit state, not assumptions.
  • Confirm-on-close: prefer signals that only occur on bar close (default in V2.7).
  • Execution β‰  signal: a valid signal can still fail to execute; record both.

3) Data model (receiver + EA)

Unique key (dedupe)

  • event_id = sha1(tickerid + timeframe + timestamp + direction)

Stored record

  • raw JSON payload
  • receiver validation result (ok / reject reason)
  • execution request (what was sent to EA)
  • EA acknowledgement + broker order ticket(s)
  • subsequent lifecycle events (partial TP, SL, BE move)

4) EA command contract (suggested)

Even if the TradingView alert is V2.7 JSON, forward to MT5 in a normalized command:

{
  "event_id": "...",
  "source": "tv_v2_7",
  "symbol": "XAUUSD.pro",
  "direction": "BUY",
  "entry": 2034.56,
  "sl": 2029.00,
  "tp1": 2045.00,
  "tp2": 2056.00,
  "risk_percent": 1.0,
  "tp1_close_percent": 50,
  "move_sl_to_be": true,
  "meta": {
    "score": 85,
    "grade": "A",
    "pass": ["ALLOW","SESSION"],
    "block": []
  }
}

5) MT5 EA state machine (minimal)

States

  • IDLE
  • PLACED (order sent)
  • OPEN (position open)
  • TP1_DONE (partial close completed)
  • CLOSED (fully closed)
  • ERROR (terminal error; requires operator)

Transitions

  1. On command (new event_id):
    • validate symbol exists + tradable
    • normalize price precision (digits)
    • validate sl distance β‰₯ broker minimum (stops level)
    • compute lot size from risk_percent (EA-defined)
    • place market order (or pending if that’s your design)
  2. On fill:
    • set SL
    • set TP logic:
      • Option A: set TP at TP2 and manage TP1 via partial close
      • Option B: no broker TP, manage both TP1/TP2 manually
  3. On price reach TP1:
    • close tp1_close_percent
    • if move_sl_to_be: move SL to entry (or entryΒ±spread, EA-defined)
  4. On SL hit or final TP hit:
    • mark closed; journal outcome

6) Safety/guardrails

Receiver-side:

  • Reject payloads missing required keys.
  • Reject if timestamp too old (replay) unless explicit replay mode.
  • Reject if direction not in {BUY,SELL}.

EA-side:

  • Enforce MaxTradesPerSymbol.
  • Enforce OneTradePerEventId.
  • Enforce session/time filter only if you want it duplicated (otherwise trust TradingView gate).
  • Log broker errors with GetLastError() / result codes.

7) Test environment checklist

MT5 terminal setup

  • Enable Algo Trading.
  • Use a demo environment for testing.
  • Turn on Journal + Experts logs.

Symbol/precision

  • Confirm digits/point for each symbol.
  • Confirm min stop distance (StopsLevel / FreezeLevel).

Replay tests (deterministic)

  1. Send a stored payload with fixed values.
  2. Verify receiver idempotency (send twice β†’ one execution).
  3. Verify EA rejects if sl=null or stops too close.
  4. Verify partial close at TP1 triggers once.
  5. Verify SL→BE move triggers once.

8) BLOCKED / NEED

NEED (to finalize lot sizing + broker constraints):

  • Instrument list + broker symbol names.
  • Tick size / tick value for sizing.
  • Risk model choice: % of balance vs equity vs fixed lot.
  • How to treat tp2=null (ignore or compute RR-based TP2).
Files are read from second-brain/brain/ on your machine.