[ARCHIVE]Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Can't go anywhere without you - 5. - page 98

 

Kim has a function:

//+------------------------------------------------------------------+
//|  Описание : Возвращает флаг разрешения торговли по времени.                |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    hb - часы времени начала торговли                                       |
//|    mb - минуты времени начала торговли                                     |
//|    he - часы времени окончания торговли                                    |
//|    me - минуты времени окончания торговли                                  |
//+----------------------------------------------------------------------------+
bool isTradeTimeInt(int hb=0, int mb=0, int he=0, int me=0) {
  datetime db, de;           // Время начала и окончания работы
  int      hc;               // Часы текущего времени торгового сервера

  db=StrToTime(TimeToStr(TimeCurrent(), TIME_DATE)+" "+hb+":"+mb);
  de=StrToTime(TimeToStr(TimeCurrent(), TIME_DATE)+" "+he+":"+me);
  hc=TimeHour(TimeCurrent());
  if (db>=de) {
    if (hc>=he) de+=24*60*60; else db-=24*60*60;
  }

  if (TimeCurrent()>=db && TimeCurrent()<=de) return(True);
  else return(False);
} 

I have two questions:

1. Why does it translate the time to a string at once and then the string to a time?

2. Why this condition in the function?

  if (db>=de) {
    if (hc>=he) de+=24*60*60; else db-=24*60*60;
  }

Because checking the time below... Right here:

if (TimeCurrent()>=db && TimeCurrent()<=de) return(True);
  else return(False);

And in function parameters, time variables are not of datetime type, but int for some reason...

 
Ha, I figured it out. The thing is, the file I was working on editing was opened from a flash drive yesterday. The text is open, everything is fine, but I haven't plugged in the flash drive today. I don't understand what I want to compile, I have text, but I just don't have access to it for editing. Man, it happens.
 
hoz:

Kim has a function:

I have two questions:

1. Why does it translate the time to a string at once and then the string to a time?

2. Why this condition in the function?

Because checking the time below... Right here:

And in function parameters, time variables are not of datetime type, but int for some reason...


1. To replace the current hour and minute values in the time with the values specified in the function parameters

I would do it like this:

db=TimeCurrent()-TimeCurrent()%86400+hb*3600+mb*60;

2. To additionally correct start or end dates by day

datetime and int are essentially the same thing, and the parameters are not full dates, but only the number of hours and minutes

 
MikeM:


2. For additional correction of start or end dates by day

Why? We need to limit the trading time of the EA. And we are not interested in the time from the hour when the trading time ends to the hour when the trading time starts, because the EA does not trade at that time! I don't understand what NONSENSES are...

MikeM:

The datetime and int are essentially the same thing, and the parameters are not the full dates, but only the number of hours and minutes

But time must be time, how is there no difference?
 
hoz:


But time must be time, how can there be no difference?


Time is a number, and a whole number at that.
 
Vinin:

Time is a number, and it's an integer.


I understand what I mean with time - it's not a date, that's why it is declared as a number. But what about:

  if (db>=de) {
    if (hc>=he) de+=24*60*60; else db-=24*60*60;
  }

As many variants as I've seen, I've never seen anything like this... It is somehow strange. Moreover, there is no cycle here, and minus and plus the time of the beginning and the end of trade. I do not understand this point.

In fact, we got the start and end times of db and de trade above. So, this piece may be erased, and then we will check the time:

  if (TimeCurrent()>=db && TimeCurrent()<=de) return(True);
  else return(False);

What is the point of writing extra code? Please explain this point. It's actually not logical.

 
hoz:


If we don't use minutes, we may simplify it. I understand what we mean with time - it's not date, we declare date. What about:

As many variants as I've seen, I've never seen anything like this... It's strange somehow. Moreover, there is no cycle here, and minus and plus the time of the beginning and the end of trade. I do not understand this point.

In fact, we got the start and end times of db and de trade above. So, this piece may be erased, and then we will check the time:

What is the point of writing extra code? Please explain this point. It's not really logical.


Everyone is free to do his own thing. Igor did it this way. I do it differently.

And whether you get a plus or minus. So, it depends on the time of trading. For example, how to arrange trading from 21 hours to 5 hours.

If the minutes were not used, everything would be much simpler.

 
Vinin:


Everyone is free to do it his own way. Igor did it this way. I am doing things differently.

And whether it's plus or minus. So it depends on the time of trading. For example, how to organise trading between 9 p.m. and 5 a.m.

And the code is redundant. It does not matter.

If the minutes were not used, everything would be much simpler.


Make the trading time be from 21.00 to 23.59, and then from 00.01 to 5.00

Are there any other options?

 
hoz:


Make the trading hours 21.00 to 23.59 and then 00.01 to 5.00

Are there other options?

If you write if(Hour() >= 21 || Hour() < 5) it will be from 21.00 to 4.59.
 
borilunad:
If you write if(Hour() >= 21 || Hour() < 5) it will be from 21.00 to 4.59.

That's weird. It skips past midnight and doesn't take that into account at all?
Reason: