MQL4 时间函数计算错误

发布于 2025-01-13 06:05:00 字数 2748 浏览 2 评论 0原文

我有以下函数,尝试计算最后一次平仓交易与当前时间之间的时间。如果时间差是<>一定数量的柱会给出不同的结果。

话虽这么说,在回测期间的某个时刻,柱计算开始失败,我没有发现错误。有什么想法吗?

 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

是你 2025-01-20 06:05:00

我使用过ibarshif并且它有效。

不管怎样,谢谢你。

i've used ibarshif and it worked.

thank you anyway.

趁微风不噪 2025-01-20 06:05:00
datetime lastTime = TimeCurrent()-OrderOpenTime();
datetime lastTime = TimeCurrent()-OrderOpenTime();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文