Warrior_EA/System
Repository files (latest commit first)
Filename Latest commit message Latest commit date
AnimateDread 41d6a63d92 fix: make sidecar writes atomic; extract shared AtomicFile helper
FileOpen(FILE_WRITE) truncates its target on open. CNet::Save already staged
the .nnw through a temp file + rename for that reason, but the three sidecars
written beside it did not:

  .stats  ExpertSignalAIBase.mqh:5918
  .arrows ExpertSignalAIBase.mqh:6224
  .cfg    ExpertSignalAIBase.mqh:7329

Two defects followed.

1. An interrupted write published a truncated sidecar. For .cfg that is the
   worst case: LoadAndCompareTopologyConfiguration() reads a short file as a
   mismatch, which discards the trained model and restarts from era 0.

2. Windows file sharing is a mutual contract - a writer opened with no
   FILE_SHARE_* blocks every concurrent open regardless of the reader's flags.
   All three read paths carry FILE_SHARE_READ|FILE_SHARE_WRITE specifically so
   a tester agent can read them while a live chart runs; an exclusive writer on
   the same path defeated that.

Extracted CNet::Save's proven pattern into System\AtomicFile.mqh
(AtomicWriteBegin/AtomicWriteEnd) and routed all four writers through it. This
also encodes the FileMove gotcha once instead of per call site: the destination
location comes from FILE_COMMON inside the 4th arg, NOT inherited from the
source, and getting it wrong moves the file to the wrong sandbox silently.

Also fixed while in these functions:

- SaveTopologyConfiguration had 13 copy-pasted 6-line error blocks that each
  returned WITHOUT FileClose(handle), leaking the handle on every write
  failure. Collapsed to one ok-chain that closes exactly once. The on-disk
  field order and types are unchanged (asserted during the rewrite) so existing
  .cfg files still load.

- SaveChartSignals documented that pruning runs only after a successful write
  ("a failed write above leaves both the file AND the chart untouched") but
  never checked any write result, so a partial write still deleted the chart
  objects. Results are checked now, making the existing comment true.

Compiles 0 errors, 0 warnings.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-29 00:31:29 -04:00
..
AtomicFile.mqh fix: make sidecar writes atomic; extract shared AtomicFile helper 2026-07-29 00:31:29 -04:00
CheckStopped.mqh convert 2025-05-30 16:35:54 +02:00
NewBar.mqh fix: add error logging for buffer failures and reject trades on invalid stop loss 2026-07-26 12:12:14 -04:00
NewsRelevance.mqh fix(SignalNewsFilter): scope calendar veto to the traded symbol's own currencies 2026-07-18 17:22:33 -04:00
PrintVerbose.mqh convert 2025-05-30 16:35:54 +02:00
README.md feat: Enhance README and documentation for Warrior_EA project 2026-04-20 19:28:34 -04:00
StatusLabel.mqh fix: correct metric label in training output and improve status panel comments 2026-07-17 21:53:09 -04:00
TradeChecks.mqh fix: correct inference-only new-bar detection and add stop validation 2026-07-27 11:51:45 -04:00

System Subsystem (System/)

Overview

The System/ directory contains utility and infrastructure code for the Warrior EA. These modules provide essential services such as expert stop handling, new bar detection, and conditional logging, supporting robust and maintainable EA operation.

Key Components

CheckStopped.mqh

  • Function: CheckStopped()
  • Purpose: Handles expert advisor stop events. Commits and closes the database, removes the EA, and logs the stop event.
  • Integration: Should be called regularly to ensure safe shutdown and resource cleanup.

NewBar.mqh

  • Function: NewBar()
  • Purpose: Detects the arrival of a new bar (candle) on the chart.
  • Logic: Compares the current bar's time with the last seen bar time. Returns true if a new bar is detected.
  • Integration: Used for event-driven logic, e.g., only executing logic once per bar.

PrintVerbose.mqh

  • Function: PrintVerbose(string message)
  • Purpose: Conditional logging based on a VerboseMode flag. Prints messages only if verbose mode is enabled.
  • Integration: Useful for debugging and development without cluttering logs in production.

Documented April 2026. For further details, see the main project documentation.