Errors, bugs, questions - page 2177

 
Konstantin Nikitin:

StringToTime

Thank you very much!
 
Maxim Khrolenko:
Much obliged!

Terribly slow and not optimal to handle string variable conversions.

You have the answer above:

Forum on trading, automated trading systems and trading strategy testing

Bugs, bugs, questions

Alexey Viktorov, 2018.03.30 19:30

Fill MqlDateTime structure and get full date and time from it.


 
Maxim Khrolenko:
Thank you very much!

We don't look for easy ways. Way to go...

 
Alexey Viktorov:

We are not looking for an easy way out. Way to go...

Write him a little example ;)

 
Alexey Viktorov:

Fill in the MqlDateTime structure and get the full date and time from it.

Interesting to see how it works in code

 
Artyom Trishkin:

Write him a little example ;)

It was said

Forum on trading, automated trading systems and trading strategy testing

Bugs, bugs, questions

Maxim Khrolenko, 2018.03.30 18:49

I can't find an answer to the question, how to write a time value corresponding to the given parameters into a variable of datetime type based on 6 variables of int type (year, month, day, hour, minute)? Then I need to find the index of the candle that opened at that time, but that's not a problem for me. If anyone has a link where you can find the answer, please, I'll figure it out on my own.

MqlDateTime dateTime;

dateTime.year = 2018;
dateTime.mon = 3;
dateTime.day = 30;
dateTime.hour = 21;
dateTime.min = 15;

datetime _Time = StructToTime(dateTime);
 
Alexey Viktorov:

It was said.


What day of the week does that make it? Have you checked? Just wondering if it calculates it by itself during the conversion or not.

Even these two: day_of_week and day_of_year

 
Artyom Trishkin:

What day of the week is it? Have you checked? I'm just wondering if it calculates it by itself during conversion or not.

Even these two: day_of_week and day_of_year.

If you put it back into the structure afterwards.

  TimeToStruct(_Time, dateTime);

it'll show up all right.

day_of_week = 5

day_of_year = 88

 
Artyom Trishkin:

What day of the week is it? Have you checked? Just curious if it calculates it by itself during conversion or not.

Even these two: day_of_week and day_of_year


void OnStart()
  {
//---
   MqlDateTime timeDate, time;
   
   timeDate.year=2018;
   timeDate.day_of_year=32;
   
   datetime date1=StructToTime(timeDate);
   Print("День года - ",timeDate.day_of_year);
   
   time.year=2018;
   time.mon=2;
   time.day=1;
   time.hour=0;
   time.min=0;
   
   datetime date2=StructToTime(time);
   Print("День года - ",time.day_of_year);
  }

День года - 879007969
День года - 32



It doesn't work when day_of_year is filled in (

 


A very strange pause of 22 seconds. Who can explain?

//+------------------------------------------------------------------+
//|                                                      BagBars.mq5 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+

void OnStart()
  {
   datetime Arr[];
   if(CopyTime(_Symbol,PERIOD_H4,0,1,Arr)<0) Print("Ошибка");
   Print("1 "+TimeToString(Arr[0])+" CurrentTime = "+TimeToString(TimeCurrent()));
   
   int Res=::Bars(_Symbol,PERIOD_W1,Arr[0],TimeCurrent());  // выполнение происходит 22 секунды!!!
   
   Print("2 CurrentTime = "+TimeToString(TimeCurrent()));
  }
//+------------------------------------------------------------------+

result:

2018.03.30 16:37:16.941 BagBars (EURUSD,W1)     1 2018.03.30 20:00 CurrentTime = 2018.03.30 23:37
2018.03.30 16:37:38.862 BagBars (EURUSD,W1)     2 CurrentTime = 2018.03.30 23:37