From 2bde52e43b25f109b55aaed165d74f06c068febc Mon Sep 17 00:00:00 2001 From: Garfield Date: Fri, 24 Jul 2026 08:45:58 -0400 Subject: [PATCH] v5.7: self-heal GridHigh/GridLow if left at 0 by a restart-timing race GridHigh/GridLow are never persisted (only lastPivotCalcDate is), so if two restarts land close together near a server-day boundary, a fresh process can find lastPivotCalcDate already matching 'today' and skip CalculatePivotPoints() entirely -- leaving the band at its uninitialized 0/0 and every IsRangingMarket() check failing 'Invalid grid bounds' until the next real day rollover. Cost XAUUSD/XAGUSD ~17h of dead trading on 2026-07-23 after the drift-enable and sizing deploys landed back-to-back. Fix: both the OnInit guard and the OnTick day-rollover guard now also recalc when GridHigh<=0 || GridLow<=0, regardless of date match. The OnTick path recalcs only (no cancel/reset side effects) when it's the same-day self-heal case, since that's not a real day transition. Co-Authored-By: Claude Fable 5 --- OrdersEA_Smart_Grid_BO.mq5 | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/OrdersEA_Smart_Grid_BO.mq5 b/OrdersEA_Smart_Grid_BO.mq5 index 30ed502..fc75b88 100755 --- a/OrdersEA_Smart_Grid_BO.mq5 +++ b/OrdersEA_Smart_Grid_BO.mq5 @@ -5,12 +5,12 @@ //+------------------------------------------------------------------+ #property copyright "Copyright 2024, Garfield Heron" #property link "https://fetcherpay.com" -#property version "5.6" +#property version "5.7" #include #include -#define VERSION "Version 5.6 Smart Grid Breakout BO MT5" +#define VERSION "Version 5.7 Smart Grid Breakout BO MT5" #define MAX_TRADES 600 #define MAX_LOG_TRADES 1200 @@ -1351,7 +1351,13 @@ int OnInit() LoadGridState(); - if(lastPivotCalcDate != TodayStartBroker()) + // GridHigh/GridLow are NOT persisted (only lastPivotCalcDate is) — if a + // prior process already recalculated today before this restart, the + // date-match guard alone would skip CalculatePivotPoints() and leave the + // band at its uninitialized 0/0, causing "Invalid grid bounds" until the + // next real day rollover (5.7 fix — cost XAUUSD/XAGUSD ~17h on 2026-07-23 + // after two restarts landed close together near a day boundary). + if(lastPivotCalcDate != TodayStartBroker() || GridHigh <= 0 || GridLow <= 0) CalculatePivotPoints(); bGetOutOK = (GetOut=="L"||GetOut=="l"||GetOut=="A"||GetOut=="a"|| @@ -1471,6 +1477,14 @@ void OnTick() cycleProfitStop = false; CalculatePivotPoints(); // also updates lastPivotCalcDate & saves } + else if(GridHigh <= 0 || GridLow <= 0) + { + // Self-heal (5.7): same-day, but the band was never actually computed + // this process (see OnInit comment above). Recalc only — no + // cancel/reset, since this isn't a real day transition. + PrintS("Grid bounds invalid on same-day check — self-healing recalc"); + CalculatePivotPoints(); + } // --- Profit target check runs every tick (cheap) --- if(CheckProfitTarget())