DxdCn老师: 你好!如何指定10秒前的价格?

 
如何指定10秒前的价格?
 

指定? 10秒前? ASK BID 是服务器提供的,,只有当前的, 历史tick数据没有提供存储功能, 除非你自己编程记录, 但不一定刚好是10秒的,因为即时价格不是等时间间隔的.

解决办法: 自己编程不断记录最近的ASK, BID数据和对应的时间.

 
DxdCn 写道 >>

指定? 10秒前? ASK BID 是服务器提供的,,只有当前的, 历史tick数据没有提供存储功能, 除非你自己编程记录, 但不一定刚好是10秒的,因为即时价格不是等时间间隔的.

解决办法: 自己编程不断记录最近的ASK, BID数据和对应的时间.

DxdCn老师: 下面的程序可以记录吗?

double price[1];

for(i=0;i<2;i++)
{
if(TimeCurrent()==Time[0]+i*10) price[i]=MarketInfo(Symbol(),MODE_ASK);
Print("--",MathAbs(price[0]-price[1]));
}

 

不能,因为 if(TimeCurrent()==Time[0]+i*10) 无法成立!! TimeCurrent() 永远是现在时间,不可能等于过去时间。

大致如下,未经调试。

double price[100];

datatime ttime[100];

int num=0;

start()

{

if (num==99) for (int i=1;i<100;i++) { price[i-1]= price[i]; ttime[i-1]= ttime[i];} //记录ticks 价格队列

price[num]=MarketInfo(Symbol(),MODE_ASK);

ttime[num]= TimeCurrent();

int fnum=num;

numm++;

double fppp =0;

bool doit = true;

while (doit || (fnum =>0))

{

fnum--;

if(ttime[fnum] < TimeCurrent() - i*10) doit = false;

}

if ( doit == false) Print("--before 10 seconds, p= ", price[fnum],TimeToStr(ttime[fnum],TIME_DATE|TIME_SECONDS));

else Print("-- price array too small to record data inside 10 seconds", TimeToStr(ttime[fnum],TIME_DATE|TIME_SECONDS),

TimeToStr(ttime[num-1],TIME_DATE|TIME_SECONDS)) ;
);

...........................................

}

 
DxdCn 写道 >>

不能,因为 if(TimeCurrent()==Time[0]+i*10) 无法成立!! TimeCurrent() 永远是现在时间,不可能等于过去时间。

大致如下,未经调试。

double price[100];

datatime ttime[100];

int num=0;

start()

{

if (num==99) for (int i=1;i<100;i++) { price[i-1]= price[i]; ttime[i-1]= ttime[i];} //记录ticks 价格队列

price[num]=MarketInfo(Symbol(),MODE_ASK);

ttime[num]= TimeCurrent();

int fnum=num;

numm++;

double fppp =0;

bool doit = true;

while (doit || (fnum =>0))

{

fnum--;

if(ttime[fnum] < TimeCurrent() - i*10) doit = false;

}

if ( doit == false) Print("--before 10 seconds, p= ", price[fnum],TimeToStr(ttime[fnum],TIME_DATE|TIME_SECONDS));

else Print("-- price array too small to record data inside 10 seconds", TimeToStr(ttime[fnum],TIME_DATE|TIME_SECONDS),

TimeToStr(ttime[num-1],TIME_DATE|TIME_SECONDS)) ;
);

...........................................

}

______________________________________________________________________________________________________________________

______________________________________________________________________________________________________________________

DxdCn老师,那如何将下面的代号修改能成生成1秒时段实时图的代码?

//+------------------------------------------------------------------+
//| Period_Converter.mq4 |
//| Copyright ?2005-2007, MetaQuotes Software Corp. |
//| https://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2007, MetaQuotes Software Corp."
#property link "https://www.metaquotes.net/"
#property show_inputs
#include <WinUser32.mqh>

