Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 616

 
001:
I don't know how I can get the numbers of yesterday's bars from 00:00 to 23:59 at any time today (in the tester of course) correctly. Please tell me.

Have you looked atiBarShift yet?
 
pu6ka:

Have you looked atiBarShift yet?

No, there's a more perverse question here, that won't help.

 
001:
I don't understand how I can check correctly the numbers of yesterday's bars from 00:00 to 23:59 at any time today (in the Strategy Tester, of course). Please tell me.
                 //+------------------------------------------------------------------+
                 //|                                                       Отскок.mq4 |
                 //|                                              FOReignEXchange2008 |
                 //|                                          forexsignal2008.ucoz.ru |
                 //+------------------------------------------------------------------+
                   #property copyright "FOReignEXchange2008"
                   #property link      "FOReignEXchange@bk.ru"

int День,i,k;

int start()
{

i=0;k=0;

День=TimeDay(iTime(NULL,0,0));

while (i<=1440)
      {
      if (TimeDay(iTime(NULL,0,i))==(День-1) && k==0) 
         {
         k=i;
         Alert("",k);
         }
      i++;
      }
return;
}

//+------------------------------------------------------------------+

This is roughly how the number of the last bar of the previous day is calculated in the tester. The rest you can make up on your own.

 
FOReignEXchange:

This is roughly how the number of the last bar of the previous day is calculated in the tester. You can do the rest on your own.


Thank you! I will try it tomorrow. I'm not thinking straight today. Didn't really ask the right question. I need, today, to know the numbers of the first and last bar of yesterday. It's not necessary to know everything.
 
001:

Thanks! I'll try it tomorrow. My head's not thinking straight today. Didn't really ask the right question. Need, today, to know the numbers of the first and last bar of yesterday. It's not necessary to know everything.

The TimeCurrent tester picks up well. So you can do something with a similar variant (try creating a script with the code below and see the result):

   datetime LastServerTime=TimeCurrent();
   long tms=LastServerTime%86400;
   int NumberFirstBar=iBarShift(NULL,0,LastServerTime,false);
   datetime TimeNumberFirstBar=iTime(NULL,0,NumberFirstBar);   
   datetime TimeLastBar=TimeNumberFirstBar-(datetime)tms;
   
   int NumberLastBar=iBarShift(NULL,0,TimeLastBar,false);
   
   Comment("NumberLastBar = ",NumberLastBar);

In fact, there' s a very good article here. Even though it's for MT5, but there's useful information for MT4 as well.

 
001:
I don't know how I can get the numbers of yesterday's bars from 00:00 to 23:59 at any time today (in the tester of course) correctly. Please tell me.


This way you can find the index of the first bar at the beginning of any day.

     int n = 1;                                           // индекс дня, в данном случае 1 - вчерашний день
datetime DayTime = iTime(NULL, PERIOD_D1, n);             // Начало дня "n" в секундах
     int cb = iBarShift(NULL,0,DayTime);                  // Получим на текущем ТФ индекс 1-го бара


If you know this index, you can calculate the index of the last bar of the previous day.

 
pu6ka:


This is how you can find the index of the first bar at the start of any day.


Knowing this index, you can find the index of the last bar of the previous day by adding one.


If the code is used only in a real or demo account, your version is more convenient. However, it may cause problems in the strategy tester.

P./S.: That's why FOReignEXchange and I have cited other options.

 
Thank you all! Let's get to work.
 
DiPach:

If the code is to be used only in real or demo account, then the variant like yours is more convenient. However, in the strategy tester, you may have problems using it.

P./S.: That's why FOReignEXchange and I cited other options.


Perhaps. I used this code for an indicator and it did not fail me there. Let him try different variants.

 

Tried different options. The result is the same. I do not understand how it can happen. At some moment the iLowest(NULL,0,MODE_LOW,NumberLastBar_beg,NumberLastBar_end); suddenly starts calculating a larger bar range. Please advise who understands, my head is broken. Thanks.


4:08:36 Time+iLowest test started

14:08:36 2004.09.29 00:00 Time+iLowest EURUSD,H1: NumberLastBar_beg= 24 NumberLastBar_end= 0
14:08:36 2004.09.29 00:00 Time+iLowest EURUSD,H1: i=18
14:08:36 2004.09.29 00:00 Time+iLowest EURUSD,H1: time_check_low_day=06:00
14:08:39 2004.09.29 01:00 Time+iLowest EURUSD,H1: NumberLastBar_beg= 25 NumberLastBar_end= 1
14:08:39 2004.09.29 01:00 Time+iLowest EURUSD,H1: i=19
14:08:39 2004.09.29 01:00 Time+iLowest EURUSD,H1: time_check_low_day=06:00
14:08:39 2004.09.29 02:00 Time+iLowest EURUSD,H1: NumberLastBar_beg= 26 NumberLastBar_end= 2
14:08:39 2004.09.29 02:00 Time+iLowest EURUSD,H1: i=20
14:08:39 2004.09.29 02:00 Time+iLowest EURUSD,H1: time_check_low_day=06:00
14:08:40 2004.09.29 03:00 Time+iLowest EURUSD,H1: NumberLastBar_beg= 27 NumberLastBar_end= 3
14:08:40 2004.09.29 03:00 Time+iLowest EURUSD,H1: i=21
14:08:40 2004.09.29 03:00 Time+iLowest EURUSD,H1: time_check_low_day=06:00
14:08:41 2004.09.29 04:00 Time+iLowest EURUSD,H1: NumberLastBar_beg= 28 NumberLastBar_end= 4
14:08:41 2004.09.29 04:00 Time+iLowest EURUSD,H1: i=31

14:08:41 2004.09.29 04:00 Time+iLowest EURUSD,H1: time_check_low_day=21:00

Code:


static int PrevTime=0;
//+------------------------------------------------------------------+
//||
//+------------------------------------------------------------------+
int start()
{
if(Time[0]<=PrevTime) return(0);
PrevTime=Time[0];
//////////////
// CheckForLongTimeClose_Sell();
double pBid=NormalizeDouble(Bid,Digits),Low_Now=Low[1];
////////////
int n_beg=1;// index of the day, in this case 1 is yesterday
datetime DayTime_beg=iTime(NULL,PERIOD_D1,n_beg); // start of day "n" in seconds
intLastBar_beg=iBarShift(NULL,0,DayTime_beg);

int n_end=0;// index of the day, in this case 1 is yesterday's day
datetime DayTime_end=iTime(NULL,PERIOD_D1,n_end); // start of the day "n" in seconds
int NumberLastBar_end=iBarShift(NULL,0,DayTime_end);
Print(" NumberLastBar_beg= ",NumberLastBar_beg," NumberLastBar_end= ",NumberLastBar_end);
//---------------------------------------------------------------------

datetime Time_Check_Low_Day=Time[iLowest(NULL,0,MODE_LOW,NumberLastBar_beg,NumberLastBar_end)];
int=iLowest(NULL,0,MODE_LOW,NumberLastBar_beg,NumberLastBar_end);
Print(" i=",i);
string time_check_low_day=TimeToStr(Time_Check_Low_Day,TIME_MINUTES);
/////////////
Print(" time_check_low_day=",time_check_low_day;)

datetime time_check_verify=StrToTime("H_check_beg:M_check_beg");


return(0);
}

Reason: