Added SetCustomTimeZone method to CTimeZoneInfo class, which you can use to configure the built-in custom time zone with a specified name, an offset from Greenwich Mean Time (GMT) and a daylight schedule identifier. Later, the custom time zone can be accessed via ZONE_ID_CUSTOM.
bool CTimeZoneInfo::SetCustomTimeZone(
conststring name,
constint baseGMTOffset = 0, // Offset from GMT in secondsconst ENUM_ZONE_ID daylightRuleId = ZONE_ID_UTC
);
fxsaber #: I suggest writing the following functions.
Thanks for that niceidea.
However, I have implemented your idea differently in the library as a custom time zone that you can configure and use freely, like any other time zone.
Would you like to see an hourly chart with bars opening from the second and the fifth minute of the hour? What does a redrawn chart look like when the opening time of bars is changing every minute? What advantages does trading on such charts have? You will find answers to these questions in this article.
However, I have implemented your idea differently in the library as a custom time zone that you can configure and use freely, like any other time zone.
Unfortunately, I couldn’t figure out from your source how I could write the following functions.
I added a new timezone (ZONE_ID_CUSTOM) that you can configure with name, desired base GMT offset and a custom DST schedule of another timezone.
This custom time zone object once configured as you liking (e.g., custom broker), it will handle the updating of its current local time, dst timings, time conversion and text formatting, etc...
// Change DST/GMT.for(int i = 0; i < copied; i++)
{
Rates[i].time = CTimeZoneInfo::ConvertTimeForPlace(Rates[i].time, ZONE_ID_BROKER, ZONE_ID_CUSTOM);
}
Here you convert bar times as given by your broker's time to the corresponding times of the hypothetical broker that we configured above, respecting its defined GMT offset and DST switch times.
The array on converted rates, is then used to display the price chart of the custom broker (or symbol).
Converting bar times from one broker to another causes the timelines (i.e., the simplified graph) of the bars to changes.
** Changing DST schedule changes the shape of the timeline of the weekly start hours of your broker:
DST_US: Straight line (e.g., ICMarkets always starts at 12:00 am Monday, every week, server is always catching up with US "Fx start/end")
DST_UK: Double_notched (spring / autumn: one zone switches early causing a notch, then the other time zone catches up in the same direction, e.g, AdmiralMarkets starts early one hour for 2 weeks in mid-march, and also early one hour in Nov)
DST_AU: Double_Stepped (at time of US switch + AU switch, because switches are in opposite directions at interleaving times)
DST_NONE : Single_step (at time of US switch: although the server does not switch, but the time offset = server-US has changes, e.g., EXness does not apply dst rules, but it starts 21:00 in US summer, and 22:-00 is US winter. Exness does not move, US moves forth and back due to its DST)
** Changing only the GMT offset and keeping the same DST schedule causes shift of the timeline forward / back.
NOTICE: to accurately check those timelines, use the GOLD charts of the broker. They are more reliable for weekly start/end timing than Fx pairs that I found having a lot of variations/surprises.
Update 11 April 2024 - version 1.77
Speed-up of the GetDaylightSwitchTimes mehod. Now using a static array to memorize the switch times for the current year.
Update 12 April 2024 - version 1.80
Fixed issue in the calculation of the broker GMT offset on brokers that do not provide gold trading.
So they can be used as follows.
To check, you can then go to the broker at the desired DST/GMT and compare the real symbol with the custom symbol .
They should match, with only slight differences between bars (different brokers).
Update 15 April 2024 - version 1.82
Added SetCustomTimeZone method to CTimeZoneInfo class, which you can use to configure the built-in custom time zone with a specified name, an offset from Greenwich Mean Time (GMT) and a daylight schedule identifier. Later, the custom time zone can be accessed via ZONE_ID_CUSTOM.
I suggest writing the following functions.
Thanks for that nice idea.
However, I have implemented your idea differently in the library as a custom time zone that you can configure and use freely, like any other time zone.
Update 16 April 2024 - version 1.85
Replaced the GetNthSunday internal method with the more optimized GetMonthTime method.
Thanks for that nice idea.
However, I have implemented your idea differently in the library as a custom time zone that you can configure and use freely, like any other time zone.
Unfortunately, I couldn’t figure out from your source how I could write the following functions.
Forum on trading, automated trading systems and testing trading strategies
Libraries: Local Timezones and Local Session Hours
fxsaber, 2024.04.15 09:34
Could you tell me how to do it correctly?
fxsaber #:
Unfortunately, I couldn’t figure out from your source how I could write the following functions.
Could you tell me how to do it correctly?
Please refer to the code in post #26
I added a new timezone (ZONE_ID_CUSTOM) that you can configure with name, desired base GMT offset and a custom DST schedule of another timezone.
This custom time zone object once configured as you liking (e.g., custom broker), it will handle the updating of its current local time, dst timings, time conversion and text formatting, etc...
Here you convert bar times as given by your broker's time to the corresponding times of the hypothetical broker that we configured above, respecting its defined GMT offset and DST switch times.
The array on converted rates, is then used to display the price chart of the custom broker (or symbol).
The code above achieves the intent of your code:
NB:
Converting bar times from one broker to another causes the timelines (i.e., the simplified graph) of the bars to changes.
** Changing DST schedule changes the shape of the timeline of the weekly start hours of your broker:
** Changing only the GMT offset and keeping the same DST schedule causes shift of the timeline forward / back.
NOTICE: to accurately check those timelines, use the GOLD charts of the broker. They are more reliable for weekly start/end timing than Fx pairs that I found having a lot of variations/surprises.
Basic example of custom time zone:
You can read more about custom time zones in C# docs here: https://learn.microsoft.com/en-us/dotnet/api/system.timezoneinfo.createcustomtimezone?view=net-8.0