Seeking help to identify Custom(FxSession) new day

 

Goal to get new specified Forex Session start-end times in CPRSession[] ... (Code in 'bold' letters)

ForexSession are calculated and populated in cFxSession[day][sessionID] and arrayprint used to display calculated values.

CPRSession[] is created to get particular sessionID start-end times (Broker Server) for given number of days. e.g. NYC start 15:00 and NYC stop next day 14:59 Hrs

All times printed in code are Broker's sever time

void CiCPR::OnTick(void) {

        string vMethod = "[" + mSymbol + " " + EnumToString(mSessionID) + " " + EnumToString(mPivotMethod) + "] " + (string)__FUNCTION__;

                cFxSession.OnTick();

        //--- STEP[A] Prepare CPRSession[] with Begin and End times for 'n' Days data

        if(!cIsNewBar.D01() && cIsNewBar.H01()) {                                                                                                               // 'XAUUSD' starts at 18:01 hrs !IsNewBar.H01

        	//--- Get data for all four forex sessions
                SFxSession      vFxSession[][4];                                                                                                                        // Must be 2d array of 'n Days' for '4 Sessions' each day
                cFxSession.getFxSession(vFxSession);
/*
                ArrayPrint(vFxSession);
at tSVR 01:01:20
2024.05.23 10:16:13.697 2024.05.01 01:01:20                     [Begin]               [End]
2024.05.23 10:16:13.697 2024.05.01 01:01:20   [0,0] 2024.05.01 01:00:00 2024.05.01 09:59:00	
2024.05.23 10:16:13.697 2024.05.01 01:01:20   [0,1] 1970.01.01 00:00:00 1970.01.01 00:00:00	... Current day TOK not yet started
2024.05.23 10:16:13.697 2024.05.01 01:01:20   [0,2] 1970.01.01 00:00:00 1970.01.01 00:00:00	... Current day LON not yet started
2024.05.23 10:16:13.697 2024.05.01 01:01:20   [0,3] 1970.01.01 00:00:00 1970.01.01 00:00:00	... Current day NYC not yet started
2024.05.23 10:16:13.697 2024.05.01 01:01:20   [1,0] 2024.04.30 01:00:00 2024.04.30 09:59:00
2024.05.23 10:16:13.697 2024.05.01 01:01:20   [1,1] 2024.04.30 02:00:00 2024.04.30 10:59:00
2024.05.23 10:16:13.697 2024.05.01 01:01:20   [1,2] 2024.04.30 10:00:00 2024.04.30 18:59:00
2024.05.23 10:16:13.697 2024.05.01 01:01:20   [1,3] 2024.04.30 15:00:00 2024.04.30 23:59:00
2024.05.23 10:16:13.697 2024.05.01 01:01:20   [2,0] 2024.04.29 01:00:00 2024.04.29 09:59:00
2024.05.23 10:16:13.697 2024.05.01 01:01:20   [2,1] 2024.04.29 02:00:00 2024.04.29 10:59:00
2024.05.23 10:16:13.697 2024.05.01 01:01:20   [2,2] 2024.04.29 10:00:00 2024.04.29 18:59:00
2024.05.23 10:16:13.697 2024.05.01 01:01:20   [2,3] 2024.04.29 15:00:00 2024.04.29 23:59:00
2024.05.23 10:16:13.697 2024.05.01 01:01:20   [3,0] 2024.04.26 01:00:00 2024.04.26 09:59:00
2024.05.23 10:16:13.697 2024.05.01 01:01:20   [3,1] 2024.04.26 02:00:00 2024.04.26 10:59:00
2024.05.23 10:16:13.697 2024.05.01 01:01:20   [3,2] 2024.04.26 10:00:00 2024.04.26 18:59:00
2024.05.23 10:16:13.697 2024.05.01 01:01:20   [3,3] 2024.04.26 15:00:00 2024.04.26 23:59:00
2024.05.23 10:16:13.697 2024.05.01 01:01:20   [4,0] 2024.04.25 01:00:00 2024.04.25 09:59:00
2024.05.23 10:16:13.697 2024.05.01 01:01:20   [4,1] 2024.04.25 02:00:00 2024.04.25 10:59:00
2024.05.23 10:16:13.697 2024.05.01 01:01:20   [4,2] 2024.04.25 10:00:00 2024.04.25 18:59:00
2024.05.23 10:16:13.697 2024.05.01 01:01:20   [4,3] 2024.04.25 15:00:00 2024.04.25 23:59:00
2024.05.23 10:16:13.697 2024.05.01 01:01:20   [5,0] 2024.04.24 01:00:00 2024.04.24 09:59:00
2024.05.23 10:16:13.697 2024.05.01 01:01:20   [5,1] 2024.04.24 02:00:00 2024.04.24 10:59:00
2024.05.23 10:16:13.697 2024.05.01 01:01:20   [5,2] 2024.04.24 10:00:00 2024.04.24 18:59:00
2024.05.23 10:16:13.697 2024.05.01 01:01:20   [5,3] 2024.04.24 15:00:00 2024.04.24 23:59:00

at tSVR 15:00:00
2024.05.23 10:17:12.524 2024.05.01 15:00:00                     [Begin]               [End]
2024.05.23 10:17:12.524 2024.05.01 15:00:00   [0,0] 2024.05.01 01:00:00 2024.05.01 09:59:00
2024.05.23 10:17:12.524 2024.05.01 15:00:00   [0,1] 2024.05.01 02:00:00 2024.05.01 10:59:00
2024.05.23 10:17:12.524 2024.05.01 15:00:00   [0,2] 2024.05.01 10:00:00 2024.05.01 18:59:00
2024.05.23 10:17:12.524 2024.05.01 15:00:00   [0,3] 2024.05.01 15:00:00 2024.05.01 23:59:00
2024.05.23 10:17:12.524 2024.05.01 15:00:00   [1,0] 2024.04.30 01:00:00 2024.04.30 09:59:00
2024.05.23 10:17:12.524 2024.05.01 15:00:00   [1,1] 2024.04.30 02:00:00 2024.04.30 10:59:00
2024.05.23 10:17:12.524 2024.05.01 15:00:00   [1,2] 2024.04.30 10:00:00 2024.04.30 18:59:00
2024.05.23 10:17:12.524 2024.05.01 15:00:00   [1,3] 2024.04.30 15:00:00 2024.04.30 23:59:00
2024.05.23 10:17:12.524 2024.05.01 15:00:00   [2,0] 2024.04.29 01:00:00 2024.04.29 09:59:00
2024.05.23 10:17:12.524 2024.05.01 15:00:00   [2,1] 2024.04.29 02:00:00 2024.04.29 10:59:00
2024.05.23 10:17:12.524 2024.05.01 15:00:00   [2,2] 2024.04.29 10:00:00 2024.04.29 18:59:00
2024.05.23 10:17:12.524 2024.05.01 15:00:00   [2,3] 2024.04.29 15:00:00 2024.04.29 23:59:00
2024.05.23 10:17:12.524 2024.05.01 15:00:00   [3,0] 2024.04.26 01:00:00 2024.04.26 09:59:00
2024.05.23 10:17:12.524 2024.05.01 15:00:00   [3,1] 2024.04.26 02:00:00 2024.04.26 10:59:00
2024.05.23 10:17:12.524 2024.05.01 15:00:00   [3,2] 2024.04.26 10:00:00 2024.04.26 18:59:00
2024.05.23 10:17:12.524 2024.05.01 15:00:00   [3,3] 2024.04.26 15:00:00 2024.04.26 23:59:00
2024.05.23 10:17:12.524 2024.05.01 15:00:00   [4,0] 2024.04.25 01:00:00 2024.04.25 09:59:00
2024.05.23 10:17:12.524 2024.05.01 15:00:00   [4,1] 2024.04.25 02:00:00 2024.04.25 10:59:00
2024.05.23 10:17:12.524 2024.05.01 15:00:00   [4,2] 2024.04.25 10:00:00 2024.04.25 18:59:00
2024.05.23 10:17:12.524 2024.05.01 15:00:00   [4,3] 2024.04.25 15:00:00 2024.04.25 23:59:00
2024.05.23 10:17:12.524 2024.05.01 15:00:00   [5,0] 2024.04.24 01:00:00 2024.04.24 09:59:00
2024.05.23 10:17:12.524 2024.05.01 15:00:00   [5,1] 2024.04.24 02:00:00 2024.04.24 10:59:00
2024.05.23 10:17:12.524 2024.05.01 15:00:00   [5,2] 2024.04.24 10:00:00 2024.04.24 18:59:00
2024.05.23 10:17:12.524 2024.05.01 15:00:00   [5,3] 2024.04.24 15:00:00 2024.04.24 23:59:00
*/
                //--- FxSession  element[0] represent current Day's session times
                //--- CPRSession element[0] calculated for previous FxSession[1] | We shall retain data only for forex session with 'mSessionID'
                ArrayResize(CPRSession,ArrayRange(vFxSession,0)-1);
                for(int day = ArrayRange(vFxSession,0)-2; day >= 0; day--) {
                	if(mSessionID == NYC) {
                          if(day != 0) {
                            CPRSession[day].Begin = vFxSession[1+day][NYC].Begin;
                            CPRSession[day].End   = vFxSession[day][NYC].Begin - 60;
                          }
                          if(day == 0) {
                            CPRSession[day].Begin = vFxSession[day][NYC].Begin;
                            CPRSession[day].End   = vFxSession[day][NYC].Begin + PeriodSeconds(PERIOD_D1) - 60;
                          
                        
                }
                ArrayPrint(CPRSession);
/*
Current code calculates wrong session times at Beginning of Broker New Day
Pivot Sessions(s) to Draw CPR timeStart and timeStop
2024.05.23 11:23:48.920 2024.05.01 01:01:20                   [Begin]               [End]
2024.05.23 11:23:48.920 2024.05.01 01:01:20   [0] 1970.01.01 00:00:00 1970.01.01 23:59:00	
2024.05.23 11:23:48.920 2024.05.01 01:01:20   [1] 2024.04.29 15:00:00 2024.04.30 14:59:00
2024.05.23 11:23:48.920 2024.05.01 01:01:20   [2] 2024.04.26 15:00:00 2024.04.29 14:59:00
2024.05.23 11:23:48.920 2024.05.01 01:01:20   [3] 2024.04.25 15:00:00 2024.04.26 14:59:00
2024.05.23 11:23:48.920 2024.05.01 01:01:20   [4] 2024.04.24 15:00:00 2024.04.25 14:59:00

2024.05.23 11:25:25.858 2024.05.01 15:00:00                   [Begin]               [End]
2024.05.23 11:25:25.858 2024.05.01 15:00:00   [0] 2024.05.01 15:00:00 2024.05.02 14:59:00
2024.05.23 11:25:25.858 2024.05.01 15:00:00   [1] 2024.04.29 15:00:00 2024.04.30 14:59:00
2024.05.23 11:25:25.858 2024.05.01 15:00:00   [2] 2024.04.26 15:00:00 2024.04.29 14:59:00
2024.05.23 11:25:25.858 2024.05.01 15:00:00   [3] 2024.04.25 15:00:00 2024.04.26 14:59:00
2024.05.23 11:25:25.858 2024.05.01 15:00:00   [4] 2024.04.24 15:00:00 2024.04.25 14:59:00
*/
Seeking help to get following correct values
Pivot Sessions(s) to Draw CPR timeStart and timeStop
2024.05.23 11:23:48.920	2024.05.01 01:01:20                   [Begin]               [End]	at Beginning of Broker New Day
2024.05.23 11:23:48.920	2024.05.01 01:01:20   [0] 2024.04.30 15:00:00 2024.01.01 14:59:00	until NYC session starts for [day=0]
2024.05.23 11:23:48.920	2024.05.01 01:01:20   [1] 2024.04.29 15:00:00 2024.04.30 14:59:00
2024.05.23 11:23:48.920	2024.05.01 01:01:20   [2] 2024.04.26 15:00:00 2024.04.29 14:59:00
2024.05.23 11:23:48.920	2024.05.01 01:01:20   [3] 2024.04.25 15:00:00 2024.04.26 14:59:00
2024.05.23 11:23:48.920	2024.05.01 01:01:20   [4] 2024.04.24 15:00:00 2024.04.25 14:59:00

2024.05.23 11:25:25.858	2024.05.01 15:00:00                   [Begin]               [End]	at Beginning of New Session Day
2024.05.23 11:25:25.858	2024.05.01 15:00:00   [0] 2024.05.01 15:00:00 2024.05.02 14:59:00	NYC session started for [day=0]
2024.05.23 11:25:25.858	2024.05.01 15:00:00   [1] 2024.04.30 15:00:00 2024.05.01 14:59:00
2024.05.23 11:25:25.858	2024.05.01 15:00:00   [2] 2024.04.29 15:00:00 2024.04.30 14:59:00
2024.05.23 11:25:25.858	2024.05.01 15:00:00   [3] 2024.04.26 15:00:00 2024.04.29 14:59:00
2024.05.23 11:25:25.858	2024.05.01 15:00:00   [4] 2024.04.25 15:00:00 2024.04.26 14:59:00

} // END Of method OnTick()

Thanks in advance for all gurus here for their support and resolving the puzzle.

Regards.

 
Seems found partial solution
                //+-------------------------------------------------------------------------------------------------------------------------+
                //| FxSession  element[0] represent current Day's session times
                //| CPRSession element[0] calculated for previous FxSession[1] | We shall retain data only for forex session with 'mSessionID'
                //+-------------------------------------------------------------------------------------------------------------------------+
                        ArrayResize(CPRSession,ArrayRange(vFxSession,0)-1);
                        for(int day = ArrayRange(vFxSession,0)-2; day >= 0; day--) {
                                if(mSessionID == NYC) {
                                        if(day != 0) {
                                                CPRSession[day].Begin = vFxSession[1+day][NYC].Begin;
                                                CPRSession[day].End       = vFxSession[day][NYC].Begin - 60;
                                        }
                                        // Current day's NYC session not yet started (FxSession stores datetime value as '0' Zero = 1970.01.01 00:00:00)
                                        if(day == 0) {
                                                if(TimeCurrent() > vFxSession[1+day][NYC].Begin && vFxSession[day][NYC].Begin == StringToTime("1970.01.01 00:00:00")) {
                                                        CPRSession[day].Begin = vFxSession[1+day][NYC].Begin;
                                                        CPRSession[day].End       = vFxSession[1+day][NYC].Begin + PeriodSeconds(PERIOD_D1) - 60;
                                                }
                                                // Current day's NYC session just started on current bar
                                                if(TimeCurrent() == vFxSession[day][NYC].Begin) {
                                                        CPRSession[day].Begin = vFxSession[day][NYC].Begin;
                                                        CPRSession[day].End       = vFxSession[day][NYC].Begin + PeriodSeconds(PERIOD_D1) - 60;
                                                }
                                        }
                                }
                        }
                        ArrayPrint(CPRSession);
/*
2024.05.23 12:37:04.568 2024.05.01 01:01:20                   [Begin]               [End]
2024.05.23 12:37:04.568 2024.05.01 01:01:20   [0] 2024.04.30 15:00:00 2024.05.01 14:59:00	at Beginning of Broker's Day
2024.05.23 12:37:04.568 2024.05.01 01:01:20   [1] 2024.04.29 15:00:00 2024.04.30 14:59:00
2024.05.23 12:37:04.568 2024.05.01 01:01:20   [2] 2024.04.26 15:00:00 2024.04.29 14:59:00
2024.05.23 12:37:04.568 2024.05.01 01:01:20   [3] 2024.04.25 15:00:00 2024.04.26 14:59:00
2024.05.23 12:37:04.568 2024.05.01 01:01:20   [4] 2024.04.24 15:00:00 2024.04.25 14:59:00

2024.05.23 12:37:39.911 2024.05.01 14:00:00                   [Begin]               [End]
2024.05.23 12:37:39.911 2024.05.01 14:00:00   [0] 2024.04.30 15:00:00 2024.05.01 14:59:00	at PeriodH01 bar before NYC Session start
2024.05.23 12:37:39.911 2024.05.01 14:00:00   [1] 2024.04.29 15:00:00 2024.04.30 14:59:00
2024.05.23 12:37:39.911 2024.05.01 14:00:00   [2] 2024.04.26 15:00:00 2024.04.29 14:59:00
2024.05.23 12:37:39.911 2024.05.01 14:00:00   [3] 2024.04.25 15:00:00 2024.04.26 14:59:00
2024.05.23 12:37:39.911 2024.05.01 14:00:00   [4] 2024.04.24 15:00:00 2024.04.25 14:59:00

2024.05.23 12:37:40.804 2024.05.01 15:00:00                   [Begin]               [End]
2024.05.23 12:37:40.804 2024.05.01 15:00:00   [0] 2024.05.01 15:00:00 2024.05.02 14:59:00	at NYC Session start in Broker's Server time
2024.05.23 12:37:40.804 2024.05.01 15:00:00   [1] 2024.04.29 15:00:00 2024.04.30 14:59:00	should be 2024.04.30 to 2024.05.01
2024.05.23 12:37:40.804 2024.05.01 15:00:00   [2] 2024.04.26 15:00:00 2024.04.29 14:59:00	should be 2024.04.29 to 2024.04.30
2024.05.23 12:37:40.804 2024.05.01 15:00:00   [3] 2024.04.25 15:00:00 2024.04.26 14:59:00	should be 2024.04.26 to 2024.04.29 ... WeekEnd
2024.05.23 12:37:40.804 2024.05.01 15:00:00   [4] 2024.04.24 15:00:00 2024.04.25 14:59:00	should be 2024.04.25 to 2024.05.26
*/
Reason: