Last update: Dec 10, 2009, posted new v1.8
There have been several versions of period converter programs that were first created in late 2005 and then updated into early 2006, but since then, there have not been any updates (to my knowledge) or solutions to
some of the limitations -- until now.
A new version (>= v1.6) is provided which I've renamed to
"P4L PeriodCon.mq4". (It is a derivative of previous versions called: periodcon.mq4 (v1.5 and v1.4), Period_Converter_Opt.mq4 and Period_Converter.mq4 Previous authors (if known) are credited in the source, and their earlier contributions are graciously acknowledged).
New features:
* Multi-chart live-updates work! The old versions could only live-update (tick-by-tick) a *single* offline chart with a given name. You could generate, e.g. an M20 (offline) chart and open it, but if you opened a 2nd-Nth window(s) of the same M20 (offline) chart, these did not get live-updates! With some hints from FF user rangebound (Thanks!), a new method was devised that finds and updates as many charts of a given name as you open. (FYI, if you only open ONE of each offline chart and if you want to save CPU, there is an external variable ("LiveUpdateMultipleCharts") you can change to "false". However in my experience CPU performance has not been a problem with the new multi-chart method).
* Full support for timeshifts (offsets) for any timeframe chart. Previous version v1.5 had the ability to generate a single Daily chart with one timeshift, but this new version can open many charts -- and of any timeframe, not just Daily -- where the user can specify any timeshift offset desired (plus or minus). HOWEVER: The timeshift *must* be an exact multiple of the source timeframe: 90min timeshift is legal on a source M30, M15, ... or less, but illegal on H1(60min) because it is not an exact multiple (i.e. 90/60 equals "1.5" which is not an exact multiple like 1,2,3, ...).
* Timeshifts are now specified either in #bars, or with the new number format, H.MM, ... or both can be used (as of >= v1.7).
Change the external variable "TimeShiftAdd_in_HptMM" from "0.0" to a number. Examples:
1.0 Timeshift 1hour forward (later). If your
broker time says 22:45:00, then the timeshifted offline chart time will be 23:45:00
0.9 Timeshift 90 minutes forward.
1.3 Timeshift 90 minutes forward (as in 1 hour + 30 min = 90min total, same as 0.90 )
-0.20 Timeshift 20 minutes backward (earlier).
-5.0 Timeshift 5 hours backward (For a GMT broker time, the chart would then display NY local time)
(Reminder, the timeshift must be an exact multiple of the source timeframe (in minutes) ).
If you prefer specifying bars, use variable "TimeShiftAdd_in_Bars" (in >= v1.7). The timeshift (in minutes) is then the #bars * Period (of the source chart).
NOTE: These 2 variables for timeshifts are BOTH in effect and the values will combine (converted to minutes) if you use both variables.
The most obvious
applications of timeshifts would be:
- Open a chart with a timeshift such that the X-axis displays your LOCAL times instead of the broker times.
- Using a single MT4 feed, create H4 and Daily charts where the daily 00:00:00 new bar time has been shifted by any number of hours, to see the same candles as are seen on other broker feeds that have a different native broker time (e.g. GMT vs. GMT+2 vs. GMT-17 etc.) You can decide if you want new Daily candles to occur at London open, NY open, NY close, etc.
- Create M45 candles but shift the bar start time as desired, to align with a time such as NY open (8AM ET) or NYSE open (9:30AM ET).
- Get a 1minute headstart on a bar close by shifting it 0.01. (How? Use an M1 chart to generate a higher TF chart timeshifted by +1M)
- Generate a Daily chart with 5-bars-per-week instead of the common 6-bars-per-week! Example: Suppose your broker time is 00:00:00 the same time as GMT. NewYork is GMT-5 which is 19:00:00. Your broker closes on Friday < 17:00:00 NY and reopens on Sunday >= 17:00:00 NY. Your Daily chart has a 2-hour Sunday bar, which is undesired. SO, you can generate an offline xxxxxx+2H,Daily chart which will *eliminate* the Sunday bar! If your broker has exactly 24*5=120 (or less) bars-per-week, and if you currently have a short Sunday (or Saturday) Daily bar on your chart, then you can pick an appropriate timeshift to eliminate your extra (short) Daily bar!
- Traders who look for candlestick patterns can try different timeshifts to see if a pattern is more (or less) successful for timeshifted vs. normal broker time.
* As before, one can still add multiple instances of this indicator to a single source chart to generate the data for multiple, different timeframe-or-timeshifted offline charts.
* An unobtrusive number of popup Alerts were added to notify the user of the offline chart name, and whether there were any problems with generating the desired chart. These occur when you add the indicator to the source chart, or when you restart MT4 with a session that has a chart with this indicator attached.
* A lot of people like to use indicators like CandleTime.mq4 to display the time remaining for the bar. However, for timeshifted data, some indicators (like these) don't work unless modified appropriately. A new version v1_2 of my
"P4L CandleTime.mq4" indicator has been posted which is compatible with the timeshifted offline charts. Please download it from this thread:
"New very cool CandleTime and session time Clock indicators"
(Note, a new v1_3 (not released yet) will be required to support charts > 1 Month period).
How to use:
* Copy this indicator to C:/Program Files/__your_MT4_broker__/experts/indicators/
Review the source with MetaEditor, Save+Compile any changes to defaults. Quit and restart MT4.
* Open a source chart of a lower-timeframe that is a multiple of whatever chart you want to generate. If you want a Daily chart with different hourly offsets than your existing normal Daily chart, then you could open an H1 chart or lower. (Note, you can choose any source TF but you will only generate data for only as much data as is in your source chart. If your M5 has 4 months of data, if you want to generate Daily charts, you would probably prefer to use H1 as source since it would likely have many more months/years of data. If you want to use a timeshift, the value (in minutes) must be an exact multiple of your source chart timeframe (in minutes) (e.g. 90min/M30 is legal but 90min/H1 is not).
* Add this indicator to the source chart. NOTE: On the Common tab, you must check the box to
"Allow DLL imports".
* As desired, change the values for the variables PeriodMultiplier and/or TimeShiftAdd_in_HptMM (or TimeShiftAdd_in_Bars), and any other external variable. Example: Open an EURUSD,H1 chart, add this indicator and set PeriodMultipler=24 and a timeshift = -2.0. It will generate the data for a "EURUSD-2H,Daily" chart.
* Next, use the menu command: File -> Open offline -> (go down the list to find the exact chart name generated, i.e "EURUSD-2H,Daily"). Select it and click "Open".
Limitations:
* Due to a MT4 limitation, in order to open any offline chart with a bar period of greater than 1 Month (30 days), MT4 must be fooled by telling it the period is <= 1Month. To tell the user what the actual period is, EITHER the symbol name is changed, or the period is changed (FYI, the period is always wrong for charts > 1 Month; this is a consequence of the MT4 limitations). For the following discussion, keep in mind that a chartname is always "symbol,period".
In >= v1.8, variable "Over_1MN_alters_Symbol_name" is "true" by default. This method is much easier to determine at a glance what is the actual chart period, but it is less compatible with some indicators (especially MTF, a.k.a. multi-time-frame) that require the original "Symbol()" name to be unmodified.
If "Over_1MN_alters_Symbol_name = true" :
An "_x#" is added to the Symbol name, where # is the PeriodMultiplier. Example:
EURUSD_x12,Monthly (This is 12 months, i.e. a Yearly chart!)
Due to an MT4 limit of 11-characters for the symbol name, if the user specifies also a timeshift and/or a large PeriodMultiplier, the symbol name is hacked in various creative ways to shorten it so MT4 can handle it. For example, a Monthly chart with PeriodMultiplier =12 and TimeShiftAdd_in_bars = 1 would be:
EURUSD+1Nx12,Monthly (ILLEGAL 12 character name!)
EU+1N_x12,Monthly (shortened symbol name). (Note "+1N" is +1 month shift!)
If "Over_1MN_alters_Symbol_name = false" :
Instead of changing the "Symbol()" name, the "Period()" is modified instead by the formula "Period() - PeriodMultiplier". The "Period()" in this case is the *source* chart period, which in common practice when generating charts over 1-month (30 days) is likely to be either PERIOD_MN1 (43200), or PERIOD_W1 (10080) or PERIOD_D1(1440). Examples:
A monthly source chart with PeriodMultiplier=2 will generate: EURUSD,M43198
A weekly source chart with PeriodMultiplier=5 will generate: EURUSD,M10075
Note: 4 hour charts are PERIOD_H4(240) but would require a multiplier of at least 180 to exceed 1-month bars. Perhaps it will work but it probably will be more confusing to even try. (FYI, regardless of timeframe, if "Period() - PeriodMultiplier" is negative, an arbitrary value of "101" is used instead).
Note2: Regardless of the setting for "Over_1MN_alters_Symbol_name", in the generated chart, the value for "Period()" is a lie! If you try to use indicators that require an accurate value for "Period()", it's going to be wrong and your indicator source must be changed to correct this. If the variable is "true", the true period is found by decoding the "Symbol()" name, finding the "#" after "x", and multiplying it times the "Period()" value. If instead the variable is "false", the true period is found by noting that it is slightly less than one of PERIOD_MN1, PERIOD_W1 or PERIOD_D1, calculating the difference, then multiplying the difference times the nearby PERIOD_* value. This is complicated... sometime in the future, I intend to post a routine to do this conversion which you can incorporate into your indicators. (Don't know when I'll get to it...)
* As before, you cannot generate a chart that has the same period as an already existing normal timeframe: M1, M5, M15, M30, H1, H4, Daily, Weekly, Monthly (and on some brokers like Oanda, M10). However, as it already exists, there is no point in doing so. HOWEVER, if you want one of these standard charts but timeshifted by some amount, no problem.
* Some indicators aren't compatible with these generated charts. Any timeshifted chart tells the user how much the shift is by changing the "Symbol()" name. If your source chart is "EURUSD" and you timeshift by +15 minutes, the offline (new) Symbol() name is "EURUSD+15M". Most indicators, EAs and scripts don't care about what the symbol name is exactly, but some of them do. Therefore, offline charts may not be compatible with some programs unless they have been properly modified to account for this Symbol() name change (AND also, if necessary, account for the fact that the bars have been timeshifted relative to the broker time). Also note that any indicator that has hardcoded the standard timeframe values may need modifications to work with non-standard timeframes like M10, M45, H2, etc.
* In MT4 when you open an offline chart, it does not use your "Default" chart template (if you have one), but you can just manually load any desired template.
Thinking ahead:
Please note that this indicator is written for MT4. The new MT5 version (out in beta now and to be released in 2010) can already generate charts with just about any timeframe (i.e. M2, M10, M20, M1234, H2, H8, etc. NOT sure about > Monthly(?) ). I have no idea if MT5 already supports an ability to timeshift data or not. Please comment if you know the answer. (So far, the answer has been "no").
UPDATES:
2009-11-13: First release of "P4L PeriodCon.mq4" v1.6 (
Was downloaded 68 times).
2009-12-07: Released v1.7 update of "P4L PeriodCon.mq4" (Was downloaded 16 times).
Thanks to circlesquare, a method to
create charts > 1 Month was found. MT4 can be fooled by (falsely) marking a chart as "Monthly" or less even though the data is > 1 Month-per-bar. However, to visually tell the user what is the actual period, the symbol name is modified to add "_x#" (e.g. "EURUSD_x12,Monthly" is actually a Yearly chart! Also added back in the "
TimeShiftAdd_in_Bars" variable which is easier for higher timeframes.
2009-12-10: Released v1.8 update of "P4L PeriodCon.mq4"
Added new variable "Over_1MN_alters_Symbol_name" ("true" by default). This is the more readable format used in v1.7, but setting it to "false" will modify the "Period()" value: Source-Period() - PeriodMultiplier. This later method leaves the Symbol() name unchanged (so long as timeshifts are zero!!) which makes generated charts somewhat more compatible with indicators. (Note, for charts > 1-month, the "Period()" is always a lie -- this was necessary to get around an MT4 limitation).
Screenshots:
The white charts are native timeframes, the black ones are generated "offline" charts. (FYI, you can change the colors of "offline" charts just like any other chart).
Note the non-standard timeframes generated (M10, M45, H2, H8).
Note the time-shifted Daily charts with +2H and -1H. A regular Daily chart is between them. See how the new "P4L CandleTime.mq4" indicator displays different numbers of hours for each Daily chart before the bar closes for each of those charts. The +2H has 17:29:21 remaining, regular has 19:29:21, and -1H has 20:29:21 remaining.
-----------------------------------------------
FYI, see also:
Collection of programs by pips4life
-----------------------------------------------