How to refer to a particular time

 
I understand Time[] and iTime uses, however to refer to a particular time or time range does one simply use datetime ?

https://docs.mql4.com/dateandtime/Hour

Is that all there is to it ?

Please advise

Thanks

 
Not sure what you mean by . . . . "to refer to a particular time or time range" can you give an example of what you mean please ?
 
Oops sorry

So take the example from the documents ?


if(Hour()>=12 || Hour()<17)
{
OrderSend code
}

Or

if(Minute()>=720 || Minute()<725)   //I may not be using this correctly
         {
         int m=TimeMinute(TimeCurrent());
         Print (m, " Minutes");
        
I don't think I understand DateTime Functions
 

You MUST read the Documentation and make sure you understand what it is saying . . don't assume.

Click this link --> Minute() "Returns the current minute (0,1,2,..59) of the last known server time by the moment of the program start (this value will not change within the time of the program execution)." . . . . so for a Server time of 12:34 Minute() will return 34

"this value will not change within the time of the program execution" I think this means from tick to tick, i.e. execution of start() NOT execution of the EA.

 
I'm missing something here


string var1=TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES);
Print (var1, " var1");

Produces this print out ? What am I looking at here, seems like it prints randomly skipping days etc.


2011.12.07 08:23:17 2011.10.14 11:55 Time_sampling EURUSD,M15: 2011.10.14 11:55 var1
2011.12.07 08:23:17 2011.10.14 11:55 Time_sampling EURUSD,M15: 2011.10.14 11:55 var1
2011.12.07 08:23:17 2011.10.14 11:55 Time_sampling EURUSD,M15: 2011.10.14 11:55 var1
2011.12.07 08:23:17 2011.10.14 11:55 Time_sampling EURUSD,M15: 2011.10.14 11:55 var1
2011.12.07 08:23:16 2011.10.12 00:59 Time_sampling EURUSD,M15: 2011.10.12 00:59 var1
2011.12.07 08:23:16 2011.10.12 00:59 Time_sampling EURUSD,M15: 2011.10.12 00:59 var1
2011.12.07 08:23:16 2011.10.12 00:59 Time_sampling EURUSD,M15: 2011.10.12 00:59 var1
2011.12.07 08:23:16 2011.10.12 00:58 Time_sampling EURUSD,M15: 2011.10.12 00:58 var1
2011.12.07 08:23:16 2011.10.12 00:58 Time_sampling EURUSD,M15: 2011.10.12 00:58 var1
2011.12.07 08:23:16 2011.10.12 00:58 Time_sampling EURUSD,M15: 2011.10.12 00:58 var1
2011.12.07 08:23:16 2011.10.12 00:57 Time_sampling EURUSD,M15: 2011.10.12 00:57 var1
2011.12.07 08:23:16 2011.10.12 00:57 Time_sampling EURUSD,M15: 2011.10.12 00:57 var1
2011.12.07 08:23:15 2011.10.07 06:51 Time_sampling EURUSD,M15: 2011.10.07 06:51 var1
2011.12.07 08:23:15 2011.10.07 06:51 Time_sampling EURUSD,M15: 2011.10.07 06:51 var1
2011.12.07 08:23:15 2011.10.07 06:51 Time_sampling EURUSD,M15: 2011.10.07 06:51 var1
2011.12.07 08:23:15 2011.10.07 06:51 Time_sampling EURUSD,M15: 2011.10.07 06:51 var1
2011.12.07 08:23:15 2011.10.07 06:51 Time_sampling EURUSD,M15: 2011.10.07 06:51 var1
2011.12.07 08:23:15 2011.10.07 06:51 Time_sampling EURUSD,M15: 2011.10.07 06:51 var1
2011.12.07 08:23:15 2011.10.07 06:51 Time_sampling EURUSD,M15: 2011.10.07 06:51 var1
2011.12.07 08:23:15 2011.10.07 06:50 Time_sampling EURUSD,M15: 2011.10.07 06:50 var1
2011.12.07 08:23:14 2011.10.04 17:42 Time_sampling EURUSD,M15: 2011.10.04 17:42 var1
2011.12.07 08:23:14 2011.10.04 17:42 Time_sampling EURUSD,M15: 2011.10.04 17:42 var1
2011.12.07 08:23:14 2011.10.04 17:42 Time_sampling EURUSD,M15: 2011.10.04 17:42 var1
2011.12.07 08:23:14 2011.10.04 17:42 Time_sampling EURUSD,M15: 2011.10.04 17:42 var1
2011.12.07 08:23:14 2011.10.04 17:42 Time_sampling EURUSD,M15: 2011.10.04 17:42 var1
2011.12.07 08:23:14 2011.10.04 17:42 Time_sampling EURUSD,M15: 2011.10.04 17:42 var1
2011.12.07 08:23:14 2011.10.04 17:42 Time_sampling EURUSD,M15: 2011.10.04 17:42 var1
2011.12.07 08:23:14 2011.10.04 17:42 Time_sampling EURUSD,M15: 2011.10.04 17:42 var1

 
Agent86:

What am I looking at here,

Take the first line at the top . . . . figure it out . . . here is a clue . .

2011.12.07 08:23:172011.10.14 11:55Time_samplingEURUSD,M15:2011.10.14 11:55 var1
Today/NowTime in the STEA/Script/Indicator nameInstrumentTime PeriodSame as "Time in the ST"

Not sure what your problem is ? if it's why your ST seems to running what ever it is you are running sporadically then I can't help as I can't see your code . . . or what you are doing with it.

 
Open a EURUSD, M15 chart and right click -> refresh so you have history for the ST and retry your test.
 
Ok, thanks all

I might be looking at this all wrong.

Maybe I simply need to refer to something like if(Time[1] >= 18:00 && Time[1] < 21:00) or some such scheme for creating a timed trade

Can I create a time range using this method ?
I'm really not sure what is a most typical method to create a range of time for placing trades

Thanks for the help everyone, I'll keep reading
 
Agent86:
Ok, thanks all

I might be looking at this all wrong.

Maybe I simply need to refer to something like if(Time[1] >= 18:00 && Time[1] < 21:00) or some such scheme for creating a timed trade

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

if(TimeHour(Time[1]) >= 18 && TimeHour(Time[1]) < 21)

read up on TimeHour

 
or
datetime now = Time[0],
         bod = now - now % 86400,
         HR1800 = bod + 18*3600,
         HR2100 = bod + 21*3600;
if (Time[1] >= HR1800 && Time[1] < HR2100) ...
see also
 
Thanks everyone, that should give me enough to work through this subject now

I'll read up and make some code

Thanks
This website uses cookies. Learn more about our Cookies Policy.