MQL4 时间函数计算错误
我有以下函数,尝试计算最后一次平仓交易与当前时间之间的时间。如果时间差是<>一定数量的柱会给出不同的结果。
话虽这么说,在回测期间的某个时刻,柱计算开始失败,我没有发现错误。有什么想法吗?
int LastOrderTicket()
{
datetime TicketTime = 0;
int LastOT;
datetime
Timeorder = LastOrderTime(),
Timeahora = TimeCurrent(),
Times = Timeahora - Timeorder;
int
m = TimeMinute(Times),
h = TimeHour(Times),
d = TimeDay(Times),
bars = (((d - 1) * 24 * 60) + (h * 60) + m) / 240;
for(int ix = 0; ix < OrdersHistoryTotal(); ix++)
{
if(OrderSelect(ix, SELECT_BY_POS, MODE_HISTORY)
&& OrderMagicNumber() == MagicNumber
&& OrderSymbol() == Symbol())
{
if(bars > barsback)
{
LastOT = -1;
}
else
{
if(bars < barsback)
{
LastOT = OrderType(); //For testing
}
}
}
else
Print("OrderSelect returned the error of ",GetLastError());
}
Print("TicketN ",LastOT);
Print("bars ",bars);
Print("Timeorder=",TimeToStr(Timeorder, TIME_MINUTES|TIME_SECONDS|TIME_DATE));
Print("Timeahora=",TimeToStr(Timeahora, TIME_MINUTES|TIME_SECONDS|TIME_DATE));
Print("Times=",TimeToStr(Times, TIME_MINUTES|TIME_SECONDS|TIME_DATE));
Print("m ",m);
Print("h ",h);
Print("d ",d);
return(LastOT); // Buy==0, Sell==1, Others==2 through 5
}
在这里我发现了错误:
0 18:02:11.243 2021.08.06 23:59:59 BBReverse V1 EURUSD,H4: bars 182
0 18:02:11.243 2021.08.06 23:59:59 BBReverse V1 EURUSD,H4: Timeorder=2021.03.09 12:00:00
0 18:02:11.243 2021.08.06 23:59:59 BBReverse V1 EURUSD,H4: Timeahora=2021.08.06 23:59:59
0 18:02:11.243 2021.08.06 23:59:59 BBReverse V1 EURUSD,H4: Times=1970.05.31 11:59:59
0 18:02:11.243 2021.08.06 23:59:59 BBReverse V1 EURUSD,H4: m 59
0 18:02:11.243 2021.08.06 23:59:59 BBReverse V1 EURUSD,H4: h 11
**0 18:02:11.243 2021.08.06 23:59:59 BBReverse V1 EURUSD,H4: d 31**
0 18:02:11.243 2021.08.08 23:05:00 BBReverse V1 EURUSD,H4: bars 8
0 18:02:11.243 2021.08.08 23:05:00 BBReverse V1 EURUSD,H4: Timeorder=2021.03.09 12:00:00
0 18:02:11.243 2021.08.08 23:05:00 BBReverse V1 EURUSD,H4: Timeahora=2021.08.08 23:05:00
0 18:02:11.243 2021.08.08 23:05:00 BBReverse V1 EURUSD,H4: Times=1970.06.02 11:05:00
0 18:02:11.243 2021.08.08 23:05:00 BBReverse V1 EURUSD,H4: m 5
0 18:02:11.243 2021.08.08 23:05:00 BBReverse V1 EURUSD,H4: h 11
**0 18:02:11.243 2021.08.08 23:05:00 BBReverse V1 EURUSD,H4: d 2**
函数时间不断总结,但日期值没有......
谢谢。
I have the following function where tries to calculate the time between the last closed trade and the current time. if the time difference is <> that a certain number of bars it gives a different result.
that being said, during the backtest at some point the bar calculation begins to fail and i do not find the error. Any thoughts?
int LastOrderTicket()
{
datetime TicketTime = 0;
int LastOT;
datetime
Timeorder = LastOrderTime(),
Timeahora = TimeCurrent(),
Times = Timeahora - Timeorder;
int
m = TimeMinute(Times),
h = TimeHour(Times),
d = TimeDay(Times),
bars = (((d - 1) * 24 * 60) + (h * 60) + m) / 240;
for(int ix = 0; ix < OrdersHistoryTotal(); ix++)
{
if(OrderSelect(ix, SELECT_BY_POS, MODE_HISTORY)
&& OrderMagicNumber() == MagicNumber
&& OrderSymbol() == Symbol())
{
if(bars > barsback)
{
LastOT = -1;
}
else
{
if(bars < barsback)
{
LastOT = OrderType(); //For testing
}
}
}
else
Print("OrderSelect returned the error of ",GetLastError());
}
Print("TicketN ",LastOT);
Print("bars ",bars);
Print("Timeorder=",TimeToStr(Timeorder, TIME_MINUTES|TIME_SECONDS|TIME_DATE));
Print("Timeahora=",TimeToStr(Timeahora, TIME_MINUTES|TIME_SECONDS|TIME_DATE));
Print("Times=",TimeToStr(Times, TIME_MINUTES|TIME_SECONDS|TIME_DATE));
Print("m ",m);
Print("h ",h);
Print("d ",d);
return(LastOT); // Buy==0, Sell==1, Others==2 through 5
}
Here where i find the error:
0 18:02:11.243 2021.08.06 23:59:59 BBReverse V1 EURUSD,H4: bars 182
0 18:02:11.243 2021.08.06 23:59:59 BBReverse V1 EURUSD,H4: Timeorder=2021.03.09 12:00:00
0 18:02:11.243 2021.08.06 23:59:59 BBReverse V1 EURUSD,H4: Timeahora=2021.08.06 23:59:59
0 18:02:11.243 2021.08.06 23:59:59 BBReverse V1 EURUSD,H4: Times=1970.05.31 11:59:59
0 18:02:11.243 2021.08.06 23:59:59 BBReverse V1 EURUSD,H4: m 59
0 18:02:11.243 2021.08.06 23:59:59 BBReverse V1 EURUSD,H4: h 11
**0 18:02:11.243 2021.08.06 23:59:59 BBReverse V1 EURUSD,H4: d 31**
0 18:02:11.243 2021.08.08 23:05:00 BBReverse V1 EURUSD,H4: bars 8
0 18:02:11.243 2021.08.08 23:05:00 BBReverse V1 EURUSD,H4: Timeorder=2021.03.09 12:00:00
0 18:02:11.243 2021.08.08 23:05:00 BBReverse V1 EURUSD,H4: Timeahora=2021.08.08 23:05:00
0 18:02:11.243 2021.08.08 23:05:00 BBReverse V1 EURUSD,H4: Times=1970.06.02 11:05:00
0 18:02:11.243 2021.08.08 23:05:00 BBReverse V1 EURUSD,H4: m 5
0 18:02:11.243 2021.08.08 23:05:00 BBReverse V1 EURUSD,H4: h 11
**0 18:02:11.243 2021.08.08 23:05:00 BBReverse V1 EURUSD,H4: d 2**
the function time keep summing up but the day value not...
thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我使用过ibarshif并且它有效。
不管怎样,谢谢你。
i've used ibarshif and it worked.
thank you anyway.