编码帮助 - 页 262

 

嗨,mladen。

我想我是疯了,这是我从PeriodConverter中修改的代码。

//+------------------------------------------------------------------+

//| PeriodConverter.mq4 |

//| Copyright 2006-2014, MetaQuotes Software Corp. |

//| http://www.metaquotes.net |

//+------------------------------------------------------------------+

#property copyright "2006-2014, MetaQuotes Software Corp."

#property link "http://www.mql4.com"

#property description "Period Converter to updated format of history base"

#property strict

#property show_inputs

#include

input int StartHour = 9;

input int StartMinute = 0;

input int CloseHour = 17;

input int CloseMinute = 30;

int ExtHandle=-1;

//+------------------------------------------------------------------+

//| script program start function |

//+------------------------------------------------------------------+

void OnStart()

{

datetime time0;

ulong last_fpos=0;

long last_volume=0;

int i,start_pos;

int hwnd=0,cnt=0;

//---- History header

int file_version=401;

string c_copyright;

string c_symbol=Symbol();

int i_period=Period();

int i_digits=Digits;

int i_unused[13];

MqlRates rate;

//---

ExtHandle=FileOpenHistory("TT_"+c_symbol+(string)i_period+".hst",FILE_BIN|FILE_WRITE|FILE_SHARE_WRITE|FILE_SHARE_READ|FILE_ANSI);

if(ExtHandle<0)

return;

c_copyright="(C)opyright 2003, MetaQuotes Software Corp.";

ArrayInitialize(i_unused,0);

//--- write history file header

FileWriteInteger(ExtHandle,file_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);

FileWriteInteger(ExtHandle,0,LONG_VALUE);

FileWriteArray(ExtHandle,i_unused,0,13);

//--- write history file

start_pos=Bars-1;

rate.open=Open[start_pos];

rate.low=Low[start_pos];

rate.high=High[start_pos];

rate.tick_volume=(long)Volume[start_pos];

rate.spread=0;

rate.real_volume=0;

//--- normalize open time

rate.time=Time[start_pos];

for(i=start_pos-1; i>=0; i--)

{

if(IsStopped())

break;

time0=Time;

//--- history may be updated

if(i==0)

{

//--- modify index if history was updated

if(RefreshRates())

i=iBarShift(NULL,0,time0);

}

//---

if((time0>=rate.time || i==0) && MainTime(time0)==true)

{

if(i==0)

{

rate.tick_volume+=(long)Volume[0];

if(rate.low>Low[0])

rate.low=Low[0];

if(rate.high<High[0])

rate.high=High[0];

rate.close=Close[0];

}

last_fpos=FileTell(ExtHandle);

last_volume=(long)Volume;

FileWriteStruct(ExtHandle,rate);

cnt++;

if(time0>=rate.time)

{

rate.time=time0;

rate.open=Open;

rate.low=Low;

rate.high=High;

rate.close=Close;

rate.tick_volume=last_volume;

}

}

else if(MainTime(time0)==true)

{

rate.tick_volume+=(long)Volume;

if(rate.low>Low)

rate.low=Low;

if(rate.high<High)

rate.high=High;

rate.close=Close;

}

}

FileFlush(ExtHandle);

Print(cnt," record(s) written");

//--- collect incoming ticks

datetime last_time=LocalTime()-5;

while(!IsStopped())

{

datetime cur_time=LocalTime();

//--- check for new rates

if(RefreshRates())

{

time0=Time[0];

FileSeek(ExtHandle,last_fpos,SEEK_SET);

//--- is there current bar?

if(time0<rate.time && MainTime(time0)==true)

{

rate.tick_volume+=(long)Volume[0]-last_volume;

last_volume=(long)Volume[0];

if(rate.low>Low[0])

rate.low=Low[0];

if(rate.high<High[0])

rate.high=High[0];

rate.close=Close[0];

}

else if(MainTime(time0)==true)

{

//--- no, there is new bar

rate.tick_volume+=(long)Volume[1]-last_volume;

if(rate.low>Low[1])

rate.low=Low[1];

if(rate.high<High[1])

rate.high=High[1];

//--- write previous bar remains

FileWriteStruct(ExtHandle,rate);

last_fpos=FileTell(ExtHandle);

//----

rate.time=time0;

rate.open=Open[0];

rate.low=Low[0];

rate.high=High[0];

rate.close=Close[0];

rate.tick_volume=(long)Volume[0];

last_volume=rate.tick_volume;

}

//----

FileWriteStruct(ExtHandle,rate);

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);

}

//---

}

