Commit graph

196 commits

Author SHA1 Message Date
AnimateDread
53599d5883 Merge branch 'main' of https://forge.mql5.io/animatedread/Warrior_EA 2026-07-27 09:25:03 -04:00
AnimateDread
ff2ece0249 fix: increase min activation deriv floor and seed RNG for fresh topology
Raise MIN_ACTIVATION_DERIVATIVE from 1e-4 to 1e-3 in both Network.cl and Network.mqh
to strengthen the escape signal through saturated hidden neurons. This provides a 10x
stronger safety net against fp32 OpenCL-specific saturation, complementing the earlier
output-layer fix (logit activation instead of sigmoid) that resolved the primary neutral
collapse bug.

Add MathSrand(GetTickCount()) before BuildFreshTopology() in ExpertSignalAIBase.mqh
to guarantee genuinely random weight initialization after genetic tuner evaluations,
matching the final-retrain path and Warrior_EA.mq5's OnInit. This prevents the previous
deterministic RNG state from dominating weight init.

Also remove UTF‑8 BOM from ExpertSignalAIBase.mqh and Network.mqh for cleaner encoding.
2026-07-27 09:24:53 -04:00
9108cdb44b docs: overhaul German market description for clarity and new features
Restructured the German market description with clearer headings, an updated feature list (including structural stops and full journal), new sections for universal applicability and signals, and improved overall readability.
2026-07-26 23:52:28 -04:00
0612eba754 docs(market): enhance MACD and Ichimoku period explanations
Provide additional details about the indicators' sensitivity and multi-timeframe support/resistance to improve clarity across all language versions.
2026-07-26 23:33:14 -04:00
a228d1bde7 feat(trade): implement trade safety checks per Article 2555 and resource limits
Add freeze-level checks, no-change modification skipping, entry price routing, and per-tick/memory budget monitoring. Override trade actions (Open, Close, Reverse, TrailingStop, TrailingOrder) to validate at the final gate before sending orders.
2026-07-26 23:08:32 -04:00
5da111d61f fix: correct totalTrades variable type to double 2026-07-26 21:15:57 -04:00
9882ea929e feat: add OnTester linear equity optimization with drawdown decimal fix
Introduce a custom OnTester() function to score backtest results
for genetic optimization, targeting smooth linear equity curves.
The score combines profit factor, recovery factor, Sharpe ratio,
and trade density, with a drawdown penalty.

Fixes a bug in the drawdown penalty where the percent value was
not converted to decimal before scaling, causing a near-zero
penalty. Also adjusts brace indentation for consistency.
2026-07-26 21:09:53 -04:00
1e4c54b95a refactor: update classic signal presets and disable close vote by default
- Append '(classic)' to RSI period 14, indicator period 14, risk-reward 1:2, and risk percent 1 preset comments
- Change Min_Vote_Close default from VOTE_CLOSE_80 to VOTE_CLOSE_DISABLED
2026-07-26 18:48:34 -04:00
a29e6677b0 docs: update market descriptions for MACD/Ichimoku and revised voting thresholds 2026-07-26 18:44:07 -04:00
b2069bcee4 feat(signals): add MACD/Ichimoku presets and Vote_Close disabled option
Add MACD_FAST, MACD_SLOW, MACD_SIGNAL presets and Ichimoku Tenkan, Kijun, Senkou presets to InputEnums.mqh. All combinations are designed to satisfy the respective indicator's validation rules (fast < slow for MACD, Tenkan < Kijun < Senkou B for Ichimoku), eliminating init errors and allowing the auto-tuner to perturb settings independently.

