How to refer to a particular time - page 2

 
Hi all

I might be mixing topics here, but let me rephrase my title / question in this way

If I want to find a candle of a particular time such as (how do I find the high[],low[]close[],open[]) of a candle at lets say 7:00am, MT4 charts shows the close candles and opening times on the charts by default so lets use that.

Print(high[], " High of the candle of 7:00am);
Print(low[], " Low of the candle of 7:am);

So I want to find the high and low of a particular candle at a particular time.

Once I find this then I want to set a time range for trading based on that starting point and starting candle that I just found.

Anyhow just FYI I think I can get this working with the info you all posted and manage from there but I may have misdescribed my question

I'll post back the code for anyone to see it once I finish, maybe then can use it.

Thanks all
 
RaptorUK:

No, because Time[x] returns a datetime . . . but you can do . . .

read up on TimeHour


How does it know 18 ?
if(TimeHour(Time[1]) >= 18

I sort of get TimeHour but Time[1] is datetime so why doesn't that need to be converted somehow ?

I'm assuming TimeHour does this for me, I'll set a print statement so I can try to see what it's doing

Sorry for the likely simple questions after all this time, but I'm still struggling to understand some of the functions

 
Should my print statement be printing at 7 ?

if(TimeHour(Time[1]) == 7)
   {
   Print(TimeHour(Time[1]), " Time [1] what is this time");
   }

2011.12.15 19:14:44 2011.11.18 08:11 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:11 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:11 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:11 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:11 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:11 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:11 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:11 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:11 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:11 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:11 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:11 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:11 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:11 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:11 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:11 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:11 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:11 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:10 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:10 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:10 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:10 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:10 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:10 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:10 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:10 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:10 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:10 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:10 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:10 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:10 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:10 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:10 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:10 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:10 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:10 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:10 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:10 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:10 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:10 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:10 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:10 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:10 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:10 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:10 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:10 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:10 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:10 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:10 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:10 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:10 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:10 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:10 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:10 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:10 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:10 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:10 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:09 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.18 08:09 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.11 08:11 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.11 08:11 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.11 08:11 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.11 08:11 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.11 08:11 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.11 08:11 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.11 08:11 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:44 2011.11.11 08:11 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:43 2011.10.28 08:08 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:43 2011.10.28 08:08 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:43 2011.10.28 08:08 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:43 2011.10.28 08:08 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:43 2011.10.28 08:08 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:43 2011.10.28 08:08 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:43 2011.10.28 08:08 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:43 2011.10.28 08:08 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:42 2011.10.14 08:09 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:42 2011.10.14 08:09 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:42 2011.10.14 08:09 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:42 2011.10.14 08:09 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:42 2011.10.14 08:09 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:42 2011.10.14 08:09 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:42 2011.10.14 08:09 Time_sampling EURUSD,M15: 7 Time [1] what is this time
2011.12.15 19:14:42 2011.10.14 08:09 Time_sampling EURUSD,M15: 7 Time [1] what is this time
 
Agent86:

So I want to find the high and low of a particular candle at a particular time.

Use iBarShift it "Search for bar by open time." and then it . . "returns bar shift with the open time specified." You have to give it a datetime . . .

. . . . so how do you work out the datetime for the hour that you want ? Well lets assume that you want 7am from this morning . . . (it's 9:30am for me right now) take TimeCurrent() (this is server time so there may be a time shift compared to your local time, you need to factor this in) then divide it by days (PERIOD_D1 * 60) and take the MathFloor value from it, this gives you Midnight as a datetime . . . add on 7 hours (7 * 60 * 60) and you have 7am as a datetime.

 
Agent86:

How does it know 18 ?

I sort of get TimeHour but Time[1] is datetime so why doesn't that need to be converted somehow ?

I'm not sure why you are having such an issue with the Documentation . . . can you explain ? To me, in this case, it is crystal clear . . yes I agree, for some functions the documentation can leave a lot to be desired . . . but . . .

int TimeHour(datetime time)

Returns the hour for the specified time.

int = what variable type the Function returns

datetime time = what type you need to pass the function when you call it

Returns the hour for the specified time. = what the Function does . . .

 
Agent86:
Should my print statement be printing at 7 ?

Yes it should . . . are you on a H1 chart ? so Time[1] returns the time of the last complete candle . . . if the current time is 08:11 then the current H1 candle is 8am so the previous is 7 am . . no ?

 
RaptorUK:

Yes it should . . . are you on a H1 chart ? so Time[1] returns the time of the last complete candle . . . if the current time is 08:11 then the current H1 candle is 8am so the previous is 7 am . . no ?

LOL, ok I'm on the 15min charts, so I see why it's printing it out this way now
Ok I'll review iBarShift again too

Thanks.
 

Hi i also hunt for a clue to get data of the first bar of the day.

this code i made, does not work for sure:

double nyitohigh; // the high value for the first bar

double nyitolow; // the low value of the first bar


datetime ejfel = D'TimeYear().TimeMonth().TimeDay() 00:00'; //we get midnight

int shift=iBarShift(NULL,PERIOD_M15,ejfel,true); // get the shift from now

nyitohigh=iHigh(NULL,PERIOD_M15,shift); //get the high

nyitolow=iLow(NULL,PERIOD_M15,shift); //get the low

i checked it with Comment("Nyito teteje ",nyitohigh," Nyito alja ",nyitolow); but it writes 0 and 0 on the comment.

could you have any good hint?

Agent86:
LOL, ok I'm on the 15min charts, so I see why it's printing it out this way now
Ok I'll review iBarShift again too

Thanks.


 
Szilar:

could you have any good hint?


You cannot do this . . .

datetime ejfel = D'TimeYear().TimeMonth().TimeDay() 00:00'; //we get midnight   <---  no you don't !

. . . read the Documentation about datetime especially the last sentence.

 

Hi.

Solved.

double nyitohigh;

double nyitolow;


datetime ejfel = StrToTime("00:00");

int shift=iBarShift(NULL,PERIOD_M15,ejfel,true);

nyitohigh=iHigh(NULL,PERIOD_M15,shift);

nyitolow=iLow(NULL,PERIOD_M15,shift);

Szilar:

Hi i also hunt for a clue to get data of the first bar of the day.

this code i made, does not work for sure:

double nyitohigh; // the high value for the first bar

double nyitolow; // the low value of the first bar


datetime ejfel = D'TimeYear().TimeMonth().TimeDay() 00:00'; //we get midnight

int shift=iBarShift(NULL,PERIOD_M15,ejfel,true); // get the shift from now

nyitohigh=iHigh(NULL,PERIOD_M15,shift); //get the high

nyitolow=iLow(NULL,PERIOD_M15,shift); //get the low

i checked it with Comment("Nyito teteje ",nyitohigh," Nyito alja ",nyitolow); but it writes 0 and 0 on the comment.

could you have any good hint?