//+------------------------------------------------------------------+

//| |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

{

//---

if(ExtHandle>=0)

{

FileClose(ExtHandle);

ExtHandle=-1;

}

//---

}

//+------------------------------------------------------------------+

bool MainTime(datetime time0)

{

datetime temp = time0 - 1 * 60 *60;

if(((TimeHour(temp) == StartHour && TimeMinute(temp) >= StartMinute) ||

TimeHour(temp) > StartHour) &&

(TimeHour(temp)< CloseHour ||

(TimeHour(temp) == CloseHour && TimeMinute(temp) < CloseMinute)))

{

Print(".......return (true) - Time0 = "+TimeToString(time0) + " tempTime = "+TimeToString(temp));

return(true);

}

else

{

Print("+++++++false - Time0 = "+TimeToString(time0) + " tempTime = "+TimeToString(temp));

return(false);

}

}

我添加了函数 MainTime来选择我想在我的新离线图表中显示的条形。

(我还将时间移动了一个小时,但这并不重要)。

现在,当我在一个有15046条(M5)的图表上测试这个功能时,从0:00(开始时间)到12:00(结束时间)的时间

我得到了正确的打印信息,并在最后得到了7596条的信息。

因此,它大约是原始图表的一半,所以我认为一切工作都很好!但是当我打开相应的离线图表时,我发现它已经被写入。

但是当我打开相应的离线图表时,它看起来与原始图表中的所有条形完全一样。

我真的无法理解这种行为!!!?

 
sunshineh:
嗨,mladen。

我想我要疯了,这是我从PeriodConverter中修改的代码。

//+------------------------------------------------------------------+

//| PeriodConverter.mq4 |

//| Copyright 2006-2014, MetaQuotes Software Corp. |

//| http://www.metaquotes.net |

//+------------------------------------------------------------------+

#property copyright "2006-2014, MetaQuotes Software Corp."

#property link "http://www.mql4.com"

#property description "Period Converter to updated format of history base"

#property strict

#property show_inputs

#include

input int StartHour = 9;

input int StartMinute = 0;

input int CloseHour = 17;

input int CloseMinute = 30;

int ExtHandle=-1;

//+------------------------------------------------------------------+

//| script program start function |

//+------------------------------------------------------------------+

void OnStart()

{

datetime time0;

ulong last_fpos=0;

long last_volume=0;

int i,start_pos;

int hwnd=0,cnt=0;

//---- History header

int file_version=401;

string c_copyright;

string c_symbol=Symbol();

int i_period=Period();

int i_digits=Digits;

int i_unused[13];

MqlRates rate;

//---

ExtHandle=FileOpenHistory("TT_"+c_symbol+(string)i_period+".hst",FILE_BIN|FILE_WRITE|FILE_SHARE_WRITE|FILE_SHARE_READ|FILE_ANSI);

if(ExtHandle<0)

return;

c_copyright="(C)opyright 2003, MetaQuotes Software Corp.";

ArrayInitialize(i_unused,0);

//--- write history file header

FileWriteInteger(ExtHandle,file_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);

FileWriteInteger(ExtHandle,0,LONG_VALUE);

FileWriteArray(ExtHandle,i_unused,0,13);

//--- write history file

start_pos=Bars-1;

rate.open=Open[start_pos];

rate.low=Low[start_pos];

rate.high=High[start_pos];

rate.tick_volume=(long)Volume[start_pos];

rate.spread=0;

rate.real_volume=0;

//--- normalize open time

rate.time=Time[start_pos];

for(i=start_pos-1; i>=0; i--)

{

if(IsStopped())

break;

time0=Time;

//--- history may be updated

if(i==0)

{

//--- modify index if history was updated

if(RefreshRates())

i=iBarShift(NULL,0,time0);

}

//---

if((time0>=rate.time || i==0) && MainTime(time0)==true)

{

if(i==0)

{

rate.tick_volume+=(long)Volume[0];

if(rate.low>Low[0])

rate.low=Low[0];

if(rate.high<High[0])

rate.high=High[0];

rate.close=Close[0];

}

last_fpos=FileTell(ExtHandle);

last_volume=(long)Volume;

FileWriteStruct(ExtHandle,rate);

cnt++;

if(time0>=rate.time)

{

rate.time=time0;

rate.open=Open;

rate.low=Low;

rate.high=High;

rate.close=Close;

rate.tick_volume=last_volume;

}

}

else if(MainTime(time0)==true)

{

rate.tick_volume+=(long)Volume;

if(rate.low>Low)

rate.low=Low;

if(rate.high<High)

rate.high=High;

rate.close=Close;

}

}

FileFlush(ExtHandle);

Print(cnt," record(s) written");

//--- collect incoming ticks

datetime last_time=LocalTime()-5;

while(!IsStopped())

{

datetime cur_time=LocalTime();

//--- check for new rates

if(RefreshRates())

{

time0=Time[0];

FileSeek(ExtHandle,last_fpos,SEEK_SET);

//--- is there current bar?

if(time0<rate.time && MainTime(time0)==true)

{

rate.tick_volume+=(long)Volume[0]-last_volume;

last_volume=(long)Volume[0];

if(rate.low>Low[0])

rate.low=Low[0];

if(rate.high<High[0])

rate.high=High[0];

rate.close=Close[0];

}

else if(MainTime(time0)==true)

{

//--- no, there is new bar

rate.tick_volume+=(long)Volume[1]-last_volume;

if(rate.low>Low[1])

rate.low=Low[1];

if(rate.high<High[1])

rate.high=High[1];

//--- write previous bar remains

FileWriteStruct(ExtHandle,rate);

last_fpos=FileTell(ExtHandle);

//----

rate.time=time0;

rate.open=Open[0];

rate.low=Low[0];

rate.high=High[0];

rate.close=Close[0];

rate.tick_volume=(long)Volume[0];

last_volume=rate.tick_volume;

}

//----

FileWriteStruct(ExtHandle,rate);

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);

}

//---

}

//+------------------------------------------------------------------+

//| |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

{

//---

if(ExtHandle>=0)

{

FileClose(ExtHandle);

ExtHandle=-1;

}

//---

}

//+------------------------------------------------------------------+

bool MainTime(datetime time0)

{

datetime temp = time0 - 1 * 60 *60;

if(((TimeHour(temp) == StartHour && TimeMinute(temp) >= StartMinute) ||

TimeHour(temp) > StartHour) &&

(TimeHour(temp)< CloseHour ||

(TimeHour(temp) == CloseHour && TimeMinute(temp) < CloseMinute)))

{

Print(".......return (true) - Time0 = "+TimeToString(time0) + " tempTime = "+TimeToString(temp));

return(true);

}

else

{

Print("+++++++false - Time0 = "+TimeToString(time0) + " tempTime = "+TimeToString(temp));

return(false);

}

}

我添加了函数MainTime来选择我想在我的新离线图表中显示的条形。

(我还将时间移动了一个小时,但这并不重要)。

现在,当我在一个有15046条(M5)的图表上测试这个功能时,从0:00(开始时间)到12:00(结束时间)的时间

我得到了正确的打印信息,并在最后得到了7596条的信息。

