# Counting bars including weekends - page 4

Thank you all very much for your help and participation!!!

Versions 1,2 and 4 are more correct, but have errors, somewhere it is correct (day to day) and somewhere it is missing 2-3 days

Version 3 sees the number of bars for the period that have already been calculated.

```//+------------------------------------------------------------------------+
//| ВЕРСИЯ 1 рассчитывает бары за период только выходных дней  12бар=3вых  |
//+------------------------------------------------------------------------+
int NumData1(datetime d_start,datetime d_stop){
const int day_in_sec = 24 * 60 * 60;
datetime d_corect1 = d_start - d_start % day_in_sec;
datetime d_corect2 = d_stop - d_stop % day_in_sec;
int result = (int)((d_corect2 - d_corect1) / day_in_sec);
datetime t_arr[];
int allbarD1 = CopyTime(_Symbol, PERIOD_D1, d_start, d_stop, t_arr);
if(allbarD1 < 0) return(0);
return(result-allbarD1);}
//+------------------------------------------------------------------------+
//| ВЕРСИЯ 2 рассчитывает бары за период только рабочих дней  12бар=9раб   |
//+------------------------------------------------------------------------+
int NumData2(datetime d_start,datetime d_stop){
int bar=Bars(Symbol(),0,d_start,d_stop);
return(bar);}
//+------------------------------------------------------------------------+
//| ВЕРСИЯ 3 рассчитывает бары за период                      12бар=12бар  |
//+------------------------------------------------------------------------+
int NumData3(datetime d_start,datetime d_stop){
MqlDateTime dts[2];
TimeToStruct(d_start,dts[0]);
TimeToStruct(d_stop,dts[1]);
return(dts[1].day_of_year - dts[0].day_of_year);}
//+------------------------------------------------------------------------+
//| ВЕРСИЯ 4 рассчитывает бары за период только рабочих дней  12бар=9раб   |
//+------------------------------------------------------------------------+
int NumData4(datetime startDate,datetime endDate){
int d=int((endDate-startDate)/86400);
int m[7,7]={
{0, 0,1,2,3,4,5}, // воскр
{0, 1,2,3,4,5,5}, // понед
{0, 1,2,3,4,4,4}, // вторн
{0, 1,2,3,3,3,4}, // среда
{0, 1,2,2,2,3,4}, // четв
{0, 1,1,1,2,3,4}, // пятн
{0, 0,0,1,2,3,4}  // субб
};
return((d/7)*5+m[(int)TimeDayOfWeek(startDate)][d%7]);}```

Although it counts 1, 2 and 4 correctly.
I didn't take into account that the second point then moves to the received +n bars
and there are also weekends and as a result I am 2-3 bars short to the right place

Is it possible to identify the visible bars?
I.e. we have the first price and add the visible bars to it on the chart
. Otherwise we have the first point on the 5th of the month + 12 bars = the 17th of the month + 4 days off = the 21st of the month and we are missing a couple more days to the end point

forex2030:

Is it possible to identify exactly the visible bars?

Yes, no problem. And this particular answer was the very first in the thread. Simple, quick, elegant.

Подсчёт баров с учётом выходных
• 2020.04.25
• www.mql5.com
Есть две точки t1 и t2, между ними 25 баров, как узнать сколько было выходных между точками например на D1 чтобы потом их прибавить к нужным барам...

Including weekends?

Write 12 months, i.e. 12 variables with the number of days in them, all into an array

into an array of years, with the number of days in February, or calculate a year with a leap in February.

in a loop:

add up the full and remaining days in the start and end months of the required period

How do holidays get away? Or do they not count as holidays?)

Aleksey Nikolayev:
How do holidays get away? Or don't they count as holidays?)
calculates the total number of days and subtracts the number of days in the quote history

Renat Akhtyamov:
It will calculate the total number of days and subtract the number of days in the quote history

You can if you can be sure that there are no other reasons for missing the day.

It is also possible to miss only part of the day - this can also have a negative impact on the calculations

Aleksey Nikolayev:

It is also possible to skip only part of the day - this can also have a bad effect on the calculations

In this case the daily bar will still be present on the chart

Aleksey Nikolayev:

You can if you can be sure that there are no other reasons for missing the day.

It is also possible to miss only part of the day - this can also have a negative impact on the calculations

You have to use the daily TF and nothing else

Igor Makanu:

in which case the daily bar will still be present on the chart

It will, of course. But, for example, its high-low will stand out from the rest and there will always be a question - is it a holiday or dropped minute bars? It is not very clear how to automate such checks.