Questions from Beginners MQL5 MT5 MetaTrader 5 - page 535

 
Karputov Vladimir:

So, you need to specify such a request right away :) .

The situation is as follows: if there is a bar in the chart, it corresponds to a cell in the indicator buffer. As long as you don't write something into this cell, it will store rubbish.

Why isn't it rubbish in MT4 but just doesn't display the indicator under this bar?
 
Aleksey Lebedev:

When you divide integers (int,long,datetime etc.) the result is an integer, i.e. the remainder is discarded. 00:00 today and 23:59:59 yesterday, the difference will be 1 day.

Firstly it is not - it is proven experimentally in the indicator.

Secondly, how do you get a 1 - show me mathematically, given that we are originally calculating in seconds.

 
Alexey Kozitsyn:
Exactly the same way as zeroing simple types. By assigning them a value of 0. Once the required fields have been assigned a value of 0 - use the reverse operation StructToTime().

Zeroed out:

MqlDateTime str1;
datetime  Open_timePos=iTime(_Symbol,0,pos);
TimeToStruct(Open_timePos,str1);
   str1.hour=0;
   str1.min=0;
   str1.sec=0;
datetime  start_time=StructToTime(str1);
Print("день=",TimeToStr(start_time));

Everything worked - thank you!
 

Aleksey Lebedev:
При делении целых чисел(int,long,datetime и т.п.) результат целое число, т.е. остаток отбрасывается. 00:00 сегодня и 23:59:59 вчера, разность будет равна 1дню.

-Aleks-:

First of all it's not - proven experimentally in the indicator.

Don't argue with the basics).

-Aleks-:

Secondly how do you get 1 - show me mathematically, given that initially we have the calculation in seconds.

datetime today=D'2016.03.09 00:00:00';
datetime yesterday=D'2016.03.08 23:59:59';
Print("today=",86400*(today/86400)," value=",int(today));
Print("yesterday=",86400*(yesterday/86400)," value=",int(yesterday));
Print("разница в днях = ",int(today/86400-yesterday/86400));

Use conversion through structure, if it is easier to understand.

 
Aleksey Lebedev:

Don't challenge the basics)

Use structure conversion if it's easier to understand.

What is understood is what has been dealt with. I haven't tried your code to run it, but I think you did it yourself, so explain to me unintelligent how it works:

86401/86400-86400/86400 equals 1, if by rules of mathematics 1.000012-1=0.000012 , and int should round up to integer, i.e. 0.

 
-Aleks-:

What is understood is what has been dealt with. I have not tried your code to run, but I think you have done it yourself, so explain to me unintelligent how it works:

86401/86400/86400 equals 1, if according to the rules of mathematics 1.000012-1=0.000012 , and int should round to integer, i.e. 0.

but do it)

Start of the day 00:00:00 is divided by 86400 without a remainder, the previous one is at least 1 second less. Rounded off - the remainder of the division is discarded, not the whole expression.

86400/86400=1

86399/86400=0

 
Aleksey Lebedev:

and then run it)

The start of the day 00:00:00 is divided by 86400 without a remainder, the previous one being at least 1 second less. Rounded off - the remainder of the division is discarded, not the whole expression.

86400/86400=1

86399/86400=0

so it surprises me that the peculiar rounding happens within an expression - I thought it was when a variable was assigned a value that the value after the decimal point is discarded.
 
Guys! Is it possible to display the indicator on the chart programmatically? Or only by hand?
 
Vladimir Tkach:
Guys! Is it possible to display the indicator on the chart programmatically? Or only by hand?
You can do ithttps://www.mql5.com/ru/docs/chart_operations/chartindicatoradd
Документация по MQL5: Операции с графиками / ChartIndicatorAdd
Документация по MQL5: Операции с графиками / ChartIndicatorAdd
  • www.mql5.com
Операции с графиками / ChartIndicatorAdd - справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
is it in mql5, and in mql4?