Introduce VOTE_CLOSE_PRESETS enum with a Disabled option (value 101) that bypasses vote-driven position closing via arithmetic thresholding, removing the need for a separate boolean flag. This ensures positions exit only via stop-loss, take-profit, or trailing when disabled.
2026-07-26 18:33:12 -04:00
8d4fe088b8 refactor: unify AI and classic vote parameters to Min_Vote_Open/Close
Removes standalone AI confidence parameters (MinAIConfidence, MinAIExitConfidence) and replaces them with unified Min_Vote_Open and Min_Vote_Close thresholds that apply to both AI and classic engines. Updates all code comments, report suggestions, and market descriptions accordingly, simplifying configuration and ensuring consistent vote requirements across entry and exit logic.
2026-07-26 17:27:51 -04:00
a17f8f1e15 fix(signal): snapshot alternation gate to prevent premature consumption on discarded votes
Add BeginVote/RevokeVote lifecycle hooks to ExpertSignalCustom and ExpertSignalAIBase.
Snapshot m_lastNonNeutralSignal before condition evaluation in Direction(), and restore
the snapshot if the vote is later discarded (e.g., Hybrid quorum shortfall).
Previously, a discarded vote still consumed the alternation gate, which could
permanently gate out valid signals until the opposite direction appeared.
2026-07-26 17:09:13 -04:00
08aefbc736 :752 — the window average is now computed after folding in this call's own result, so what's returned always includes the current tick.
:106 — window key changed from the 0-59 sec field to a full datetime. Fixing #1 alone would have replaced "always 0" with "cumulative average of every bar since startup", since the window still never rolled over.
:746 — restored result /= number. number was being counted and then never used, leaving a raw sum where the base class averages. MA's 60 + RSI's 100 = 160 tripped the ±100 range check and got zeroed — it discarded precisely the strongest agreed setups.
2026-07-26 15:31:09 -04:00
AnimateDread
58bdac1328 fix: handle legacy neuron classes in BlendWeightsFrom to avoid UB
BlendWeightsFrom now uses CObject::Type() to correctly identify neuron classes, avoiding undefined behavior when neurons are from the plain-CPU hierarchy (CNeuron, CNeuronConv, CNeuronPool, CNeuronLSTM). Weight blending for those legacy classes is also implemented.
2026-07-26 14:45:08 -04:00
AnimateDread
3c8f41e6ab fix: preserve historical arrows on rescan and remove temporary throughput diagnostics
- Arrow deletion now scoped to rescan window (barsNow) instead of all arrows, preventing loss of multi-year arrow history on Show Signals click.
- Removed temporary throughput diagnostic counters and logging added to investigate performance regression; issue resolved.
2026-07-26 14:08:59 -04:00
AnimateDread
0233664d29 feat: add raw argmax tally to rescan logs, raise train time budget to 200ms
The commit adds three counters (`m_rescanRawBuy`, `m_rescanRawSell`, `m_rescanRawNeutral`) that accumulate the raw argmax signal before the prior-correction step in `AdvanceChartSignalRescan`. This distinguishes a model that outputs mostly Neutral from one where adjusted signals suppress non-Neutral arrows. The rescan completion log now reports both the pre-decluttering tallies and the time. Additionally, `TRAIN_TIME_BUDGET_MS` is increased from 120 to 200 ms to improve throughput (as noted in the comment), balancing UI responsiveness and training speed.
2026-07-26 13:58:05 -04:00
AnimateDread
f193429299 refactor: make RescanPending() public and update comments for deferred rescan logic 2026-07-26 12:55:31 -04:00
AnimateDread
1bef4fea08 refactor(expert): split RescanChartSignals into async start/advance methods
The old RescanChartSignals ran the entire per-bar inference loop synchronously,
blocking the button-click handler for a potentially long duration on large lookbacks.
Replaced with StartChartSignalRescan (cheap setup) and AdvanceChartSignalRescan
(time-boxed slices) so the heavy work is drained from PollTraining's timer without
freezing the UI.
2026-07-26 12:52:56 -04:00
AnimateDread
15226b64df feat: add manual rescan of chart signal arrows from deployed model
Introduce `RescanChartSignals()` method and `SIGNAL_RESCAN_LOOKBACK_BARS` define to allow operators to replace stale historical arrows (e.g., from years-old training runs) with fresh inferences from the currently deployed weights on recent bars. This prevents outdated signals from lingering on the chart and ensures the displayed set matches what a live re-render would produce.
2026-07-26 12:36:56 -04:00
AnimateDread
5247c34fe9 fix: add error logging for buffer failures and reject trades on invalid stop loss 2026-07-26 12:12:14 -04:00
AnimateDread
c5f3d56542 chore: move and rename Market_Description.html to Market Descriptions/ subdirectory 2026-07-26 12:11:56 -04:00
AnimateDread
fc0b244aa0 feat: implement deferred chart arrow restore to avoid frozen OnInit 2026-07-26 11:17:55 -04:00
AnimateDread
2cf68e2e87 fix: skip weight save on inference-only runs and detect stale cache
PersistWeightsOnShutdown now returns early when m_inferenceOnly is true,
preventing the tester cache from being overwritten with untrained state.
InitNeuralNetwork compares modification timestamps of the production model
(FILE_COMMON) and the agent-local cache, re-seeding when the production
copy is newer. This ensures backtests always run the latest deployed
weights even when the cache file persists across runs. Also moved
LoadChartSignals() call to after the config fingerprint is appended,
so that persisted arrows are correctly keyed per configuration.
2026-07-26 10:59:46 -04:00
AnimateDread
b7ef83f8c6 fix(ai,expert): add FILE_SHARE flags to avoid 5004 errors on deployed models
Add FILE_SHARE_READ and FILE_SHARE_WRITE to all FileOpen calls in CNet::Load,
CNet::LoadCheckpoint, and in ExpertSignalAIBase (LoadModelStats, LoadChartSignals)
so that reading model files does not fail with error 5004 when another process
(e.g., a live chart) holds the file. Replace FileCopy with the new CopySharedFile
function for sidecar files (.cfg, .stats, _shadow.nnw) to perform share-aware
copying, preventing the same failure during tester seeding. This ensures the EA
can read and copy model artifacts even while a deployed instance is running.
2026-07-26 10:46:19 -04:00
AnimateDread
6e47019be5 refactor: add exponential backoff retry logic and bar-close autosave
Replace fixed short-delay retries in CopyFileWithRetry and LoadNetWithRetry with exponential backoff (8 attempts, cap at 2s) to reliably handle transient file locks from AV/EDR or concurrent saves.
Change autosave trigger from a fixed 300-second wall-clock timer to firing on new bar close, reducing unnecessary overwrites and narrowing the collision window with backtest FileCopy operations.
2026-07-26 10:27:38 -04:00
AnimateDread
377aa6bbc4 fix: handle transient file locking during concurrent model saves and loads
Add retry logic (CopyFileWithRetry, LoadNetWithRetry) to the tester's seeding path in ExpertSignalAIBase.mqh, and print diagnostic error messages in CNet::Load (Network.mqh) when FileOpen fails. This addresses silent failures caused by transient Windows sharing violations that occur when a live chart's atomic Save() overlaps with a Strategy Tester agent's FileCopy or FileOpen on the same production file. The new helpers retry the operation a few times with a short pause instead of silently falling back to an untrained model.
2026-07-26 10:15:56 -04:00
AnimateDread
2b666f6744 refactor: compress whitespace and divs in Market_Description.html 2026-07-26 09:19:38 -04:00
AnimateDread
c30a10f7b9 fix(ExpertSignal): convert TP from ATR-relative to risk-relative to fix zero-trade bug
The previous TP calculation used ATR from entry, decoupled from the swing-anchored SL distance. This caused the Min_Risk_Reward_Ratio rejection filter to always fail because reward < 2*risk with default settings, preventing any trades. Now TP is a multiple of the actual trade risk (entry-to-stop distance), restoring coupling and ensuring the default RR filter is satisfiable. Also enforce minimum SL distance before TP calculation to maintain correct risk-ratio.
2026-07-25 22:33:45 -04:00
AnimateDread
8ae14c60a8 fix: protect TargetCPULoad for Market build and update description
The Market build has no DLL tier (WarriorCPU.dll is compiled out per MQL5 Market rules), so the TargetCPULoad input would have sat unused in the Inputs tab. Now it is conditionally compiled as a const when WARRIOR_MARKET_BUILD is defined, keeping the call site intact while avoiding a dead input.

