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())