script on chart and the first bar..?

 

Hi,

I want to write e little script which needs the first bar of the chart (Eurusd m1) it is attached to.

Naively I use (mql5) iTime:

void OnStart()
  {
//---
   datetime tOne  = iTime(_Symbol,_Period,0);
   Comment("t1 ",tOne);
   return;
}

But what I see is the last timestamp of Friday.

If I use 100000 (instead of 0) I get 1970.01.01 00:00:00

If I use TERMINAL_MAXBARS I get 2018.09.14 23:46:00 and TERMINAL_MAXBARS = 11??

Beside this I see the Eurusd-chart for m1 going back to 2018.06.01 23:38

What can I do?

 
Carl Schreiber:

Hi,

I want to write e little script which needs the first bar of the chart (Eurusd m1) it is attached to.

Naively I use (mql5) iTime:

But what I see is the last timestamp of Friday.

If I use 100000 (instead of 0) I get 1970.01.01 00:00:00

If I use TERMINAL_MAXBARS I get 2018.09.14 23:46:00 and TERMINAL_MAXBARS = 11??

Beside this I see the Eurusd-chart for m1 going back to 2018.06.01 23:38

What can I do?

It is the weekend, so the last timestamp can only be Friday

 

I want the first bar that I can navigate to, in my case 2018.06.01 23:38. In mq5 bar 0 is the latest bar so the minute the market closed last Friday, but I don't need this date.

If I enter it manually I get it:

   int iB = iBarShift(_Symbol,_Period,D'2018.06.01 23:39');
   datetime tOne  = iTime(_Symbol,_Period,iB);
   Comment("t1 ",tOne,"  tMax: ",TERMINAL_MAXBARS,"  iB ",iB);

This puts 2018.06.01 23:39 on the chart.

So how can I get this moment without entering it manually with D'2018. ...'?

 

Sorry, I don't think that I read and understood your first post correctly.

 

This seems to give me the correct time.

void OnStart()
  {
//---
   datetime tOne  = iTime(_Symbol,_Period,iBars(_Symbol,_Period)-1);
   Comment("t1 ",tOne);
   return;
}
 
Thanks that works!
Reason: