forked from animatedread/Warrior_EA
| Filename | Latest commit message | Latest commit date |
|---|---|---|
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>
|
||
| .. | ||
| AtomicFile.mqh | ||
| CheckStopped.mqh | ||
| NewBar.mqh | ||
| NewsRelevance.mqh | ||
| PrintVerbose.mqh | ||
| README.md | ||
| StatusLabel.mqh | ||
| TradeChecks.mqh | ||
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
VerboseModeflag. 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.