Help requested on a for..loop to get IsNewSession() value
Dear Fellows
Please help me to rectify the below code to get correct IsNewSession value when a new session has started.
I failed to resolve it.
Thanks in advance and happy weekend.
Hi Dominik
I personally felt that, there was requirement of another for..loop inside the main loop to check TimeCross at [ith] index of main loop in say 120 counts, and return true if found AND continue to look for i-1th index in main loop.
I tried this, and current problem is RESOLVED. The revised code is as below, may be someone finds it useful.
bool CiVPBase::IsNewSession() { #define _HoD(t) ((int)(((t)%86400)/3600)) // Hour of Day 2018.02.03 17:55:56 => (int) 17 #define _MoH(t) (int(((t)%3600)/60)) // Minute of Current Hour string vMethod = "[" + mSymbol + "," + TimeToString(TimeCurrent()) + "] " + __FUNCTION__; datetime vCurrCross = TimeCurrent(); for(int i = ArraySize(TimeFxOpen)-1; i >= 0; i--) { // We need first PERIOD_M1 bar for TimeFxOpen[i] which is on PERIOD_H1. For Asian session and tSVR it starts at 01:01 Hrs int idx = iBarShift(mSymbol,PERIOD_M1,TimeFxOpen[i]); datetime vPrevTime = iTime(mSymbol,PERIOD_M1,idx-1); for(int j = 0; j <= 120; j++) { int vHour = _HoD(TimeCurrent()); // Hour value of CurrentTime int vMinute = _MoH(TimeCurrent()); // Minute value of CurrentTime datetime vCurrTime = StringToTime(""+(string)YoY(TimeFxOpen[i])+"."+(string)MoY(TimeFxOpen[i])+"."+(string)DoM(TimeFxOpen[i])+" "+(string)vHour+":"+(string)vMinute); if(cATS.checkTimeCross(vHour,vMinute,vCurrTime,vPrevTime)) { if(mPrevCross != vCurrCross) { if(HoD(vPrevTime) == vHour) { vCurrCross = vCurrTime; mPrevCross = vCurrCross; return(true); } } } } } return(false); } // End of method IsNewSession()
Thanks for your support and time. Regards.
Dear Fellows
Please help me to rectify the below code to get correct IsNewSession value when a new session has started.
I failed to resolve it.
Thanks in advance and happy weekend.