Download MetaTrader 5

How to check TimeMinute(Time[0]) = 30 at TF-H4 ? - page 2

To add comments, please log in or register
Hongliang Liu
1269
Hongliang Liu  

when i want to send report for each hour,i do like this:

reporthour:record which hour has been sent,to avoid send again.

if you want to handle at 01:31,07:31...just use (31 == TimeMinute(nowtime)) instead.

    datetime nowtime = TimeCurrent();
    //send hour report
    if((reporthour != TimeHour(nowtime)) && (0 == TimeMinute(nowtime)) && (OrdersTotal() > 0))//do something
    {
    }
whroeder1
15577
whroeder1  
Moggy: i want to send report for each hour,i do like this:
   datetime nowtime = TimeCurrent();
    //send hour report
    if((reporthour != TimeHour(nowtime)) && (0 == TimeMinute(nowtime)) && (OrdersTotal() > 0))//do something

And if there is no tick at the top of the hour during the first minute, your code fails. It also fails over the weekend.
Just typed. Not compiled.
bool isReportTime(){
   static datetime nextReportTime;
   datetime   now = TimeCurrent();
   bool     isNow = now >= nextReportTime;
   if(isNow){
      nextReportTime  = now + 3600;             // Next hour
      nextReportTime -= nextReportTime % 3600;  // Top of the hour
   return isNow;
}
Oninit(){ isReportTime(); ... }
Onstart(){
   if( isReportTime() && (OrdersTotal() > 0))//do something
Just typed. Not compiled.
sorasit
359
sorasit  
WHRoeder:
sorasit46: That's real.And that is my question .

When run backtest on TF-H4. How to check TimeMinute(Time[0]) = 30,31.... (Etc.) ?

  1. Then why didn't you ask that in the first place?
  2. You don't want to use Time[0] because it isn't changing for the entire H4.
  3. RTM Minute() See Alphabetic Index of MQL4 Functions (600+) - MQL4 forum

Sorry ! My language very weak.

But thanks for the tip.

Hongliang Liu
1269
Hongliang Liu  
WHRoeder:

And if there is no tick at the top of the hour during the first minute, your code fails. It also fails over the weekend.
Just typed. Not compiled.
Just typed. Not compiled.

 thanks for your ideas~ 

 if there is no tick at the top of the hour during the first minute

easy to improve,just changed to 10 >= TimeMinute(nowtime),not enough? 59 >= TimeMinute(nowtime) ~~~~

in fact,if the symbols has no tick in one minute,no need to run EA on it anymore~,my EA is running normally for months now.

datetime nowtime = TimeCurrent();
    //send hour report
    if((reporthour != TimeHour(nowtime)) && (10 >= TimeMinute(nowtime)) && (OrdersTotal() > 0))//do something

It also fails over the weekend

 when the market is closed in weekend,there in no tick to drive onStart() and the EA is closed.i don't think it's a problem.

 

 thanks again~

whroeder1
15577
whroeder1  

Moggy:

when the market is closed in weekend,there in no tick to drive onStart() and the EA is closed.i don't think it's a problem.

easy to improve,just changed to 10 >= TimeMinute(nowtime),not enough?

59 >= TimeMinute(nowtime) ~~~~

  1. You missed the point. If you want to send a report at the top of the hour, it may not on market open.

    Market closed at 04:59 ET Friday - no report sent, not top of the hour.

    Market opens at 18:00 ET Sunday - no tick for the first minute, no report sent.

    Either you want a report sent at the top of the hour, every hour or you don't. Your code does the latter.

  2. Sure, now a glitch brings your network down for ten minutes, no report sent after reconnection.
  3. Sure, but how are you stopping it. You don't want it to report 59 times an hour. Your code is only half a solution. My now > next is complete.
12
To add comments, please log in or register