code it work like function then use it make offline chart 1, 2 ,3 ..
Thanks, Nguyen Nga! Though could you please show me how to actually do it?? Or are there also alternative solutions to the problem, for instance - can we use loop for it (by looping through the period-multipler number and applying the function repeatedly)? I have the conceptual idea, but am not able to program it myself :-( Who could help me get to the actual solution of it?
You need to create two new folders on your desktop, name them new-folder#1, and new-folder#2.
Once you've done this, Locate the Roaming-Metaquotes-Terminals-xyz-mql4-indicators folder on your C: Drive.
Once you've done this, Locate the Period Converter indicator, then Copy & Paste the Period Converter indicator (twice), once IN each of the two new folders, new-folder#1, and new-folder#2.
Once you have pasted the Period Converter indicator into the new-folder#1 and new-folder#2,
IN new-folder#1 rename the Period Converter to, .ie "Period_Converter01_M1_M2", in new-folder#2 rename the Period Converter to, .ie "Period_Converter01_M1_M3", now copy & paste "Period_Converter01_M1_M3" from new-folder#2 into new-folder#1, now go back to new-folder#2 rename the Period Converter from "Period_Converter01_M1_M3" to, .ie "Period_Converter01_M1_M4", now copy & paste "Period_Converter01_M1_M4" from new-folder#2 into new-folder#1, and so on until you have All of the period converters for each of the desired period multipliers.
Once you have the number of the period converters that you desire in new-folder#1, now you have to open each of them and replace the period multiplier with the desired period multiplier that matches the new period converter indicator's "NAME", .ie "Period_Converter01_M1_M3" would have the period multiplier of 3, Save and Close the indicator file, "Period_Converter01_M1_M4" would have the period multiplier of 4, Save and Close the indicator file.
Repeat process until you complete the modification of All period converter indicator files in new-folder#1.
Now, (indicators ONLY, not the folder itself), Copy & Paste the newly named and modified period converter indicators from new-folder#1 into the Roaming-Metaquotes-Terminals-xyz-mql4-indicators folder on your C: Drive.
REBOOT PLATFORM to recognize new additions in indicators folder.
NOW WORK SMART
Select a symbol, for the example we'll use EUR/USD. Open a EUR/USD M1 chart.
Simply drag and drop period converter indicator into same EUR/USD M1 chart, using different (period multiple) inputs each time you drag & drop. Example drag & drop, set (period multiple) to M2 then apply, drag & drop, set (period multiple) to M3 then apply, drag & drop, set (period multiple) to M4 then apply, drag & drop, set (period multiple) to M6 then apply, drag & drop, set (period multiple) to M7 then apply, drag & drop, set (period multiple) to M8 then apply, and so on...
Once you've applied all of the offline (period multiple) time frames you need produced from the original EUR/USD M1 chart, save the chart to a Template by naming it and saving to your hard drive, Name example "PC1-8" for Period Converter M1 thru M8. Once this task has been completed, close all charts including original EUR/USD M1 chart. Later, this Template can be applied to ANY Symbol.
Now open an m1 chart in any symbol of choice, For example select .ie EUR/USD, set chart to (m1 time frame), apply the template you just saved, the template being applied automatically creates the "Offline Time Frame" chart files for m2, m3, m4, m6, m7, m8, and so on "in the Selected Symbol ONLY,"
Now You need to manually open the "offline charts" of the desired (period multiples) in the specific symbol that you created them in, Example: If you chose EUR/USD, look in the Offline charts list for the EUR/USD symbol and then click on the desired offline time frames you created, each of them will open automatically as you double click on them, EUR/USD M2, EUR/USD M3, EUR/USD M4, EUR/USD M6, EUR/USD M7, EUR/USD M8, and so on, be careful, the charts will auto arrange on the desktop in the order that you open them in, either ascending, descending, or mixed up, so pay attention to detail here.
Once this is done, arrange the charts on the desktop by selecting the "Window" icon in the Toolbar at the top and select arrange "Tile Horizontally" or "Tile Vertically", whichever is your preference, this will automatically arrange the charts in the order "in which they were opened" either in vertical format or horizontal format, horizontal format is better if you have greater than 8 time frames meaning more than 7 offline charts in addition to the original "Live M1 Chart."
Once you like the layout of the charts and have made sure they are in the desired order for organization sake, Now you need to create a PROFILE, do this by looking at the bottom of the platform in the center you'll find the word "Default", Click on this word and the options window will pop up for the PROFILE'S, select "Save Profile As", a window will pop up to Name the Profile, Choose a Name that is logical to your needs, include EUR/USD in the name. Once this is complete, you have a PROFILE that includes all of your desired offline time frames including the original "Live EUR/USD M1 Chart." Each time in the future that you select this Profile, it will automatically populate the desktop with the EUR/USD PROFILE and Template layout you originally created.
You must create a PROFILE for each symbol that you want this specific PROFILE layout and offline time frames for.
The way you do this is Very Simple.
Inside the Profile are the Templates, inside the Templates is the "SYMBOL" name and the list of applied indicators.
Copy & Paste the Profile Folder to your desktop, open the new profile folder that you just pasted to your desktop.
Open each of the 8 Templates using a "Notepad" app, Change The "Symbol Name" from EUR/USD to desired Symbol, .ie EUR/JPY in Each of the Templates within the Profile, then Save and Close All Templates, Close Profile folder.
Go back to desktop, Rename The PROFILE Folder that you pasted to the desktop from EUR/USD to EUR/JPY, Copy and Paste this new Profile from the desktop into the Profile folder within the MT4 program files on your computer.
Now you have Two Profiles of the off line time frames in two different symbols.
Repeat this process for any symbol you want the same profile layout for, remember to always back up your work at each and every step.
I did this Fourteen Years Ago... It Works...
Thanks a ton, Rod!! Really appreciate your taking the time to provide step-by-step approach.
I went ahead and applied the steps (all separate Period Converters created and applied onto a chart). After all the TF offline charts had been created, I then created a Template out of it. Restarted platform and opened a new currency pair. Then applied the Template. However, no offline charts had been created with the new currency.
I realized what the problem was - my default "Period Converter" is a Script (as originally provided by MetaQuotes, attached in the original posting as well), and not an Indicator!
I understand the Template only pulls up, and automatically applies "multiple Indicators" to a chart, but is not able to do that with "multiple Scripts".
So before I can get your solution to work - how can I convert my PeriodConverter (the original provided by MetaQuotes) from a Script into an Indicator??
Reread the instructions.
Template only calls on Symbols and Indicators.
Profile calls on Templates.
Therefore the Profile must consist of the multiple chart-templates including the offline time frames and any indicators you wish to automatically populate the charts, .ie repeatable process.
When profile is applied it should populate the platform screen with the correct charts.
No there is no way that I know of to do it with scripts, at least not at the time when I created this strategy in 2005 (11+ years ago)
A script must be initialized .ie started each time it's applied, must be called manually as far as I know, So only works with Indicators.
Look for the indicator in the indicator library in the forum section.
Here's the code for PERIOD CONVERTER INDICATOR period multiplier = 3
Just Copy & Paste into a blank mql4 file
Period_Converter02_M1_M3
//+------------------------------------------------------------------------+
//| "This Indicator Is An Official Component Of: |
//| "Angiebot Technologies TM" |
//| "Angiebot Pro TM" |
//| "Angiebot Institutional TM" |
//| "Angiebot Premium Investment Grade Technologies TM" |
//| "MIIT Macro Institutional Investment Trader TM" |
//| "BlackBox Industries For MT4/MT5" |
//| "A20&2HFIT" / "A50&5HFIT" / "A80&5HFIT" |
//+------------------------------------------------------------------------+
//| Modified By: |
//| "Rod MT5 Harrell" 2006-2011 |
//| 549 - 66th Street, Oakland, California, 94609-1117, USA |
//| SirRodCA@aol.com / SirRodUS@aol.com |
//| +1-510-655-4966 (PST) |
//+------------------------------------------------------------------------+
#property copyright "Copyright © 2011, Rod MT5 Harrell, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
#property link "Angiebot Premium Trade Technologies TM"
#property copyright "wfy05@talkforex.com"
#property link "http://www.mql4.com/codebase/indicators/277/"
#property indicator_chart_window
#property show_inputs
#include <WinUser32.mqh>
/*
Readme:
I. Features:
This is an improved version of period converter for MT4 based on the
MT4's default period converter by metaquotes.
The default period converter script do not support real-time refreshing,
and consume lots of CPU (50%-9x%) making the whole system slow.
Also, the default one is a script which do not save when you exit MT4,
so you have to apply every converter script again after restarting, quite
annoying.
This one fixed all above problems:
1. Real-time updating or custom interval millisecond level updating.
2. Low CPU cost, average 5%-10% or less.
3. Works as an indicator, so can be saved and reloaded during restart.
4. There is no one converter per chart limitation as it is not script
any more, you can only use one window as source to generate as many
new timeframe chart as possible.
5. Auto updating if there is new history block loaded.
II. How to use:
Copy the mq4 file to your MT4 indicators folder (experts\indicators)
to install it as an indicator, NOT script. then in the custom indicator
list, attach period_converter_opt to the chart you want.
It support 4 parameters:
PeriodMultiplier: new period multiplier factor, default is 2
UpdateInterval: update interval in milliseconds,
zero means update real-time. default is zero.
Enabled: You can disable it without remove it with this option.
Other parameters are comments or for debugging, it is safe to ignore them.
Also Make sure you have Allow Dll imports option checked in common tab or
it won't work
After that, File->Open Offline to open the generated offline data. then
the offline data will be updated automatically.
As long as you keep the source chart open and the converter indicator
running, the generated chart including indicators inside will always
be updated. also you can close the generated chart and open again
later from File->Open Offline without problem.
If you want to quit MT4, you can leave those offline chart as other
normal online charts. when you start MT4 next time, those charts will
also be loaded and updated.
III. Notes:
1. Do NOT uncheck the "offline chart" option in offline chart common properties.
or after MT4 restart, it will treat that chart as online chart and request
the data from server, resulting empty chart window.
2. You can attach more than one converter to same window with different
PeriodMultiplier, e.g: you can attach 3 converter with
PeriodMultiplier = 2, 4, 10 to M1 to generate M2, M4, M10 at the same time.
It is even ok to use the M1 chart to generate Hourly chart like H2, which
only cost a few more CPU resource during initial conversion. but usually
most server don't have much data for those short period. resulting the
generated data isn't long enough for long period. so it is suggested
to use Hourly/Daily charts as source when needed.
3. The real-time updating mode updates quotes as fast as possible, but as
this is done via script, and MT will skip calling start() function when
your PC is busy and lots of quotes income. anyway, this seldom happen,
and you can at least get 10 updates each seconds which is much more
than enough.
4. The offline chart don't have a bid line showing in chart, but all data
in the chart including the indicators is still being updated,
so don't worry. you can show the bid line by unclick the "offline chart"
option in chart properties. but which don't helps much and if you forget
to check "offline chart" option before exit. it will cause errors and
become empty on next startup. you have to close the window and open
again from File->Open offline, which don't worth the trouble.
IV. History:
2005.12.24 1.4 faster to detect if data changed by removing float point
operations, added support to output CSV file in real time.
OutputCSVFile = 0 means no CSV.
OutputCSVFile = 1 means CSV + HST
OutputCSVFile = 2 CSV only, no HST .
(useful if you want to generate CSV for builtin periods)
CSV Filename will be the same as HST file except the extension.
added safe checking for PeriodMultiplier.
2005.12.04 1.3 Fixed missing data when there is large amount of data
loaded in several blocks, and support auto updating
when new history is loaded.
2005.11.29 1.2 Additional fix for missing data and server changing.
2005.11.29 1.1 Fixed missing partial data after restart.
Reinitialize after changing server or data corrupted.
2005.11.28 1.0 Initial release
*/
extern double Version = 1.4; // code version
extern string BuildInfo = "2005.12.24 by wfy05@talkforex.com";
extern int PeriodMultiplier = 4; // new period multiplier factor
extern int OutputCSVFile = 0; // also output CSV file?
extern int UpdateInterval = 0; // update interval in milliseconds, zero means update real-time.
extern bool Enabled = true;
extern bool Debug = false;
int FileHandle = -1;
int CSVHandle = -1;
int NewPeriod = 0;
#define OUTPUT_HST_ONLY 0
#define OUTPUT_CSV_HST 1
#define OUTPUT_CSV_ONLY 2
#define CHART_CMD_UPDATE_DATA 33324
void DebugMsg(string msg)
{
if (Debug) Alert(msg);
}
int init()
{
//safe checking for PeriodMultiplier.
if (PeriodMultiplier <= 1) {
//only output CSV file
PeriodMultiplier = 1;
OutputCSVFile = 2;
}
NewPeriod = Period() * PeriodMultiplier;
if (OpenHistoryFile() < 0) return (-1);
WriteHistoryHeader();
UpdateHistoryFile(Bars-1, true);
UpdateChartWindow();
return (0);
}
void deinit()
{
//Close file handle
if(FileHandle >= 0) {
FileClose(FileHandle);
FileHandle = -1;
}
if (CSVHandle >= 0) {
FileClose(CSVHandle);
CSVHandle = -1;
}
}
int OpenHistoryFile()
{
string name;
name = Symbol() + NewPeriod;
if (OutputCSVFile != OUTPUT_CSV_ONLY) {
FileHandle = FileOpenHistory(name + ".hst", FILE_BIN|FILE_WRITE);
if (FileHandle < 0) return(-1);
}
if (OutputCSVFile != OUTPUT_HST_ONLY) {
CSVHandle = FileOpen(name + ".csv", FILE_CSV|FILE_WRITE, ',');
if (CSVHandle < 0) return(-1);
}
return (0);
}
int WriteHistoryHeader()
{
string c_copyright;
int i_digits = Digits;
int i_unused[13] = {0};
int version = 400;
if (FileHandle < 0) return (-1);
c_copyright = "(C)opyright 2003, MetaQuotes Software Corp.";
FileWriteInteger(FileHandle, version, LONG_VALUE);
FileWriteString(FileHandle, c_copyright, 64);
FileWriteString(FileHandle, Symbol(), 12);
FileWriteInteger(FileHandle, NewPeriod, LONG_VALUE);
FileWriteInteger(FileHandle, i_digits, LONG_VALUE);
FileWriteInteger(FileHandle, 0, LONG_VALUE); //timesign
FileWriteInteger(FileHandle, 0, LONG_VALUE); //last_sync
FileWriteArray(FileHandle, i_unused, 0, ArraySize(i_unused));
return (0);
}
static double d_open, d_low, d_high, d_close, d_volume;
static int i_time;
void WriteHistoryData()
{
if (FileHandle >= 0) {
FileWriteInteger(FileHandle, i_time, LONG_VALUE);
FileWriteDouble(FileHandle, d_open, DOUBLE_VALUE);
FileWriteDouble(FileHandle, d_low, DOUBLE_VALUE);
FileWriteDouble(FileHandle, d_high, DOUBLE_VALUE);
FileWriteDouble(FileHandle, d_close, DOUBLE_VALUE);
FileWriteDouble(FileHandle, d_volume, DOUBLE_VALUE);
}
if (CSVHandle >= 0) {
int i_digits = Digits;
FileWrite(CSVHandle,
TimeToStr(i_time, TIME_DATE),
TimeToStr(i_time, TIME_MINUTES),
DoubleToStr(d_open, i_digits),
DoubleToStr(d_high, i_digits),
DoubleToStr(d_low, i_digits),
DoubleToStr(d_close, i_digits),
d_volume);
}
}
int UpdateHistoryFile(int start_pos, bool init = false)
{
static int last_fpos, csv_fpos;
int i, ps;
// if (FileHandle < 0) return (-1);
// normalize open time
ps = NewPeriod * 60;
i_time = Time[start_pos]/ps;
i_time *= ps;
if (init) {
//first time, init data
d_open = Open[start_pos];
d_low = Low[start_pos];
d_high = High[start_pos];
d_close = Close[start_pos];
d_volume = Volume[start_pos];
i = start_pos - 1;
if (FileHandle >= 0) last_fpos = FileTell(FileHandle);
if (CSVHandle >= 0) csv_fpos = FileTell(CSVHandle);
} else {
i = start_pos;
if (FileHandle >= 0) FileSeek(FileHandle,last_fpos,SEEK_SET);
if (CSVHandle >= 0) FileSeek(CSVHandle, csv_fpos, SEEK_SET);
}
if (i < 0) return (-1);
int cnt = 0;
int LastBarTime;
//processing bars
while (i >= 0) {
LastBarTime = Time[i];
//a new bar
if (LastBarTime >= i_time+ps) {
//write the bar data
WriteHistoryData();
cnt++;
i_time = LastBarTime/ps;
i_time *= ps;
d_open = Open[i];
d_low = Low[i];
d_high = High[i];
d_close = Close[i];
d_volume = Volume[i];
} else {
//no new bar
d_volume += Volume[i];
if (Low[i]<d_low) d_low = Low[i];
if (High[i]>d_high) d_high = High[i];
d_close = Close[i];
}
i--;
}
//record last_fpos before writing last bar.
if (FileHandle >= 0) last_fpos = FileTell(FileHandle);
if (CSVHandle >= 0) csv_fpos = FileTell(CSVHandle);
WriteHistoryData();
cnt++;
d_volume -= Volume[0];
//flush the data writen
if (FileHandle >= 0) FileFlush(FileHandle);
if (CSVHandle >= 0) FileFlush(CSVHandle);
return (cnt);
}
int UpdateChartWindow()
{
static int hwnd = 0;
if (FileHandle < 0) {
//no HST file opened, no need updating.
return (-1);
}
if(hwnd == 0) {
//trying to detect the chart window for updating
hwnd = WindowHandle(Symbol(), NewPeriod);
}
if(hwnd!= 0) {
if (IsDllsAllowed() == false) {
//DLL calls must be allowed
DebugMsg("Dll calls must be allowed");
return (-1);
}
if (PostMessageA(hwnd,WM_COMMAND,CHART_CMD_UPDATE_DATA,0) == 0) {
//PostMessage failed, chart window closed
hwnd = 0;
} else {
//PostMessage succeed
return (0);
}
}
//window not found or PostMessage failed
return (-1);
}
/*
int PerfCheck(bool Start)
{
static int StartTime = 0;
static int Index = 0;
if (Start) {
StartTime = GetTickCount();
Index = 0;
return (StartTime);
}
Index++;
int diff = GetTickCount() - StartTime;
Alert("Time used [" + Index + "]: " + diff);
StartTime = GetTickCount();
return (diff);
}
*/
static int LastStartTime = 0;
static int LastEndTime = 0;
static int LastBarCount = 0;
int reinit()
{
deinit();
init();
LastStartTime = Time[Bars-1];
LastEndTime = Time[0];
LastBarCount = Bars;
}
bool IsDataChanged()
{
/*
static int LastBars = 0, LastTime = 0, LastVolume = 0;
static double LastOpen = 0, LastClose = 0, LastHigh = 0, LastLow = 0;
if (LastVolume != Volume[0] || LastBars != Bars || LastTime != Time[0]||
LastClose != Close[0] || LastHigh != High[0] || LastLow != Low[0] ||
LastOpen != Open[0]) {
LastBars = Bars;
LastVolume = Volume[0];
LastTime = Time[0];
LastClose = Close[0];
LastHigh = High[0];
LastLow = Low[0];
LastOpen = Open[0];
return (true);
}
return (false);
*/
/*
fast version without float point operation
*/
static int LastBars = 0, LastTime = 0, LastVolume = 0;
bool ret;
ret = false;
if (LastVolume != Volume[0]) {
LastVolume = Volume[0];
ret = true;
}
if (LastTime != Time[0]) {
LastTime = Time[0];
ret = true;
}
if (LastBars != Bars) {
LastBars = Bars;
ret = true;
}
return (ret);
}
int CheckNewData()
{
static string LastServer = "";
if (Bars < 2) {
//the data is not loaded yet.
DebugMsg("Data not loaded, only " + Bars + " Bars");
return (-1);
}
string serv = ServerAddress();
if (serv == "") {
//no server yet
DebugMsg("No server connected");
return (-1);
}
//server changed? check this and reinit to prevent wrong data while changing server.
if (LastServer != serv) {
DebugMsg("Server changed from " + LastServer + " to " + serv);
LastServer = serv;
reinit();
return (-1);
}
if (!IsDataChanged()) {
//return if no data changed to save resource
//DebugMsg("No data changed");
return (-1);
}
if (Time[Bars-1] != LastStartTime) {
DebugMsg("Start time changed, new history loaded or server changed");
reinit();
return (-1);
}
int i, cnt;
//try to find LastEndTime bar, which should be Time[0] or Time[1] usually,
//so the operation is fast
for (i = 0; i < Bars; i++) {
if (Time[i] <= LastEndTime) {
break;
}
}
if (i >= Bars || Time[i] != LastEndTime) {
DebugMsg("End time " + TimeToStr(LastEndTime) + " not found");
reinit();
return (-1);
}
cnt = Bars - i;
if (cnt != LastBarCount) {
DebugMsg("Data loaded, cnt is " + cnt + " LastBarCount is " + LastBarCount);
reinit();
return (-1);
}
//no new data loaded, return with LastEndTime position.
LastBarCount = Bars;
LastEndTime = Time[0];
return (i);
}
//+------------------------------------------------------------------+
//| program start function |
//+------------------------------------------------------------------+
int start()
{
static int last_time = 0;
if (!Enabled) return (0);
//always update or update only after certain interval
if (UpdateInterval != 0) {
int cur_time;
cur_time = GetTickCount();
if (MathAbs(cur_time - last_time) < UpdateInterval) {
return (0);
}
last_time = cur_time;
}
//if (Debug) PerfCheck(true);
int n = CheckNewData();
//if (Debug) PerfCheck(false);
if (n < 0) return (0);
//update history file with new data
UpdateHistoryFile(n);
//refresh chart window
UpdateChartWindow();
//if (Debug) PerfCheck(false);
return(0);
}
- www.metaquotes.net
Sorry that period multiplier is
PeriodMultiplier = 4;
Not PeriodMultiplier = 3;
Please don't contact me via the emails listed in the above code, they are no longer my primary e-mailboxes.
Current Primary e-mailbox is RodMT5Harrell@gmail.com
Address & Phone is accurate...
After Creating a new period converter indicator via copying & pasting the above code, simply repeat and change name and period multiplier for each new multiple, save and add to indicator folder, reboot..
After Creating a new period converter indicator via copying & pasting the above code, simply repeat and change name and period multiplier for each new multiple, save and add to indicator folder, reboot..
You're welcome, Timing is Everything, I just so happened to come across the Youtube tutorials on on hosting virtual servers today and posted them to my social networks and that thought process led me to check for some updates specifically in Period Converters, and happened to click on the link which had your question which you had also just posted today, so you got the luck of timing, that's the only reason I logged in today... Happy to have been of help. Feel free to contact me in the future at the above contacts. Have a good weekend.. Always remember, Timing is Everything...
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi!
When I drag the "Period Converter" (raw copy attached) to a chart (for instance, onto a 1-minute EURUSD chart), then I am able to separately create a new offline chart, for instance 3minute off-line chart (basically a new .hst file is created).
My ask from the clever team here is the following:
How can I modify the period converted in such a way that it would create multiple (say 3 separate) offline charts based on the 1-minute chart. not just 1 at a time? So in essence, it would create 2minute, 3minute and 4minute offline chart all at the same time in parallel, all after just dragging the script onto a chart once? Idea being I would not then have to repeat the process manually for each offline charts I would like to create.
Any ideas?
Hat off to anyone caring to answer!
TK