extern int ExtPeriodMultiplier=3; // new period multiplier factor
int ExtHandle=-1;
//+------------------------------------------------------------------+
//| script program start function |
//+------------------------------------------------------------------+
int start()
{
int i, start_pos, i_time, time0, last_fpos, periodseconds;
double d_open, d_low, d_high, d_close, d_volume, last_volume;
int hwnd=0,cnt=0;
//---- History header
int version=400;
string c_copyright;
string c_symbol=Symbol();
int i_period=Period()*ExtPeriodMultiplier;
int i_digits=Digits;
int i_unused[13];
//----
ExtHandle=FileOpenHistory(c_symbol+i_period+".hst", FILE_BIN|FILE_WRITE);
if(ExtHandle < 0) return(-1);
//---- write history file header
c_copyright="(C)opyright 2003, MetaQuotes Software Corp.";
FileWriteInteger(ExtHandle, version, LONG_VALUE);
FileWriteString(ExtHandle, c_copyright, 64);
FileWriteString(ExtHandle, c_symbol, 12);
FileWriteInteger(ExtHandle, i_period, LONG_VALUE);
FileWriteInteger(ExtHandle, i_digits, LONG_VALUE);
FileWriteInteger(ExtHandle, 0, LONG_VALUE); //timesign
FileWriteInteger(ExtHandle, 0, LONG_VALUE); //last_sync
FileWriteArray(ExtHandle, i_unused, 0, 13);
//---- write history file
periodseconds=i_period*60;
start_pos=Bars-1;
d_open=Open[start_pos];
d_low=Low[start_pos];
d_high=High[start_pos];
d_volume=Volume[start_pos];
//---- normalize open time
i_time=Time[start_pos]/periodseconds;
i_time*=periodseconds;
for(i=start_pos-1;i>=0; i--)
{
time0=Time[i];
//---- history may be updated
if(i==0)
{
//---- modify index if history was updated
if(RefreshRates())
i=iBarShift(NULL,0,time0);
}
//----
if(time0>=i_time+periodseconds || i==0)
{
if(i==0 && time0<i_time+periodseconds)
{
d_volume+=Volume[0];
if (Low[0]<d_low) d_low=Low[0];
if (High[0]>d_high) d_high=High[0];
d_close=Close[0];
}
last_fpos=FileTell(ExtHandle);
last_volume=Volume[i];
FileWriteInteger(ExtHandle, i_time, LONG_VALUE);
FileWriteDouble(ExtHandle, d_open, DOUBLE_VALUE);
FileWriteDouble(ExtHandle, d_low, DOUBLE_VALUE);
FileWriteDouble(ExtHandle, d_high, DOUBLE_VALUE);
FileWriteDouble(ExtHandle, d_close, DOUBLE_VALUE);
FileWriteDouble(ExtHandle, d_volume, DOUBLE_VALUE);
FileFlush(ExtHandle);
cnt++;
if(time0>=i_time+periodseconds)
{
i_time=time0/periodseconds;
i_time*=periodseconds;
d_open=Open[i];
d_low=Low[i];
d_high=High[i];
d_close=Close[i];
d_volume=last_volume;
}
}
else
{
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];
}
}
FileFlush(ExtHandle);
Print(cnt," record(s) written");
//---- collect incoming ticks
int last_time=LocalTime()-5;
while(IsStopped()==false)
{
int cur_time=LocalTime();
//---- check for new rates
if(RefreshRates())
{
time0=Time[0];
FileSeek(ExtHandle,last_fpos,SEEK_SET);
//---- is there current bar?
if(time0<i_time+periodseconds)
{
d_volume+=Volume[0]-last_volume;
last_volume=Volume[0];
if (Low[0]<d_low) d_low=Low[0];
if (High[0]>d_high) d_high=High[0];
d_close=Close[0];
}
else
{
//---- no, there is new bar
d_volume+=Volume[1]-last_volume;
if (Low[1]<d_low) d_low=Low[1];
if (High[1]>d_high) d_high=High[1];
//---- write previous bar remains
FileWriteInteger(ExtHandle, i_time, LONG_VALUE);
FileWriteDouble(ExtHandle, d_open, DOUBLE_VALUE);
FileWriteDouble(ExtHandle, d_low, DOUBLE_VALUE);
FileWriteDouble(ExtHandle, d_high, DOUBLE_VALUE);
FileWriteDouble(ExtHandle, d_close, DOUBLE_VALUE);
FileWriteDouble(ExtHandle, d_volume, DOUBLE_VALUE);
last_fpos=FileTell(ExtHandle);
//----
i_time=time0/periodseconds;
i_time*=periodseconds;
d_open=Open[0];
d_low=Low[0];
d_high=High[0];
d_close=Close[0];
d_volume=Volume[0];
last_volume=d_volume;
}
//----
FileWriteInteger(ExtHandle, i_time, LONG_VALUE);
FileWriteDouble(ExtHandle, d_open, DOUBLE_VALUE);
FileWriteDouble(ExtHandle, d_low, DOUBLE_VALUE);
FileWriteDouble(ExtHandle, d_high, DOUBLE_VALUE);
FileWriteDouble(ExtHandle, d_close, DOUBLE_VALUE);
FileWriteDouble(ExtHandle, d_volume, DOUBLE_VALUE);
FileFlush(ExtHandle);
//----
if(hwnd==0)
{
hwnd=WindowHandle(Symbol(),i_period);
if(hwnd!=0) Print("Chart window detected");
}
//---- refresh window not frequently than 1 time in 2 seconds
if(hwnd!=0 && cur_time-last_time>=2)
{
PostMessageA(hwnd,WM_COMMAND,33324,0);
last_time=cur_time;
}
}
Sleep(50);
}
//----
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void deinit()
{
if(ExtHandle>=0) { FileClose(ExtHandle); ExtHandle=-1; }
}
//+------------------------------------------------------------------+

 

1秒时段实时图?

MT没有提供1秒时段实时数据,当然无法绘制。 tick数据是不定时不等间隔的。

我已经向Rosh提交了收集tick数据做指标的文件,等他审核,发布后,你就可以在 代码基地 下的 指示器 即指标中, 下载tick数据指标了。

 
DxdCn 写道 >>

1秒时段实时图?

MT没有提供1秒时段实时数据,当然无法绘制。 tick数据是不定时不等间隔的。

我已经向Rosh提交了收集tick数据做指标的文件,等他审核,发布后,你就可以在 代码基地 下的 指示器 即指标中, 下载tick数据指标了。

原来这样,谢谢DxdCn老师!

 
DxdCn 写道 >>

1秒时段实时图?

MT没有提供1秒时段实时数据,当然无法绘制。 tick数据是不定时不等间隔的。

我已经向Rosh提交了收集tick数据做指标的文件,等他审核,发布后,你就可以在 代码基地 下的 指示器 即指标中, 下载tick数据指标了。

DxdCn老师,指标发布后,可以在论坛通知我吗?

 
DxdCn老师,你的联系方式是多少?
 
DxdCn老师,请教一下用MQL4语言编写计秒器该如何? sleep(1000)?
 

已经发布了, 点上面的 代码基地

'tick指标'

方式 代码里有。
sleep(1000) 函数最好不要使用。
有可能干扰MT运行。 一般也用不着。

原因: