MT4自定义周期实时更新程序
MT4自定义周期实时更新程序 已经更新成1.3版本
最后一次代码更新在第5页的87楼
一. 功能
这个是MT4自带的period_converter的重写改进版, 自带的period_converter
不少人都用过, 不支持真正的实时刷新, 单个转换脚本就占用大量的CPU(50%-9x%)
导致整个系统变慢. 退出MT4下次重新进来还得重新对各窗口应用脚本才能再次
更新,麻烦至极.
这个改进版解决了上面的所有问题:
1. 支持实时刷新或者自定义到毫秒级的刷新周期.
2. 很低的CPU占用, 平均为5%-10%或者更低.
3. 以指标模式工作,退出MT4再重新启动也不会有任何问题,一切恢复到退出
之前的设置.
4. 没有每个窗口只能应用一个脚本的限制,用不同参数可以从同一窗口生成
多个不同的输出结果到多个窗口.
二. 使用方法
和其他的MT4指标安装类似,复制到experts\indicators即可完成安装.
注意必须安装为自定义指标而不是脚本. 然后类似其他指标那样操作,
添加到你想转化的窗口即可.
参数设置:
PeriodMultiplier: 新的周期对于原周期的倍数。
UpdateInterval: 刷新间隔, 毫秒为单位, 0表示实时刷新
默认为实时刷新.
Enabled: 是否启用刷新.
注意必须将允许动态库调用选项允许,否则将无法正常工作.
之后通过文件->打开离线历史数据打开刚生成的图表即可. 然后将会
自动进行实时刷新.
只要你一直保持数据源窗口以及该程序运行,则生成的离线图表也会
一直保持为最新状态,包括其中的指标等等. 关闭该离线窗口后, 你
也可以再重新通过文件->打开离线历史数据打开.
如果需要退出或者重新启动MT4, 可以和往常一样正常退出,离线图表
以及设置会同样保存并且下次重新启动后加载恢复到上次同样设置.
三. 注意事项
1. 注意"不"要将离线窗口属性中的"离线窗口"的勾去掉,否则退出
MT4再重新启动该窗口将被当成实时数据而导致无法获得数据.
这种情况下将需要重新关闭离线窗口后重新打开.
2. 你可以在同一个数据源窗口中加载多个不同倍数设置的转换程序,
从而获得多个数据输出, 比如对M1使用PeriodMultiplier = 2, 4, 10
将同时获得M2, M4, M10. 甚至可以使用M1数据来获得小时图.
但一般因为服务器上不会有太多的短周期数据,所以这样讲导致
生成的数据时间跨度不大, 所以推荐用接近的数据周期来获得需要
的周期.比如用H1来获得H2.
3. 实时刷新时候将尽可能快地进行数据刷新, 即对每一次数据变动,
但如果同时有大量数据进入时可能会错过部分数据, 但这种情况
一般不会出现而且你至少可以获得每秒十次以上的刷新率, 这已经
完全足够用了.
4. 离线图表窗口没有那条买入价线显示,但数据实际上还是被刷新的,
如果该城非离线窗口则必须退出前改回来, 否则下次启动就会得不到
数据. 一般就没有必要去弄这个麻烦.
5. 如果你在源数据窗口中往前拉到了新的历史数据, 生成的数据窗口里面
是不会自动更新这些数据的, 需要ctrl+I显示指标列表后选择对应的
指标然后双击弹出设置窗口后确认即可.
另外附一个用这个改进的版本后开了M1->M3, M10, 以及H1->H2的转换时候
的CPU使用率图.
如需转载请保留原始版权信息, 谢谢.
更新到1.3版本,解决了当重新启动后新加载的数据过多时候可能出现的数据丢失情况, 并且现在支持源数据窗口中新增加了开头的历史数据时候的自动更新. 不过因为现在是周末服务器没有数据刷新没有进行完整测试, 请大家帮忙测试.
//+------------------------------------------------------------------+
//| Period_Converter_Opt.mq4|
//| Copyright ?2005, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//| Modified by wfy05@talkforex based on Period_Converter|
//| http://www.talkfx.com |
//+------------------------------------------------------------------+
#property copyright "[email protected]"
#property link "http://www.talkfx.com"
#property indicator_chart_window
#property show_inputs
#include
/*
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.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.3; // code version
extern string BuildInfo = "2005.12.04 by [email protected]";
extern int PeriodMultiplier = 2; // new period multiplier factor
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 NewPeriod = 0;
#define CHART_CMD_UPDATE_DATA 33324
void DebugMsg(string msg)
{
if (Debug) Alert(msg);
}
int init()
{
NewPeriod = Period() * PeriodMultiplier;
if (OpenHistoryFile() < 0) return (-1);
WriteHistoryHeader();
WriteHistoryFile(Bars-1, true);
UpdateChartWindow();
return (0);
}
void deinit()
{
//Close file handle
if(FileHandle >= 0) {
FileClose(FileHandle);
FileHandle = -1;
}
}
int OpenHistoryFile()
{
FileHandle = FileOpenHistory(Symbol()+NewPeriod+".hst", FILE_BIN|FILE_WRITE);
if(FileHandle < 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);
}
int WriteHistoryFile(int start_pos, bool init = false)
{
static int last_fpos, i_time;
static double d_open, d_low, d_high, d_close, d_volume;
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;
} else {
i = start_pos;
FileSeek(FileHandle,last_fpos,SEEK_SET);
}
if (i < 0) return (-1);
int cnt = 0;
int LastBarTime;
//processing bars
while (i >= 0) {
LastBarTime = Time;
//a new bar
if (LastBarTime >= i_time+ps) {
//write the bar data
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);
cnt++;
i_time = LastBarTime/ps;
i_time *= ps;
d_open = Open;
d_low = Low;
d_high = High;
d_close = Close;
d_volume = Volume;
} else {
//no new bar
d_volume += Volume;
if (Lowd_high) d_high = High;
d_close = Close;
}
i--;
}
//record last_fpos before writing last bar.
last_fpos = FileTell(FileHandle);
//write last bar's data
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);
cnt++;
d_volume -= Volume[0];
//flush the data writen
FileFlush(FileHandle);
return (cnt);
}
int UpdateChartWindow()
{
static int hwnd = 0;
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);
}
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 <= LastEndTime) {
break;
}
}
if (i >= Bars || Time != 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
WriteHistoryFile(n);
//refresh chart window
UpdateChartWindow();
//if (Debug) PerfCheck(false);
return(0);
}
[ 本帖最后由 管理员No.6 于 2007-1-18 11:09 编辑 ]CPU.gif
发表于:2005-11-29 04:50只看该作者
2楼
韬客社区www.talkfx.co
发表于:2005-11-29 05:25只看该作者
3楼
高,谢谢啦!
发表于:2005-11-29 07:35只看该作者
4楼
呵呵,MT4和wfy05 都很棒。
发表于:2005-11-29 08:35只看该作者
5楼
....强啊。。。。。。去申请给你加分哈
[ 本帖最后由 老正 于 2005-11-29 16:36 编辑 ]
遇到矛盾 先站在对方的立场上想想问题,先试着去理解别人
● 如何使用WinMTR查询平台连接流畅度
发表于:2005-11-29 10:35只看该作者
6楼
谢谢哦,我用上了.^_^
冷静观察、稳住阵脚、沉着应付、韬光养晦、有所作为、决不当头。
7楼
原帖由 老正 于 2005-11-29 16:35 发表 ....强啊。。。。。。去申请给你加分哈
韬客社区www.talkfx.co
8楼
更新到版本1.2, 进一步修正了一些特殊情况下的数据丢失或者异常处理,比如切换服务器或者当因为休市出现数据间隔的时候的情况,前面下了老版本的请更新一下. (直接覆盖源mq4文件后重启MT4再重新设置即可)
btw: 正版能不能帮忙把新版本也更新到顶楼帖子上? 免得后来的还得到后面找.
//+------------------------------------------------------------------+
//| Period_Converter_Opt.mq4|
//| Copyright ?2005, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//| Modified by wfy05@talkforex based on Period_Converter|
//| http://www.talkfx.com |
//+------------------------------------------------------------------+
#property copyright "[email protected]"
#property link "http://www.talkfx.com"
#property indicator_chart_window
#property show_inputs
#include
/*
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.
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.
5. If you downloaded new history data in the source chart, and want to update
the generated chart as well, ctrl+I to bring indicator list and
choose the indicator you want, and double click to show inputs then
click OK to reinitialize it.
IV. History:
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.2; // code version
extern string BuildInfo = "2005.11.29 by [email protected]";
extern int PeriodMultiplier = 2; // new period multiplier factor
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 LastBarTime = 0;
int NewPeriod = 0;
string LastServer = "";
#define CHART_CMD_UPDATE_DATA 33324
int init()
{
LastBarTime = 0;
NewPeriod = Period() * PeriodMultiplier;
if (OpenHistoryFile() < 0) return (-1);
WriteHistoryHeader();
WriteHistoryFile(Bars-1, true);
UpdateChartWindow();
LastServer = ServerAddress();
return (0);
}
void deinit()
{
//Close file handle
if(FileHandle >= 0) {
FileClose(FileHandle);
FileHandle = -1;
}
}
int OpenHistoryFile()
{
FileHandle = FileOpenHistory(Symbol()+NewPeriod+".hst", FILE_BIN|FILE_WRITE);
if(FileHandle < 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);
}
int WriteHistoryFile(int start_pos, bool init = false)
{
static int last_fpos, i_time;
static double d_open, d_low, d_high, d_close, d_volume;
int i, ps;
if (FileHandle < 0) return (-1);
if (init) {
//first time, init data
d_open = Open[start_pos];
d_low = Low[start_pos];
d_high = High[start_pos];
d_volume = Volume[start_pos];
d_close = Close[start_pos];
i = start_pos - 1;
} else {
i = start_pos;
FileSeek(FileHandle,last_fpos,SEEK_SET);
}
if (i < 0) return (-1);
// normalize open time
ps = NewPeriod * 60;
i_time = Time[start_pos]/ps;
i_time *= ps;
int cnt = 0;
//processing bars
while (i >= 0) {
LastBarTime = Time;
//a new bar
if (LastBarTime >= i_time+ps) {
//write the bar data
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);
cnt++;
i_time = LastBarTime/ps;
i_time *= ps;
d_open = Open;
d_low = Low;
d_high = High;
d_close = Close;
d_volume = Volume;
} else {
//no new bar
d_volume += Volume;
if (Lowd_high) d_high = High;
d_close = Close;
}
i--;
}
//record last_fpos before writing last bar.
last_fpos = FileTell(FileHandle);
//write last bar's data
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);
cnt++;
d_volume -= Volume[0];
//flush the data writen
FileFlush(FileHandle);
return (cnt);
}
int UpdateChartWindow()
{
static int hwnd = 0;
if(hwnd == 0) {
//trying to detect the chart window for updating
hwnd = WindowHandle(Symbol(), NewPeriod);
}
if(hwnd!= 0) {
if (IsDllsAllowed() == false) {
//DLL call must be allowed
if (Debug) Alert("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 reinit()
{
deinit();
init();
}
//+------------------------------------------------------------------+
//| script 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 (Bars < 2) {
//the data is not loaded yet.
if (Debug) Alert("Data not loaded, only ", Bars, " Bars");
return (0);
}
static int wait_count = 0;
if ((Time[0] - Time[1]) != Period() * 60) {
//this will happen when the client load block of data at startup.
//return and wait till the data fully loaded in next call
wait_count++;
//only wait 3 times, to prevent deadlock when server data missing.
if (wait_count <= 3) {
if (Debug) Alert("Data not fully loaded, waiting for update");
return (0);
}
}
wait_count = 0;
//server changed?
if (LastServer != ServerAddress()) {
if (Debug) Alert("Server changed from ", LastServer, " to ", ServerAddress(), ", reinitialize");
reinit();
return (0);
}
//init failed?
if (!LastBarTime) {
if (Debug) Alert("Zero LastBarTime, reinitialize");
reinit();
return (0);
}
//going to find the bar index which matching LastBarTime
int i = 0;
while (i < Bars) {
if (Time <= LastBarTime) {
break;
}
i++;
}
if (Time != LastBarTime) {
//this should only happen when client change server.
if (Debug) Alert("corrupted data or server changed, reinitialize");
reinit();
return (-1);
}
//update history file with new data
WriteHistoryFile(i);
//refresh chart window
UpdateChartWindow();
return(0);
}
韬客社区www.talkfx.co
发表于:2005-11-30 00:57只看该作者
9楼
好的
遇到矛盾 先站在对方的立场上想想问题,先试着去理解别人
● 如何使用WinMTR查询平台连接流畅度
发表于:2005-11-30 02:12只看该作者
10楼
怎么加进去!请版主赐教!
韬客社区www.talkfx.co
发表于:2005-11-30 05:06只看该作者
11楼
原帖由 chenai 于 2005-11-30 10:12 发表 怎么加进去!请版主赐教!
冷静观察、稳住阵脚、沉着应付、韬光养晦、有所作为、决不当头。
发表于:2005-11-30 07:41只看该作者
12楼
发表于:2005-11-30 08:21只看该作者
13楼
楼主真强!!!!!!!!!!!!!
向您致敬!!!!!!!!!!!!!
谢谢!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!:handshake
韬客社区www.talkfx.co
发表于:2005-12-01 03:42只看该作者
15楼
啊,实在是无限感谢wfy05兄啊,wfy05兄连续两个的创新发明,完全解决了我一直来非常渴望的功能,真不知道该怎样表达俺的感激之情哪,呵呵。非常感谢啊。太感谢了。
韬客社区www.talkfx.co
发表于:2005-12-01 05:18只看该作者
16楼
wfy05,请问为什么我按照这样的步骤操作;结果zhouqi不是出现在“智能交易”就出现在“脚本”里 1.终端打开----自定义指标右键----点击创建(稍候)----出现MetaEditor背景,Expert Advisor Wizard 对话框.
2.Expart Advisor Wizard对话框点击下一步,在Name键入名字,比如zhouqi----点击下一步.点击完成.
3.删除左上部编辑器里的所有内容,把搂主的东东复制到上面----点击按钮Compile----关闭MetaEditor ------关闭MT4,重新打开.
等待回复????
发表于:2005-12-01 06:01只看该作者
17楼
原帖由 上海环球油轮 于 2005-12-1 13:18 发表 wfy05,请问为什么我按照这样的步骤操作;结果zhouqi不是出现在“智能交易”就出现在“脚本”里 1.终端打开----自定义指标右键----点击创建(稍候)----出现MetaEditor背景,Expert Advisor Wizard 对话框. 2.Expar ...
韬客社区www.talkfx.co
发表于:2005-12-01 06:18只看该作者
18楼
原帖由 Zukunft 于 2005-12-1 14:01 发表
发表于:2005-12-01 12:46只看该作者
19楼
十分欣赏楼主的专业知识和乐于助人的态度,谢谢
韬客社区www.talkfx.co
发表于:2005-12-01 15:31只看该作者
20楼
楼主,H4的图表数据很全,而制出H8的数据不全,则该如何制全H8的数据???
韬客外汇论坛TALKFOREX.COM