因此,它大约是原始图表的一半,所以我认为一切工作都很好!但是当我打开相应的离线图表时,我发现它已经被写入。

但是当我打开相应的离线图表时,它看起来与原始图表的所有条形完全一样。

我真的无法理解这种行为。

这是因为你使用的是符号的原始名称和时间框架。你必须改变符号名称或时间框架(最好是改变时间框架,这样你的所有代码就能识别正确的符号名称)。

如果你改变时间框架,确保你不使用一些 "合法 "的时间框架(1,5,15,30,60,...)。

 

你好。

这个EA是用来和其他EA结合进行股权保护的。您可以输入股权的盈亏限额,当限额被击中时,EA将关闭所有订单并关闭其他EA。

ea股权保护的问题是,它只在mt4最大化的情况下工作。如果它被最小化或MT4在VPS上 运行,当限额被击中时,EA将不会开始关闭订单,直到我最大化EA或在VPS上登录。当我登录或最大化时,EA开始平仓。

谢谢。

附加的文件:
 
DarkForex33:
你好

该EA用于与其他EA结合进行股权保护。你可以输入股权的利润和损失限制,当限制被击中时,EA将关闭所有订单并关闭其他EA。

ea股权保护的问题是,它只在mt4最大化的情况下工作。如果它被最小化或MT4在VPS上运行,当限额被击中时,EA将不会开始关闭订单,直到我最大化EA或在VPS上登录。当我登录或最大化时,EA开始平仓。

谢谢。

在您的电脑上(不是VPS)是否有同样的表现?

如果在相同条件下,它在您的电脑上工作正常,那么您的VPS 就有问题了。

 
mladen:
这是因为你使用的是符号的原始名称和时间框架。你必须改变符号名称或时间框架(最好是改变时间框架,这样你所有的代码都能识别正确的符号名称)如果你改变时间框架,确保你不使用一些 "合法 "的时间框架(1、5、15、30、60,...)。

谢谢,我已经改变了

ExtHandle=FileOpenHistory("TT_"+c_symbol+(string)3+".hst",FILE_BIN|FILE_WRITE|FILE_SHARE_WRITE|FILE_SHARE_READ|FILE_ANSI);

and

FileWriteInteger(ExtHandle,3,LONG_VALUE);

但如果我打开离线图表......,M3只显示 "等待更新"......而没有任何反应。

 
sunshineh:
谢谢,我已经改了

ExtHandle=FileOpenHistory("TT_"+c_symbol+(string)3+".hst",FILE_BIN|FILE_WRITE|FILE_SHARE_WRITE|FILE_SHARE_READ|FILE_ANSI);

and

FileWriteInteger(ExtHandle,3,LONG_VALUE);

但如果我打开离线图表......,M3只显示 "等待更新"......什么也没有发生

有趣的是

用这个作为你的指标的基础。这个是有效的(看来你用作基础的版本有错误)。

附加的文件:
 

帮助我!为这一行动

问候语

请专家们

在EA中设置止损和止盈

gaps.ex4

gaps.mq4

附加的文件:
gaps.ex4  6 kb
gaps.mq4  4 kb
 

你好。

你能帮助在附件中的指标中增加一个DEMA 选项吗?

目前的选项是。

0=SMA

1=EMA

2=smma

3=LWMA

希望增加。

4=DEMAI 这可能吗?非常感谢您!

 
MrWigglesworth:
你好。

你能帮助在所附的指标中增加一个DEMA选项吗?

目前的选项是。

0=SMA

1=EMA

2=smma

3=LWMA

想添加。

4= DEMAI 这可能吗?非常感谢您!

MrWigglesworth

这里有一个添加了Dema作为类型4的版本:ma__dema_crossover_with_arrow_and_email.mq4

 
amirreza132:
问候语

请专家们

在EA中设置止损和止盈

gaps.ex4

差距.mq4

amirreza132

该EA是为捕捉缺口而设计的,当缺口发生时,它已经有了止盈。