The Market_Description.html was rewritten to better explain the EA's neural network, its self-training on unseen data, and the dual classic/AI signal paths, along with installation details and screenshots.
2026-07-25 21:32:15 -04:00
AnimateDread
d6bbf26785 fix(ExpertSignalAIBase): add primary occurrence flag to correct IS accuracy under oversampling
The queue duplicates minority bars up to repCount (~21x at 30.7:1 imbalance), causing IS accuracy to be scored over an ~58%-directional set while OOS counts the real ~6% distribution. This made the IS/OOS gap misleading (e.g. 77% vs 12%), appearing as catastrophic overfitting when OOS was actually stronger (1.97x vs 1.33x lift). By marking only the first occurrence per bar with `m_isTrainQueuePrimary` and using that flag in the counter, both metrics now measure the same natural class distribution, making the gap directly interpretable as generalization. Backprop and training remain unaffected—every occurrence still trains as before.
2026-07-25 19:34:24 -04:00
AnimateDread
69307ff121 feat: implement manual deploy and retrain in ExpertSignalAIBase
Extract shared persistence logic into PersistDeployedModel() to guarantee consistency across all deploy paths (ladder, era-cap, stop, and manual). Add DeployNow() to let the panel button finalize the current best checkpoint as the live model, and RetrainDeployed() to revert deployment and resume training from the deployed weights without starting from scratch. This enables operator-controlled deployment while preserving online continual learning.
2026-07-25 16:39:11 -04:00
AnimateDread
c7e533a880 feat(ExpertSignalAIBase): add plateau ladder escalation and legacy MinWR shim
Implement a plateau detection mechanism that escalates through warm restart, gamma annealing, and eventual deployment when balanced accuracy stagnates for `PLATEAU_PATIENCE_ERAS`. Also add a compatibility shim for the removed `MinWR` input to preserve model filenames and `.cfg` layout.
2026-07-25 15:55:56 -04:00
AnimateDread
d5575db339 fix: suppress repeated OpenCL/DirectML probe messages across multiple CNet instances
A single EA run instantiates several CNet objects (main net, EMA shadow, OOS clones, etc.). Each previously ran its own OpenCL/DirectML probe, printing redundant error banners (e.g., "OpenCL not found") and compute tier messages.

Added process-wide static flags `s_openclUnavailable` and `s_computeTierLogged` to skip subsequent probes and log once per process. This eliminates log clutter and avoids unnecessary probe overhead on hosts without OpenCL.
2026-07-25 13:03:45 -04:00
AnimateDread
582e1dec59 fix: correct CLayer::CreateElement signature to prevent model load failures
Rename the original `CreateElement` with a defaulted `weighScale` parameter to `CreateElementScaled` and provide a proper virtual override that matches the base `CArrayObj::CreateElement` signature exactly. This ensures `CArrayObj::Load()` dispatches correctly, fixing a bug where every saved model load failed at the first layer. Update all call sites in `CNeuronBase::Init` and `CNeuronPool::Init`. Additionally, enhance error diagnostics in `CNet::Load` to distinguish between file truncation and code faults (such as the signature mismatch).
2026-07-25 12:02:38 -04:00
AnimateDread
b09c3a5f4e feat(network): add quiet parameter to CNet::Load for graceful miss handling
The `Load` method now accepts an optional `quiet` flag that suppresses diagnostic
`Print` statements when set to `true`. This is used by callers that anticipate
a load failure and handle it gracefully — for example, the EMA shadow-net
bootstrap on a CPU-DLL box, which cannot hold a second full network. The main
model load keeps `quiet=false` so actual failures remain visible.
2026-07-25 11:05:28 -04:00
AnimateDread
f70824b8c2 fix(AI): correct FileMove destination flags to prevent model save in wrong sandbox 2026-07-25 10:40:47 -04:00
AnimateDread
703a1f46d6 fix: improve load diagnostics and prevent shutdown crash
- In Network.mqh: Add upfront file size check to distinguish truncated files from backend allocation failures during model load, improving error diagnosis.
- In ExpertSignalAIBase.mqh: Remove redundant shadow net save on shutdown to avoid doubling shutdown cost and exceeding MT5's deinit budget, preventing abnormal termination and subsequent retrain.
- In Warrior_EA.mq5: Reduce training timer interval from 5s to 250ms to allow more frequent training cycles instead of sitting idle ~98% of the time.
2026-07-25 02:01:05 -04:00
AnimateDread
5d6f03014e fix: implement atomic file save in CNet::Save to prevent data corruption
The previous save directly wrote to the target file, which could leave a truncated/partial file if the process was force-killed (e.g., MT5 deinit timeout). Now the save writes to a temporary file (.savetmp) and only renames it over the real file after a successful write. This ensures that an interrupted save never corrupts the last good model. Additionally, improved diagnostics in CNet::Load to distinguish corrupt/incompatible files from compute errors.
2026-07-25 01:21:05 -04:00
AnimateDread
5fda52b212 docs: clarify cumulative accuracy as directional win-rate excluding neutral calls
Updated comments across ExpertSignalAIBase.mqh to explicitly state that the
compounded accuracy metric is a directional win-rate (Buy/Sell predictions only)
and that neutral/no-trade calls are excluded to avoid inflating the rate (since
neutral is the ~94% majority). The cumulative counters now only increment when
the prediction is directional, ensuring the panel reflects genuine trade quality
rather than overall label accuracy.
2026-07-25 01:07:21 -04:00
AnimateDread
3f0d1557de feat: add compounded accuracy counters and remove fired-hitrate threshold
Replace the display-only MIN_FIRED_FOR_HITRATE with persistent cumulative accuracy counters (m_cumIsCorrect, m_cumIsTotal, m_cumOosCorrect, m_cumOosTotal) that survive era-to-era and restart via .stats. New ComputeCompoundedAccuracyLine() builds the panel line from these counts, providing a stable "accuracy over all validated signals so far" metric.
2026-07-25 00:02:34 -04:00
AnimateDread
b9fe2d865f fix: reorder shutdown to ensure chart cleanup before weight persistence
Split `PersistOnShutdown` into `PersistWeightsOnShutdown` (heavy weights save) and `ShutdownChartCleanup` (save arrows + purge chart).  In `OnDeinit`, run panel destruction and per‑signal chart cleanup **before** the weight persistence, preventing leftover chart objects when the weight save stalls or faults past MT5's deinit budget.
2026-07-24 21:56:53 -04:00
AnimateDread
aba963a97d feat: require minimum fired calls for hit-rate display
Add MIN_FIRED_FOR_HITRATE constant (10) to the simple panel and training status hit-rate display. Update ScheduleTrainingIfNeeded and UpdateTrainingStatusLabel to only show a percentage when a side has at least MIN_FIRED_FOR_HITRATE live-fired calls; otherwise show "n/a" or "measuring". This prevents misleading early "0%" or "measuring" output from a single sample, while keeping full detail in logs and verbose panel.
2026-07-24 21:42:26 -04:00
AnimateDread
635cb555c1 fix: force isInitialized=false on weight reset to avoid config mismatch
- ResetWeights now passes `false` (not `m_isInitialized`) to SaveTopologyConfiguration so the config fingerprint matches the fresh-init write (always false). Prevents spurious "Configuration mismatch" that would discard the just-reset weights.
- UpdateTrainingStatusLabel: collapse hit-rate display to "measuring..." when neither side has fired yet; once at least one side fired, show both with "n/a" for missing side.
2026-07-24 21:36:02 -04:00
AnimateDread
d7c550c470 feat: add in-memory weight snapshot/restore for mid-run stability
Add CaptureWeights and RestoreWeights methods that snapshot every neuron's weights into host arrays (CArrayDouble per neuron) and restore them in-place via setWeights. This replaces the file-based SaveCheckpoint/LoadCheckpoint for the mid-run best-era rollback, because the file path re-creates neurons (CLayer+Init) which fails on the multithreaded CPU-DLL backend (CDirectMLMy/WarriorCPU.dll) that cannot allocate a second full set of neuron tensors while the live set exists. In-memory weight copy uses only getWeights/setWeights, already proven by the per-era shadow blend. Snapshots weights only (not Adam moments); the regression handler decays eta on restore and clips per-step deltas to prevent stale-moment overshoot. Snapshot is valid only within a single Train() run. Also adds HaveWeightSnapshot() query and the m_weightSnapshot / m_haveWeightSnapshot member variables.
2026-07-24 21:21:47 -04:00
AnimateDread
339369fe99 feat: add common parameter to checkpoint save/load for consistent file location
SaveCheckpoint and LoadCheckpoint in Network.mqh now accept a `bool common` flag. When true, the ephemeral checkpoint is stored in FILE_COMMON (co-located with the model's .nnw/.cfg/.stats/_shadow.nnw), preventing a parallel folder tree under the terminal-local Files directory. ExpertSignalAIBase.mqh is updated to pass the same flag to file existence checks and deletions, ensuring all sidecar files use the correct location.
2026-07-24 18:56:20 -04:00
AnimateDread
bf82f4a034 fix(AI/Network): atomic checkpoint restore to prevent zero-layer state on failure
Previously, LoadCheckpoint cleared the live layers before reading, so any read failure (truncated/corrupt file, OCL init hiccup) left the network with zero layers. This collapsed predictions to neutral, caused Save to refuse writing 0-layer stubs, and wiped chart arrows. Now the checkpoint is loaded into a temporary layer set that is swapped in only on full success; on failure the current weights are preserved and a diagnostic message is printed.
2026-07-24 18:37:54 -04:00
AnimateDread
4f5003dc78 fix: prevent CLayer memory leak on network load failure
In CNet::Load and CNet::LoadCheckpoint, when a CLayer object is allocated but subsequent Load() or layers.Add() fails, the layer was not freed, causing a memory leak (reported as "1 object of class 'CLayer'" on MT5 unload). Added a check for invalid pointer and explicit deletion of the layer before breaking from the loop, ensuring proper cleanup.
2026-07-24 12:01:09 -04:00
AnimateDread
b78bb5d2ec feat: support pure-MQL5 CPU inference for OCL neuron layers without GPU backend 2026-07-24 11:52:19 -04:00
AnimateDread
303d46da8b fix: reset training state on failed network load to prevent untrained model deployment
A failed load of a corrupt/empty network could leave trainingComplete=true, causing the freshly built topology to be treated as already converged. This forced the model to never train, run inference on random weights, and delete all chart arrows. The fix ensures the state is reset to a genuine fresh start so BuildFreshTopology() actually gets trained.
2026-07-23 21:46:38 -04:00
AnimateDread
72797ab7ba feat: prevent saving empty network and add logit adjustment calibration
- Guard CNet::Save to refuse writing a 0-layer network (prevents overwriting ~18MB model with empty stub)
- In CNet::Load and LoadCheckpoint, treat 0-layer files as load failure (older stubs still on disk)
- Introduce LOGIT_PRIOR_STRENGTH_PRESETS enum (0–100%) to control logit adjustment tau
- Prepare member variables and AdjustedSignalFromSoftmax for prior-corrected posterior at inference
- Ensure raw argmax scoring for recall/convergence remains unchanged; correction only affects live signal
2026-07-23 19:36:34 -04:00