refactor(persistence): ModelPersistence is a real collaborator, not a raw-include partial (S3)
Expert/AIBase/Persistence.mqh (598 lines, 8 methods) -> Expert/Persistence/:
IPersistenceView.mqh (abstract, 68 read+write accessors) + AIBasePersistenceView.mqh/
AIBasePersistenceViewImpl.mqh (the adapter) + ModelPersistence.mqh (CModelPersistence,
the real collaborator - signal owns m_modelPersistence and binds it to m_persistenceView,
same shape as ChartUI's S2).
Grep-verified before starting: every field these 8 methods touch is ALSO touched
elsewhere in the class (Training/Lifecycle/OnlineLearning/Topology/FeatureScreen/
Labels.mqh) or already exposed via ChartView. Zero exclusive state, unlike ChartUI's
arrow-restore/rescan queues - CModelPersistence is stateless, holding only the
borrowed view pointer, operating entirely through 68 Persist*/PersistSet*() accessors
on the signal.
ValidateCpuInference's Net-pointer/throwaway-clone core is ONE consolidated view call
(PersistRunCpuInferenceSelfCheck) rather than field-by-field - irreducible pointer/
object work, not signal state, same doctrine as ChartScoreBarForRescan.
LoadNetWithRetry keeps its original CheckPointer(Net)-free Net.Load() call unchanged
(no guard added - would change failure behaviour on what must be a pure relocation).
This code writes the actual on-disk .cfg/.stats binary layouts every deployed model
depends on (explicit "DO NOT REORDER" comment in the original), so beyond compiling
clean (0 errors, 0 warnings) this was verified with a positional field-order diff:
every FileWrite*/FileRead* call's target field, extracted and normalized from both
the original and the new file, matches 1:1 in the same order (43/43 on the write
side covering SaveModelStats+SaveTopologyConfiguration, 17/17 on LoadModelStats'
read side; LoadAndCompareTopologyConfiguration's local-variable read block was
copied verbatim, untouched, so nothing to diff there). The magic-version
conditionals (WST2-6, haveDerivedStages/haveBarrierGeometry/etc.) moved unchanged.
All 8 methods keep their exact original signatures as one-line forwards - zero
external call sites changed.
2026-08-23 21:45:09 -04:00
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
//| Warrior_EA |
|
|
|
|
|
//| AnimateDread |
|
|
|
|
|
//| |
|
|
|
|
|
//| CAIBasePersistenceView bodies - needs the full signal |
|
|
|
|
|
//| declaration. Same doctrine as Chart\AIBaseChartViewImpl.mqh - |
|
|
|
|
|
//| every method is a forward, borrowed pointer checked on every |
|
|
|
|
|
//| call. |
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
#ifndef WARRIOR_PERSISTENCE_AIBASEPERSISTENCEVIEWIMPL_MQH
|
|
|
|
|
#define WARRIOR_PERSISTENCE_AIBASEPERSISTENCEVIEWIMPL_MQH
|
|
|
|
|
string CAIBasePersistenceView::Id(void)
|
|
|
|
|
{ return (CheckPointer(m_owner) != POINTER_INVALID) ? m_owner.DataId() : ""; }
|
|
|
|
|
string CAIBasePersistenceView::FileName(void)
|
|
|
|
|
{ return (CheckPointer(m_owner) != POINTER_INVALID) ? m_owner.ChartFileName() : ""; }
|
|
|
|
|
int CAIBasePersistenceView::NeuronsCount(void)
|
|
|
|
|
{ return (CheckPointer(m_owner) != POINTER_INVALID) ? m_owner.DataFeaturesPerBar() : 0; }
|
|
|
|
|
long CAIBasePersistenceView::CumIsCorrect(void)
|
|
|
|
|
{ return (CheckPointer(m_owner) != POINTER_INVALID) ? m_owner.ChartCumIsCorrect() : 0; }
|
|
|
|
|
long CAIBasePersistenceView::CumIsTotal(void)
|
|
|
|
|
{ return (CheckPointer(m_owner) != POINTER_INVALID) ? m_owner.ChartCumIsTotal() : 0; }
|
|
|
|
|
long CAIBasePersistenceView::CumOosCorrect(void)
|
|
|
|
|
{ return (CheckPointer(m_owner) != POINTER_INVALID) ? m_owner.ChartCumOosCorrect() : 0; }
|
|
|
|
|
long CAIBasePersistenceView::CumOosTotal(void)
|
|
|
|
|
{ return (CheckPointer(m_owner) != POINTER_INVALID) ? m_owner.ChartCumOosTotal() : 0; }
|
|
|
|
|
|
|
|
|
|
bool CAIBasePersistenceView::NetLoaded(void)
|
|
|
|
|
{ return (CheckPointer(m_owner) != POINTER_INVALID) ? m_owner.PersistNetLoaded() : false; }
|
|
|
|
|
bool CAIBasePersistenceView::UsesConvStage(void)
|
|
|
|
|
{ return (CheckPointer(m_owner) != POINTER_INVALID) ? m_owner.PersistUsesConvStage() : false; }
|
|
|
|
|
uint CAIBasePersistenceView::NetFirstConvWindow(void)
|
|
|
|
|
{ return (CheckPointer(m_owner) != POINTER_INVALID) ? m_owner.PersistNetFirstConvWindow() : 0; }
|
|
|
|
|
int CAIBasePersistenceView::ConvReceptiveFieldBars(void)
|
|
|
|
|
{ return (CheckPointer(m_owner) != POINTER_INVALID) ? m_owner.PersistConvReceptiveFieldBars() : 0; }
|
|
|
|
|
ENUM_ACTIVATION CAIBasePersistenceView::OutputLayerActivation(void)
|
|
|
|
|
{ return (CheckPointer(m_owner) != POINTER_INVALID) ? m_owner.PersistOutputLayerActivation() : TANH; }
|
|
|
|
|
bool CAIBasePersistenceView::NetEnforceOutputActivation(const ENUM_ACTIVATION intended, ENUM_ACTIVATION &stale)
|
|
|
|
|
{
|
|
|
|
|
stale = intended;
|
|
|
|
|
return (CheckPointer(m_owner) != POINTER_INVALID) ? m_owner.PersistNetEnforceOutputActivation(intended, stale) : false;
|
|
|
|
|
}
|
|
|
|
|
void CAIBasePersistenceView::SetTopologySuperseded(const bool v)
|
|
|
|
|
{ if(CheckPointer(m_owner) != POINTER_INVALID) m_owner.PersistSetTopologySuperseded(v); }
|
|
|
|
|
|
|
|
|
|
double CAIBasePersistenceView::PriorBuy(void)
|
|
|
|
|
{ return (CheckPointer(m_owner) != POINTER_INVALID) ? m_owner.PersistPriorBuy() : 0.0; }
|
|
|
|
|
void CAIBasePersistenceView::SetPriorBuy(const double v)
|
|
|
|
|
{ if(CheckPointer(m_owner) != POINTER_INVALID) m_owner.PersistSetPriorBuy(v); }
|
|
|
|
|
double CAIBasePersistenceView::PriorSell(void)
|
|
|
|
|
{ return (CheckPointer(m_owner) != POINTER_INVALID) ? m_owner.PersistPriorSell() : 0.0; }
|
|
|
|
|
void CAIBasePersistenceView::SetPriorSell(const double v)
|
|
|
|
|
{ if(CheckPointer(m_owner) != POINTER_INVALID) m_owner.PersistSetPriorSell(v); }
|
|
|
|
|
double CAIBasePersistenceView::PriorNeutral(void)
|
|
|
|
|
{ return (CheckPointer(m_owner) != POINTER_INVALID) ? m_owner.PersistPriorNeutral() : 0.0; }
|
|
|
|
|
void CAIBasePersistenceView::SetPriorNeutral(const double v)
|
|
|
|
|
{ if(CheckPointer(m_owner) != POINTER_INVALID) m_owner.PersistSetPriorNeutral(v); }
|
|
|
|
|
double CAIBasePersistenceView::ConfidenceCalScale(void)
|
|
|
|
|
{ return (CheckPointer(m_owner) != POINTER_INVALID) ? m_owner.PersistConfidenceCalScale() : 0.0; }
|
|
|
|
|
void CAIBasePersistenceView::SetConfidenceCalScale(const double v)
|
|
|
|
|
{ if(CheckPointer(m_owner) != POINTER_INVALID) m_owner.PersistSetConfidenceCalScale(v); }
|
|
|
|
|
bool CAIBasePersistenceView::MqlInferenceValidated(void)
|
|
|
|
|
{ return (CheckPointer(m_owner) != POINTER_INVALID) ? m_owner.PersistMqlInferenceValidated() : false; }
|
|
|
|
|
void CAIBasePersistenceView::SetMqlInferenceValidated(const bool v)
|
|
|
|
|
{ if(CheckPointer(m_owner) != POINTER_INVALID) m_owner.PersistSetMqlInferenceValidated(v); }
|
|
|
|
|
datetime CAIBasePersistenceView::OnlineLearnedUpToTime(void)
|
|
|
|
|
{ return (CheckPointer(m_owner) != POINTER_INVALID) ? m_owner.PersistOnlineLearnedUpToTime() : 0; }
|
|
|
|
|
void CAIBasePersistenceView::SetOnlineLearnedUpToTime(const datetime v)
|
|
|
|
|
{ if(CheckPointer(m_owner) != POINTER_INVALID) m_owner.PersistSetOnlineLearnedUpToTime(v); }
|
|
|
|
|
double CAIBasePersistenceView::OnlineRollingAcc(void)
|
|
|
|
|
{ return (CheckPointer(m_owner) != POINTER_INVALID) ? m_owner.PersistOnlineRollingAcc() : 0.0; }
|
|
|
|
|
void CAIBasePersistenceView::SetOnlineRollingAcc(const double v)
|
|
|
|
|
{ if(CheckPointer(m_owner) != POINTER_INVALID) m_owner.PersistSetOnlineRollingAcc(v); }
|
|
|
|
|
long CAIBasePersistenceView::OnlineSamples(void)
|
|
|
|
|
{ return (CheckPointer(m_owner) != POINTER_INVALID) ? m_owner.PersistOnlineSamples() : 0; }
|
|
|
|
|
void CAIBasePersistenceView::SetOnlineSamples(const long v)
|
|
|
|
|
{ if(CheckPointer(m_owner) != POINTER_INVALID) m_owner.PersistSetOnlineSamples(v); }
|
|
|
|
|
int CAIBasePersistenceView::LastBuyFiredPrecPct(void)
|
|
|
|
|
{ return (CheckPointer(m_owner) != POINTER_INVALID) ? m_owner.PersistLastBuyFiredPrecPct() : -1; }
|
|
|
|
|
void CAIBasePersistenceView::SetLastBuyFiredPrecPct(const int v)
|
|
|
|
|
{ if(CheckPointer(m_owner) != POINTER_INVALID) m_owner.PersistSetLastBuyFiredPrecPct(v); }
|
|
|
|
|
int CAIBasePersistenceView::LastSellFiredPrecPct(void)
|
|
|
|
|
{ return (CheckPointer(m_owner) != POINTER_INVALID) ? m_owner.PersistLastSellFiredPrecPct() : -1; }
|
|
|
|
|
void CAIBasePersistenceView::SetLastSellFiredPrecPct(const int v)
|
|
|
|
|
{ if(CheckPointer(m_owner) != POINTER_INVALID) m_owner.PersistSetLastSellFiredPrecPct(v); }
|
|
|
|
|
int CAIBasePersistenceView::LastBuyRecallPct(void)
|
|
|
|
|
{ return (CheckPointer(m_owner) != POINTER_INVALID) ? m_owner.PersistLastBuyRecallPct() : -1; }
|
|
|
|
|
void CAIBasePersistenceView::SetLastBuyRecallPct(const int v)
|
|
|
|
|
{ if(CheckPointer(m_owner) != POINTER_INVALID) m_owner.PersistSetLastBuyRecallPct(v); }
|
|
|
|
|
int CAIBasePersistenceView::LastSellRecallPct(void)
|
|
|
|
|
{ return (CheckPointer(m_owner) != POINTER_INVALID) ? m_owner.PersistLastSellRecallPct() : -1; }
|
|
|
|
|
void CAIBasePersistenceView::SetLastSellRecallPct(const int v)
|
|
|
|
|
{ if(CheckPointer(m_owner) != POINTER_INVALID) m_owner.PersistSetLastSellRecallPct(v); }
|
|
|
|
|
int CAIBasePersistenceView::LastBuyFired(void)
|
|
|
|
|
{ return (CheckPointer(m_owner) != POINTER_INVALID) ? m_owner.PersistLastBuyFired() : 0; }
|
|
|
|
|
void CAIBasePersistenceView::SetLastBuyFired(const int v)
|
|
|
|
|
{ if(CheckPointer(m_owner) != POINTER_INVALID) m_owner.PersistSetLastBuyFired(v); }
|
|
|
|
|
int CAIBasePersistenceView::LastSellFired(void)
|
|
|
|
|
{ return (CheckPointer(m_owner) != POINTER_INVALID) ? m_owner.PersistLastSellFired() : 0; }
|
|
|
|
|
void CAIBasePersistenceView::SetLastSellFired(const int v)
|
|
|
|
|
{ if(CheckPointer(m_owner) != POINTER_INVALID) m_owner.PersistSetLastSellFired(v); }
|
|
|
|
|
void CAIBasePersistenceView::SetCumIsCorrect(const long v)
|
|
|
|
|
{ if(CheckPointer(m_owner) != POINTER_INVALID) m_owner.PersistSetCumIsCorrect(v); }
|
|
|
|
|
void CAIBasePersistenceView::SetCumIsTotal(const long v)
|
|
|
|
|
{ if(CheckPointer(m_owner) != POINTER_INVALID) m_owner.PersistSetCumIsTotal(v); }
|
|
|
|
|
void CAIBasePersistenceView::SetCumOosCorrect(const long v)
|
|
|
|
|
{ if(CheckPointer(m_owner) != POINTER_INVALID) m_owner.PersistSetCumOosCorrect(v); }
|
|
|
|
|
void CAIBasePersistenceView::SetCumOosTotal(const long v)
|
|
|
|
|
{ if(CheckPointer(m_owner) != POINTER_INVALID) m_owner.PersistSetCumOosTotal(v); }
|
fix(vote): persist the tier ladder - a converged model was mute after every restart
THIS IS NOT A DISPLAY BUG. A deployed model could not vote, or trade, at
any point after a terminal restart, and never would have.
LiveVoteContribution() returns 0 for every call until m_tiersSelfRanked
is set - deliberately, and correctly: before RankTiersFromOos() runs,
m_pattern_0..3 hold the constructor's stock 25/50/75/100, which since the
2026-08-18 currency change is the WRONG UNIT rather than a weak opinion,
and one unranked member would drag the whole ensemble over any threshold.
But that ladder is produced ONLY by a completed pass 3, and it was never
persisted - the code comment at LiveVoteContribution says so outright.
A converged model runs no further passes. So on every restart it lost its
entire vote permanently:
LiveVoteContribution -> 0 => no live vote ("0 vote/4 flat")
ReconstructionWeight -> 0 => overlay divisor 0 ("0 had a snapshot")
=> no arrows
=> no fired bars, so g_ensCumOosTotal stays 0
=> "measuring..." forever
Every symptom reported over the last three exchanges is that one cause.
The log is unambiguous: six H4 charts resumed at era 70/71, all 24
rescans completed with ~2700 Buy / ~2200 Sell per model, and the overlay
then swept 4999 bars finding "0 had a snapshot". The calls were there;
nothing was permitted to count them.
WST7 now stores the four tier weights, the module trust weight and the
self-ranked flag beside the model. Restored only when the stored flag
says the ladder was MEASURED - a .stats written before a model's first
pass 3 holds the stock ladder, and adopting that as if measured is the
exact error the flag exists to prevent.
A .stats predating WST7 has no ladder, so existing converged models stay
silent until their next scoring pass mints one. That case now prints a
warning naming all three of its symptoms, because each one independently
looks like a different bug.
Compile-verified in _claude_stage: 0 errors, 0 warnings.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-25 14:26:33 -04:00
|
|
|
int CAIBasePersistenceView::TierWeight(const int tier)
|
|
|
|
|
{ return (CheckPointer(m_owner) != POINTER_INVALID) ? m_owner.PersistTierWeight(tier) : 0; }
|
|
|
|
|
void CAIBasePersistenceView::SetTierWeight(const int tier, const int v)
|
|
|
|
|
{ if(CheckPointer(m_owner) != POINTER_INVALID) m_owner.PersistSetTierWeight(tier, v); }
|
|
|
|
|
double CAIBasePersistenceView::ModuleTrustWeight(void)
|
|
|
|
|
{ return (CheckPointer(m_owner) != POINTER_INVALID) ? m_owner.ModuleWeight() : 0.0; }
|
|
|
|
|
void CAIBasePersistenceView::SetModuleTrustWeight(const double v)
|
|
|
|
|
{ if(CheckPointer(m_owner) != POINTER_INVALID) m_owner.PersistSetModuleTrustWeight(v); }
|
|
|
|
|
bool CAIBasePersistenceView::TiersSelfRanked(void)
|
|
|
|
|
{ return (CheckPointer(m_owner) != POINTER_INVALID) ? m_owner.SelfRanked() : false; }
|
|
|
|
|
void CAIBasePersistenceView::SetTiersSelfRanked(const bool v)
|
|
|
|
|
{ if(CheckPointer(m_owner) != POINTER_INVALID) m_owner.PersistSetTiersSelfRanked(v); }
|
2026-08-26 16:53:16 -04:00
|
|
|
double CAIBasePersistenceView::CertifiedPrecPct(void)
|
|
|
|
|
{ return (CheckPointer(m_owner) != POINTER_INVALID) ? m_owner.PersistCertifiedPrecPct() : -1.0; }
|
|
|
|
|
double CAIBasePersistenceView::CertifiedChancePct(void)
|
|
|
|
|
{ return (CheckPointer(m_owner) != POINTER_INVALID) ? m_owner.PersistCertifiedChancePct() : -1.0; }
|
|
|
|
|
void CAIBasePersistenceView::SetCertifiedEdge(const double precPct, const double chancePct)
|
|
|
|
|
{ if(CheckPointer(m_owner) != POINTER_INVALID) m_owner.PersistSetCertifiedEdge(precPct, chancePct); }
|
refactor(persistence): ModelPersistence is a real collaborator, not a raw-include partial (S3)
Expert/AIBase/Persistence.mqh (598 lines, 8 methods) -> Expert/Persistence/:
IPersistenceView.mqh (abstract, 68 read+write accessors) + AIBasePersistenceView.mqh/
AIBasePersistenceViewImpl.mqh (the adapter) + ModelPersistence.mqh (CModelPersistence,
the real collaborator - signal owns m_modelPersistence and binds it to m_persistenceView,
same shape as ChartUI's S2).
Grep-verified before starting: every field these 8 methods touch is ALSO touched
elsewhere in the class (Training/Lifecycle/OnlineLearning/Topology/FeatureScreen/
Labels.mqh) or already exposed via ChartView. Zero exclusive state, unlike ChartUI's
arrow-restore/rescan queues - CModelPersistence is stateless, holding only the
borrowed view pointer, operating entirely through 68 Persist*/PersistSet*() accessors
on the signal.
ValidateCpuInference's Net-pointer/throwaway-clone core is ONE consolidated view call
(PersistRunCpuInferenceSelfCheck) rather than field-by-field - irreducible pointer/
object work, not signal state, same doctrine as ChartScoreBarForRescan.
LoadNetWithRetry keeps its original CheckPointer(Net)-free Net.Load() call unchanged
(no guard added - would change failure behaviour on what must be a pure relocation).
This code writes the actual on-disk .cfg/.stats binary layouts every deployed model
depends on (explicit "DO NOT REORDER" comment in the original), so beyond compiling
clean (0 errors, 0 warnings) this was verified with a positional field-order diff:
every FileWrite*/FileRead* call's target field, extracted and normalized from both
the original and the new file, matches 1:1 in the same order (43/43 on the write
side covering SaveModelStats+SaveTopologyConfiguration, 17/17 on LoadModelStats'
read side; LoadAndCompareTopologyConfiguration's local-variable read block was
copied verbatim, untouched, so nothing to diff there). The magic-version
conditionals (WST2-6, haveDerivedStages/haveBarrierGeometry/etc.) moved unchanged.
All 8 methods keep their exact original signatures as one-line forwards - zero
external call sites changed.
2026-08-23 21:45:09 -04:00
|
|
|
|
|
|
|
|
bool CAIBasePersistenceView::RunCpuInferenceSelfCheck(double &maxDiff)
|
|
|
|
|
{
|
|
|
|
|
maxDiff = DBL_MAX;
|
|
|
|
|
return (CheckPointer(m_owner) != POINTER_INVALID) ? m_owner.PersistRunCpuInferenceSelfCheck(maxDiff) : false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CAIBasePersistenceView::SetDirConfThreshold(const double v)
|
|
|
|
|
{ if(CheckPointer(m_owner) != POINTER_INVALID) m_owner.PersistSetDirConfThreshold(v); }
|
|
|
|
|
double CAIBasePersistenceView::BestDirConfThreshold(void)
|
|
|
|
|
{ return (CheckPointer(m_owner) != POINTER_INVALID) ? m_owner.PersistBestDirConfThreshold() : 0.0; }
|
|
|
|
|
void CAIBasePersistenceView::SetBestDirConfThreshold(const double v)
|
|
|
|
|
{ if(CheckPointer(m_owner) != POINTER_INVALID) m_owner.PersistSetBestDirConfThreshold(v); }
|
|
|
|
|
string CAIBasePersistenceView::CrossAssetPairsPinned(void)
|
|
|
|
|
{ return (CheckPointer(m_owner) != POINTER_INVALID) ? m_owner.PersistCrossAssetPairsPinned() : ""; }
|
|
|
|
|
void CAIBasePersistenceView::SetCrossAssetPairsPinned(const string v)
|
|
|
|
|
{ if(CheckPointer(m_owner) != POINTER_INVALID) m_owner.PersistSetCrossAssetPairsPinned(v); }
|
|
|
|
|
void CAIBasePersistenceView::SetCrossAssetCfgSaved(const bool v)
|
|
|
|
|
{ if(CheckPointer(m_owner) != POINTER_INVALID) m_owner.PersistSetCrossAssetCfgSaved(v); }
|
|
|
|
|
string CAIBasePersistenceView::AltDataNamesPinned(void)
|
|
|
|
|
{ return (CheckPointer(m_owner) != POINTER_INVALID) ? m_owner.PersistAltDataNamesPinned() : ""; }
|
|
|
|
|
void CAIBasePersistenceView::SetAltDataNamesPinned(const string v)
|
|
|
|
|
{ if(CheckPointer(m_owner) != POINTER_INVALID) m_owner.PersistSetAltDataNamesPinned(v); }
|
|
|
|
|
void CAIBasePersistenceView::ApplyAltDataPinnedNames(const string v)
|
|
|
|
|
{ if(CheckPointer(m_owner) != POINTER_INVALID) m_owner.PersistApplyAltDataPinnedNames(v); }
|
|
|
|
|
|
|
|
|
|
bool CAIBasePersistenceView::LoadNetOnce(double &indicatorParams[])
|
|
|
|
|
{ return (CheckPointer(m_owner) != POINTER_INVALID) ? m_owner.PersistLoadNetOnce(indicatorParams) : false; }
|
|
|
|
|
#endif // WARRIOR_PERSISTENCE_AIBASEPERSISTENCEVIEWIMPL_MQH
|
|
|
|
|
//+------------------------------------------------------------------+
|