Is the DealWithTime.mqh have problem working on weekend, even in StrategyTester?
It is returning following error:
You have really made a very useful utility, however complexities involved to implement it in an Indicator or an EA, are outweighing against its benefits. (Or may be my skills are not yet upto mark) :(
Regards
Could it be that you broker does not offer quotes for that and previous times? Have you checked that?
Beside that the time around Christmas (~Dec.20 .. Jan. 8) are not the best for backtests!
Sorry for my above comment, please ignore it. I was really frustrated, as I was having so many challenges for my project VolumeProfile Indicator.
I have tried to incorporate following methods into your code and somehow succeeding to get results. Will keep you posted on developments.
The Constructor method ...
//+-----------------------------------------------------------------------------------------------------------------------------+//| CLASS: CDealWithTime() ... file to be renamed once this class is working properly//+-----------------------------------------------------------------------------------------------------------------------------+class CDealWithTime final { // The use of the 'final' specifier during class declaration prohibits further inheritance from this class.public:
// Default Constructor with default parameters. Need so *pointer class can be declared
CDealWithTime() { mSymbol = mSymbol; mTimeFrame = mTimeFrame; }
~CDealWithTime() { }
voidOnTick(void);
public:
bool setBokerOffset();
void checkTimeOffset(datetime tB);
int SecTillClose();
private:
bool calcSwitchUSD(datetime now=0);
bool calcSwitchEUR(datetime now=0);
bool calcSwitchAUD(datetime now=0);
void calcSwitchRUB(constdatetime t);
datetime arrTme[]; // array to copy timestring mSymbol; // Default EURUSDENUM_TIMEFRAMES mTimeFrame; // Default PERIOD_H1datetime mPrevTimeH01;
bool IsNewBarH01();
}; // END of class CDealWithTime() definition
The Support Methods OnTick and IsNewBarH01 ...
//+-----------------------------------------------------------------------------------------------------------------------------+//| function to determin broker offset for the time given (tB)//+-----------------------------------------------------------------------------------------------------------------------------+void CDealWithTime::OnTick(void) {
string vMethod = __FUNCTION__ + " Line[" + (string)__LINE__ + "] ";
if(IsNewBarH01()) {
datetime weekBegin = BoW(TimeCurrent())+26*3600;
int attempt = 0;
int copied = 0;
// get time last 1h bar before switch in EUint bars = Bars(mSymbol,mTimeFrame,weekBegin,(weekBegin)+(5*24*3600));
ResetLastError();
while(CopyTime(mSymbol,mTimeFrame,weekBegin,5,arrTme) != bars && attempt <= 10) {
Sleep(100);
attempt++;
}
if(attempt > 0) {
PrintFormat("%s: Error[%i] copiedTime %s-%s for [%i] bars from [%s] to [%s]",vMethod,GetLastError(),mSymbol,EnumToString(mTimeFrame),TimeToString(weekBegin),TimeToString((weekBegin)+(5*24*3600)));
}
else setBokerOffset();
}
} // End of checkTimeOffset()
With this I am able to run the code without error Assigning the broker offset went wrong - somehow.
Additional fine tuning is still on to make it a workable solution.
Is the DealWithTime.mqh have problem working on weekend, even in StrategyTester?
It is returning following error:
2024.02.1015:06:12.6382024.01.0100:00:00Alert: DealingWithTime v2.03.mqh[596] Assigning the broker offset went wrong - somehow.
You have really made a very useful utility, however complexities involved to implement it in an Indicator or an EA, are outweighing against its benefits. (Or may be my skills are not yet upto mark) :(
Regards
I also found the same error today (Saturday) when testing the library.
The BoW(t) macro has a bug.
If (t) is anytime in Saturday, BoW(t) calculates the beginning of the NEXT WEEK (wrong ?!), not current week.
amrali #: #include "DealingWithTime.mqh"// to use BoW(t) -- !!! Note: if (t) is Saturday, BoW(t) returns the begining of the NEXT WEEK (wrong ?!), not current week.#define BoW_fixed(t) ((t)-((t)+345600)%604800)
I was trying to run it again today (my CurrentTime 17-Feb-2024 15:47 UTC+5.30) which is Saturday.
Facing error ... Assigning the broker offset went wrong - somehow. Error occurring in checkTimeOffset() and I have tried to put do..while loop to allow 10 attempts to setBrokerOffset().
The error happened with BoW as well as BoW_fixed variable. I am getting same datetime value with both of them.
Worst thing is there is no Error message, even in the debugging mode, as why it failed to set.
2024.02.1716:35:09.3212024.02.1601:01:00 USD-DST for2024.02.1601:01 DST: 0 nxtSwitch: SUN 2024.03.1003:00 USD Spring: second 10 Sunday of March: 32024.02.1716:35:09.3212024.02.1601:01:00 DST_EUR for2024.02.1601:01 DST: 0 nxtSwitch: SUN 2024.03.3103:00 EUR Spring: last 31 Sunday of March: 32024.02.1716:35:09.3212024.02.1601:01:00 AUD-DST for2024.02.1601:01 DST: -3600 nxtSwitch: SUN 2024.04.0703:00 AUD Spring: first 7 Sunday of April: 42024.02.1716:35:09.3212024.02.1601:01:00 Setting broker time offset at: FRI, 2024.02.1601:01for Pepperstone Group Limited
2024.02.1716:35:09.3212024.02.1601:01:00 Offest (time+diff=GMT): OffsetBroker.actOffset: -7200 sec => GMT: 2024.02.1523:01 time area: US=Winter & EU=Winter
2024.02.1716:35:09.3212024.02.1601:01:00get the seconds until FX closes (NY 17:00) with SecTillClose(): 82739 sec or 22 h, close time: FRI, 2024.02.1623:592024.02.1716:35:09.3212024.02.1601:01:00 DealWithTimeV2.03.mqh[513] OffsetBroker.set[true]
2024.02.1716:35:09.3212024.02.1601:01:00 CDealWithTime::checkTimeOffset: TimeCurr[2024.02.1601:01] BoW[2024.02.1100:00] BoW_fixed[2024.02.1100:00] setBokerOffset attempt[1] isTimeSet[true]
2024.02.1716:35:09.3212024.02.1601:01:00 Setting broker time offset at: FRI, 2024.02.1601:01for Pepperstone Group Limited
2024.02.1716:35:09.3212024.02.1601:01:00 Offest (time+diff=GMT): OffsetBroker.actOffset: -7200 sec => GMT: 2024.02.1523:01 time area: US=Winter & EU=Winter
2024.02.1716:35:09.3212024.02.1601:01:00get the seconds until FX closes (NY 17:00) with SecTillClose(): 82739 sec or 22 h, close time: FRI, 2024.02.1623:592024.02.1716:35:09.3212024.02.1601:01:00 DealWithTimeV2.03.mqh[513] OffsetBroker.set[true]
got totally different results in another run :( ... this time it did setBroker which lead to correct time calculation for Asian/LON/NYC session time in my Broker's Server time. This matched with times at https://www.babypips.com/tools/forex-market-hours. I did used variable ... BoW_fixed (Though BoW and BoW_fixed returned same value)
2024.02.1716:35:09.3982024.02.1601:01:00 [XAUUSD,2024.02.1601:01] CVPSBase::IsNewBarD01: tSessions Day idx[3]: for [XAUUSD] tSVR[2024.02.1601:01] Open tASA_SVR[2024.02.1301:01] tLON_SVR[2024.02.1310:00] tNYC_SVR[2024.02.1315:00]
2024.02.1716:35:09.3982024.02.1601:01:00 [XAUUSD,2024.02.1601:01] CVPSBase::IsNewBarD01: tSessions Day idx[2]: for [XAUUSD] tSVR[2024.02.1601:01] Open tASA_SVR[2024.02.1401:01] tLON_SVR[2024.02.1410:00] tNYC_SVR[2024.02.1415:00]
2024.02.1716:35:09.3982024.02.1601:01:00 [XAUUSD,2024.02.1601:01] CVPSBase::IsNewBarD01: tSessions Day idx[1]: for [XAUUSD] tSVR[2024.02.1601:01] Open tASA_SVR[2024.02.1501:01] tLON_SVR[2024.02.1510:00] tNYC_SVR[2024.02.1515:00]
2024.02.1716:35:09.3982024.02.1601:01:00 [XAUUSD,2024.02.1601:01] CVPSBase::IsNewBarD01: tSessions Day idx[0]: for [XAUUSD] tSVR[2024.02.1601:01] Open tASA_SVR[2024.02.1601:01] tLON_SVR[2024.02.1610:00] tNYC_SVR[2024.02.1615:00]
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Hi @Carl Schreiber
Is the DealWithTime.mqh have problem working on weekend, even in StrategyTester?
It is returning following error:
You have really made a very useful utility, however complexities involved to implement it in an Indicator or an EA, are outweighing against its benefits. (Or may be my skills are not yet upto mark) :(
Regards
Could it be that you broker does not offer quotes for that and previous times? Have you checked that?
Beside that the time around Christmas (~Dec.20 .. Jan. 8) are not the best for backtests!Hi @Carl Schreiber
Sorry for my above comment, please ignore it. I was really frustrated, as I was having so many challenges for my project VolumeProfile Indicator.
I have tried to incorporate following methods into your code and somehow succeeding to get results. Will keep you posted on developments.
The Constructor method ...
The Support Methods OnTick and IsNewBarH01 ...
With this I am able to run the code without error Assigning the broker offset went wrong - somehow.
Additional fine tuning is still on to make it a workable solution.
Could it be that you broker does not offer quotes for that and previous times? Have you checked that?
Beside that the time around Christmas (~Dec.20 .. Jan. 8) are not the best for backtests!Hi Carl
Thanks for taking off time to reply me.
With the changes as mentioned above, I am able to run it without error in EA. So the Broker is providing data for these days.
Yeh you have a valid point that " Beside that the time around Christmas (~Dec.20 .. Jan. 8) are not the best for backtests!" :)
However, since it is not strategy BackTest, but just to make sure that my VolumeProfile OOP Class is working well and returning correct Session Times.
Have a nice weekend and take care.
Amazing job! Thank you!
:)
Very inspiring library!
a little suggestion about macro expansions
t needs to be enclosed in parentheses to avoid side effects inside these macros DoWi, SoW, rndHoT, BoW.
without the small fix, the above prints 1, 5
Very inspiring library!
a little suggestion about macro expansions
t needs to be enclosed in parentheses to avoid side effects inside these macros DoWi, SoW, rndHoT, BoW.
without the small fix, the above prints 1, 5
Thanks, I hadn't thought of such an application, will change that...
Forum on trading, automated trading systems and testing trading strategies
Libraries: Dealing with time (2) functions
Anil Varma, 2024.02.10 10:39
Hi @Carl Schreiber
Is the DealWithTime.mqh have problem working on weekend, even in StrategyTester?
It is returning following error:
You have really made a very useful utility, however complexities involved to implement it in an Indicator or an EA, are outweighing against its benefits. (Or may be my skills are not yet upto mark) :(
Regards
I also found the same error today (Saturday) when testing the library.
The BoW(t) macro has a bug.
If (t) is anytime in Saturday, BoW(t) calculates the beginning of the NEXT WEEK (wrong ?!), not current week.
This is a fixed version of BoW()
#include "DealingWithTime.mqh" // to use BoW(t) -- !!! Note: if (t) is Saturday, BoW(t) returns the begining of the NEXT WEEK (wrong ?!), not current week. #define BoW_fixed(t) ((t)-((t)+345600)%604800)
Thanks @amrali to point out the bug.
Will incorporate into my revised version of the Class.
I also found the same error today (Saturday) when testing the library.
The BoW(t) macro has a bug.
If (t) is anytime in Saturday, BoW(t) calculates the beginning of the NEXT WEEK (wrong ?!), not current week.
This is a fixed version of BoW()
Hi @amrali
I was trying to run it again today (my CurrentTime 17-Feb-2024 15:47 UTC+5.30) which is Saturday.
Facing error ... Assigning the broker offset went wrong - somehow. Error occurring in checkTimeOffset() and I have tried to put do..while loop to allow 10 attempts to setBrokerOffset().
The error happened with BoW as well as BoW_fixed variable. I am getting same datetime value with both of them.
Worst thing is there is no Error message, even in the debugging mode, as why it failed to set.
got totally different results in another run :( ... this time it did setBroker which lead to correct time calculation for Asian/LON/NYC session time in my Broker's Server time. This matched with times at https://www.babypips.com/tools/forex-market-hours. I did used variable ... BoW_fixed (Though BoW and BoW_fixed returned same value)
when set this setting on ...
2024.02.17 16:52:15.694 2024.02.01 01:01:00 CDealWithTime::checkTimeOffset: TimeCurr[2024.02.01 01:01] BoW[2024.01.28 00:00] BoW_fixed[2024.01.28 00:00] setBokerOffset attempt[1] isTimeSet[true]
2024.02.17 16:52:15.694 2024.02.01 01:01:00 DealWithTimeV2.03.mqh[513] OffsetBroker.set[true]
seems more testing is required :)