Skip to content

Harden safety & correctness (EA + bridge) + compile CI#1

Merged
codedpro merged 5 commits into
mainfrom
harden-safety-and-ci
Jul 4, 2026
Merged

Harden safety & correctness (EA + bridge) + compile CI#1
codedpro merged 5 commits into
mainfrom
harden-safety-and-ci

Conversation

@codedpro

@codedpro codedpro commented Jul 4, 2026

Copy link
Copy Markdown
Owner

Safety/correctness hardening for the EA and Python bridge, plus a GitHub Actions workflow that compiles the EA on every push/PR.

Verified: EA compiles with MetaEditor (0 errors, 0 warnings); bridge correlation + timeout-abandon covered by a local test.

EA (bulk-add-signals.mq5)

  • Reject wrong-side order types instead of silently converting STOP<->LIMIT (which reversed trade intent); support all four pending types; validate SL/TP sides.
  • Trailing SL and safe-shutdown use the actual TP prices sent, not hardcoded pip offsets (also fixes the converted-LIMIT direction bug).
  • Recovery no longer depends on truncatable comments: compact <groupId>#<idx> comment, TP prices rebuilt from live orders, both new and legacy formats parsed.
  • Daily-loss limit resets each day and measures against equity.
  • Source made pure ASCII so it compiles on all MetaEditor codepages.

Bridge (server.py)

  • Per-request response correlation; commands abandoned on timeout so they can't fire late.
  • Optional X-API-Key auth; binds to 127.0.0.1 by default; Docker sets HOST=0.0.0.0 + API_KEY and drops --reload.

CI

  • .github/workflows/compile-ea.yml compiles the EA on a Windows runner and fails on any error.

Compile-verified only - please demo-test before live use.

Generated with Claude Code

codedpro and others added 5 commits July 1, 2026 19:54
EA (bulk-add-signals.mq5):
- Reject wrong-side order types instead of silently converting STOP<->LIMIT,
  which used to reverse trade intent (breakout vs pullback). Support all four
  pending types explicitly and validate SL/TP are on the correct side.
- Store the actual TP prices per group and use them for trailing SL (real TP1)
  and safe shutdown (real TP2) instead of hardcoded pip offsets that broke on
  any non-default TP ladder. Fixes the converted-LIMIT direction bug.
- Use a compact "<groupId>#<idx>" order comment so group/TP tokens survive
  broker comment truncation; rebuild TP prices from live orders on recovery and
  accept both the new and legacy comment formats.
- Reset the daily-loss baseline at each day boundary and measure against equity
  so floating losses count.

Bridge (server.py):
- Give each request its own response Event so concurrent calls can no longer
  receive each other's response; abandon a command on timeout so it can't fire
  late on the EA's next poll.
- Add optional X-API-Key auth and bind to 127.0.0.1 by default; Docker sets
  HOST=0.0.0.0 with an API_KEY passthrough and no longer runs uvicorn --reload.

Docs updated where behavior changed (no auto-convert; TP-aware trailing; new
Security section). Verified: EA compiles with MetaEditor (0 errors, 0 warnings);
bridge correlation + timeout-abandon covered by a local test.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Adds a GitHub Actions workflow (Windows runner) that installs MetaTrader 5,
unpacks the MQL5 standard library, and compiles bulk-add-signals.mq5, failing
the job on any compile error and uploading the .ex5 artifact on success. Adds a
build-status badge to the README.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The .mq5 was UTF-8 without a BOM and used emoji in Print() logs. MetaEditor
treats a no-BOM source as ANSI, so on a fresh Windows install (the CI runner)
each emoji corrupted its string literal -> 101 compile errors, even though a
UTF-8-locale build (local Wine) compiled it cleanly. Replaced the emoji with
short ASCII tags ([OK], [ERR], [WARN], ...) so the source compiles identically
regardless of the compiler's codepage. Logs only; no behavior change.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…lback)

The installer writes files in stages, so waiting only for MetaEditor64.exe
raced ahead of terminal64.exe and the "unpack" step crashed with file-not-
found. Merge install+unpack into one step that waits for the header the compile
actually needs (Include\Trade\Trade.mqh), and only launches the terminal as a
guarded fallback if the installer didn't lay it down.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Root cause of the 101 errors: MetaEditor resolved <Trade/Trade.mqh> from its
roaming data directory (empty), not the Program Files install dir where the
standard library lives, so every include failed and cascaded into undeclared
CTrade/CPositionInfo/CAccountInfo errors. Compiling with /portable points
MetaEditor at the install-dir MQL5 tree. (The earlier emoji were never the
cause - same 101 errors before and after the ASCII change.)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@codedpro codedpro merged commit 4576a8d into main Jul 4, 2026
2 checks passed
@codedpro codedpro deleted the harden-safety-and-ci branch July 4, 2026 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant