fix: Reconstruction UTC offset, Daily-reset timing, Dead code removed.
This commit is contained in:
+14
-51
@@ -5,7 +5,7 @@
|
|||||||
//| Based on: ORB-All-Sessions.pine + LuxAlgo Order Block Detector |
|
//| Based on: ORB-All-Sessions.pine + LuxAlgo Order Block Detector |
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
#property copyright "NANDR"
|
#property copyright "NANDR"
|
||||||
#property version "1.394"
|
#property version "1.395"
|
||||||
#property strict
|
#property strict
|
||||||
|
|
||||||
#include <Trade\Trade.mqh>
|
#include <Trade\Trade.mqh>
|
||||||
@@ -179,7 +179,6 @@ struct SSession
|
|||||||
|
|
||||||
int breakoutDir; // 0=none, 1=bull, -1=bear
|
int breakoutDir; // 0=none, 1=bull, -1=bear
|
||||||
bool inBreakout;
|
bool inBreakout;
|
||||||
bool inRetest;
|
|
||||||
int breakoutBarsAgo;
|
int breakoutBarsAgo;
|
||||||
bool breakoutEntryTaken; // one entry max per breakout confirmation leg
|
bool breakoutEntryTaken; // one entry max per breakout confirmation leg
|
||||||
|
|
||||||
@@ -202,7 +201,6 @@ struct SSession
|
|||||||
orbStartTime = 0;
|
orbStartTime = 0;
|
||||||
breakoutDir = 0;
|
breakoutDir = 0;
|
||||||
inBreakout = false;
|
inBreakout = false;
|
||||||
inRetest = false;
|
|
||||||
breakoutBarsAgo = 0;
|
breakoutBarsAgo = 0;
|
||||||
breakoutEntryTaken = false;
|
breakoutEntryTaken = false;
|
||||||
|
|
||||||
@@ -299,13 +297,6 @@ int g_ServerUtcOffsetSec = 0;
|
|||||||
// ATR handle
|
// ATR handle
|
||||||
int g_ATRHandle = INVALID_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 |
|
//| Utility: resolve actual symbol |
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
@@ -559,7 +550,6 @@ void UpdateORBSessions()
|
|||||||
g_Sessions[s].orbComplete = (g_OrbBarsNeeded == 1);
|
g_Sessions[s].orbComplete = (g_OrbBarsNeeded == 1);
|
||||||
g_Sessions[s].breakoutDir = 0;
|
g_Sessions[s].breakoutDir = 0;
|
||||||
g_Sessions[s].inBreakout = false;
|
g_Sessions[s].inBreakout = false;
|
||||||
g_Sessions[s].inRetest = false;
|
|
||||||
g_Sessions[s].breakoutBarsAgo = 0;
|
g_Sessions[s].breakoutBarsAgo = 0;
|
||||||
g_Sessions[s].tradesThisSession= 0;
|
g_Sessions[s].tradesThisSession= 0;
|
||||||
ResetLadderProgress(s);
|
ResetLadderProgress(s);
|
||||||
@@ -659,7 +649,7 @@ void DetectBreakouts()
|
|||||||
{
|
{
|
||||||
if(!g_Sessions[s].enabled || !g_Sessions[s].orbComplete) continue;
|
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].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
|
double c0 = iClose(g_Symbol, PERIOD_CURRENT, 1); // just-closed bar
|
||||||
bool outsideBull = (c0 > g_Sessions[s].orbHigh);
|
bool outsideBull = (c0 > g_Sessions[s].orbHigh);
|
||||||
@@ -978,44 +968,9 @@ bool IsOBNearLevel(double price, int dir, double &obTop, double &obBottom)
|
|||||||
return false;
|
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 |
|
//| Session-scoped active exposure |
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
bool HasActiveExposure()
|
|
||||||
{
|
|
||||||
return (CountOpenPositions() + CountPendingOrders()) > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CommentHasSessionTag(const string comment, const string sessionName)
|
bool CommentHasSessionTag(const string comment, const string sessionName)
|
||||||
{
|
{
|
||||||
if(comment == "" || sessionName == "")
|
if(comment == "" || sessionName == "")
|
||||||
@@ -1617,7 +1572,6 @@ void CheckEntrySignals()
|
|||||||
g_Sessions[s].name, g_Sessions[s].breakoutBarsAgo);
|
g_Sessions[s].name, g_Sessions[s].breakoutBarsAgo);
|
||||||
g_Sessions[s].inBreakout = false;
|
g_Sessions[s].inBreakout = false;
|
||||||
g_Sessions[s].breakoutDir = 0;
|
g_Sessions[s].breakoutDir = 0;
|
||||||
g_Sessions[s].inRetest = false;
|
|
||||||
g_Sessions[s].breakoutEntryTaken = false;
|
g_Sessions[s].breakoutEntryTaken = false;
|
||||||
ResetLadderProgress(s);
|
ResetLadderProgress(s);
|
||||||
continue;
|
continue;
|
||||||
@@ -1768,9 +1722,16 @@ void ManageOpenTrades()
|
|||||||
void CheckDailyReset()
|
void CheckDailyReset()
|
||||||
{
|
{
|
||||||
datetime now = TimeCurrent();
|
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;
|
MqlDateTime dt, dtLast;
|
||||||
TimeToStruct(now, dt);
|
TimeToStruct(tradingNow, dt);
|
||||||
TimeToStruct(g_LastDayReset, dtLast);
|
TimeToStruct(tradingLast, dtLast);
|
||||||
|
|
||||||
if(dt.day != dtLast.day || dt.mon != dtLast.mon || dt.year != dtLast.year)
|
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;
|
if(!g_Sessions[s].enabled || g_Sessions[s].orbComplete) continue;
|
||||||
|
|
||||||
// Build this session's open datetime for today
|
// 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;
|
MqlDateTime dtSess = dtNow;
|
||||||
dtSess.hour = g_Sessions[s].startHour;
|
dtSess.hour = g_Sessions[s].startHour;
|
||||||
dtSess.min = g_Sessions[s].startMin;
|
dtSess.min = g_Sessions[s].startMin;
|
||||||
dtSess.sec = 0;
|
dtSess.sec = 0;
|
||||||
datetime sessOpenTime = StructToTime(dtSess);
|
datetime sessOpenTime = StructToTime(dtSess) + g_ServerUtcOffsetSec;
|
||||||
|
|
||||||
// Only reconstruct if the opening bar has fully closed
|
// Only reconstruct if the opening bar has fully closed
|
||||||
long barSecs = (long)g_OrbBarsNeeded * (int)InpOrbTimeframe * 60;
|
long barSecs = (long)g_OrbBarsNeeded * (int)InpOrbTimeframe * 60;
|
||||||
|
|||||||
Reference in New Issue
Block a user