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
- Alert source: TradingView script (Indicator or Strategy) sending JSON (see
ALERTS_SPEC_V2_7.md). - Transport: TradingView Webhook POST to your endpoint (or PineConnector-style bridge).
- Receiver (server): validates + stores + forwards to MT5.
- 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
IDLEPLACED(order sent)OPEN(position open)TP1_DONE(partial close completed)CLOSED(fully closed)ERROR(terminal error; requires operator)
Transitions
- On command (new
event_id):- validate symbol exists + tradable
- normalize price precision (digits)
- validate
sldistance β₯ broker minimum (stops level) - compute lot size from
risk_percent(EA-defined) - place market order (or pending if thatβs your design)
- 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
- On price reach TP1:
- close
tp1_close_percent - if
move_sl_to_be: move SL to entry (or entryΒ±spread, EA-defined)
- close
- 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
directionnot 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)
- Send a stored payload with fixed values.
- Verify receiver idempotency (send twice β one execution).
- Verify EA rejects if
sl=nullor stops too close. - Verify partial close at TP1 triggers once.
- 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).