diff --git a/NANDR_ORB_OB_EA.mq5 b/NANDR_ORB_OB_EA.mq5 index 0fc134e..cca48ff 100644 --- a/NANDR_ORB_OB_EA.mq5 +++ b/NANDR_ORB_OB_EA.mq5 @@ -5,7 +5,7 @@ //| Based on: ORB-All-Sessions.pine + LuxAlgo Order Block Detector | //+------------------------------------------------------------------+ #property copyright "NANDR" -#property version "1.394" +#property version "1.395" #property strict #include @@ -179,7 +179,6 @@ struct SSession int breakoutDir; // 0=none, 1=bull, -1=bear bool inBreakout; - bool inRetest; int breakoutBarsAgo; bool breakoutEntryTaken; // one entry max per breakout confirmation leg @@ -202,7 +201,6 @@ struct SSession orbStartTime = 0; breakoutDir = 0; inBreakout = false; - inRetest = false; breakoutBarsAgo = 0; breakoutEntryTaken = false; @@ -299,13 +297,6 @@ int g_ServerUtcOffsetSec = 0; // ATR handle int g_ATRHandle = INVALID_HANDLE; -// History tracking for price buffer (need N bars lookback) -#define MAX_BARS_LOOKBACK 20 -double g_HighBuf[]; -double g_LowBuf[]; -double g_CloseBuf[]; -double g_VolBuf[]; - //+------------------------------------------------------------------+ //| Utility: resolve actual symbol | //+------------------------------------------------------------------+ @@ -559,7 +550,6 @@ void UpdateORBSessions() g_Sessions[s].orbComplete = (g_OrbBarsNeeded == 1); g_Sessions[s].breakoutDir = 0; g_Sessions[s].inBreakout = false; - g_Sessions[s].inRetest = false; g_Sessions[s].breakoutBarsAgo = 0; g_Sessions[s].tradesThisSession= 0; ResetLadderProgress(s); @@ -659,7 +649,7 @@ void DetectBreakouts() { if(!g_Sessions[s].enabled || !g_Sessions[s].orbComplete) continue; if(g_Sessions[s].orbHigh <= 0 || g_Sessions[s].orbLow >= DBL_MAX) continue; - if(g_Sessions[s].inBreakout || g_Sessions[s].inRetest) continue; + if(g_Sessions[s].inBreakout) continue; double c0 = iClose(g_Symbol, PERIOD_CURRENT, 1); // just-closed bar bool outsideBull = (c0 > g_Sessions[s].orbHigh); @@ -978,44 +968,9 @@ bool IsOBNearLevel(double price, int dir, double &obTop, double &obBottom) return false; } -//+------------------------------------------------------------------+ -//| Count open positions by magic | -//+------------------------------------------------------------------+ -int CountOpenPositions() -{ - int count = 0; - for(int i = PositionsTotal() - 1; i >= 0; i--) - { - if(g_Position.SelectByIndex(i)) - if(g_Position.Magic() == InpMagicNumber && g_Position.Symbol() == g_Symbol) - count++; - } - return count; -} - -//+------------------------------------------------------------------+ -//| Count pending orders by magic | -//+------------------------------------------------------------------+ -int CountPendingOrders() -{ - int count = 0; - for(int i = OrdersTotal() - 1; i >= 0; i--) - { - if(g_Order.SelectByIndex(i)) - if(g_Order.Magic() == InpMagicNumber && g_Order.Symbol() == g_Symbol) - count++; - } - return count; -} - //+------------------------------------------------------------------+ //| Session-scoped active exposure | //+------------------------------------------------------------------+ -bool HasActiveExposure() -{ - return (CountOpenPositions() + CountPendingOrders()) > 0; -} - bool CommentHasSessionTag(const string comment, const string sessionName) { if(comment == "" || sessionName == "") @@ -1617,7 +1572,6 @@ void CheckEntrySignals() g_Sessions[s].name, g_Sessions[s].breakoutBarsAgo); g_Sessions[s].inBreakout = false; g_Sessions[s].breakoutDir = 0; - g_Sessions[s].inRetest = false; g_Sessions[s].breakoutEntryTaken = false; ResetLadderProgress(s); continue; @@ -1768,9 +1722,16 @@ void ManageOpenTrades() void CheckDailyReset() { datetime now = TimeCurrent(); + // The trading day is anchored to the 22:00 UTC Daily Open session. Shifting + // UTC time forward by 2h moves that anchor onto a UTC-midnight boundary, so + // comparing calendar days resets exactly at 22:00 UTC regardless of the + // broker server timezone. This prevents a server-midnight reset from + // truncating the Daily Open session only a couple of hours after it starts. + datetime tradingNow = (now - g_ServerUtcOffsetSec) + 2 * 3600; + datetime tradingLast = (g_LastDayReset - g_ServerUtcOffsetSec) + 2 * 3600; MqlDateTime dt, dtLast; - TimeToStruct(now, dt); - TimeToStruct(g_LastDayReset, dtLast); + TimeToStruct(tradingNow, dt); + TimeToStruct(tradingLast, dtLast); if(dt.day != dtLast.day || dt.mon != dtLast.mon || dt.year != dtLast.year) { @@ -2118,11 +2079,13 @@ void ReconstructORBFromHistory() if(!g_Sessions[s].enabled || g_Sessions[s].orbComplete) continue; // Build this session's open datetime for today + // Session start hours are UTC; convert to server time so iBarShift/iTime + // (which operate in server time) locate the correct opening bar. MqlDateTime dtSess = dtNow; dtSess.hour = g_Sessions[s].startHour; dtSess.min = g_Sessions[s].startMin; dtSess.sec = 0; - datetime sessOpenTime = StructToTime(dtSess); + datetime sessOpenTime = StructToTime(dtSess) + g_ServerUtcOffsetSec; // Only reconstruct if the opening bar has fully closed long barSecs = (long)g_OrbBarsNeeded * (int)InpOrbTimeframe * 60;