iTime question

 
Hi

if(val1 > 0 && faster > slower)
      {
       Print (val1, " val1");
       Print (iTime(NULL, 0, 3), " iTime val1");      
       int a = iTime(NULL, 0, 3);  
  
      }
   if(val2 > 0 && faster > slower)
      {
      Print (val2, " val2");
      Print (iTime(NULL, 0, 3), " iTime val2");
      int b = iTime(NULL, 0, 3); 
      }
      
   if(b>a)
      {
      Print (a, " a");
      Print (b, " b");
      } 
When using iTime to compare these 2 conditions, is it necessary to convert to readable time or can you simply use something like this ?
if(b>a)



Also if I even need to convert this please clarify the conversion I don't understand the syntax of TimeToStr()

Thanks

 

a and b are ints, of course you can do this (b>a) really you should use type datetime . . . but an int will work.

Dates and time are stored as . . . "an unsigned integer containing seconds that have passed since 0.00 a.m. on 1 January, 1970." TimeToStr() converts that unsigned int into a man readable date and time . .

 
  1. RaptorUK:
    a and b are ints, of course you can do this (b>a) really you should use type datetime . . . but an int will work.
    int b>a will work until you reach 2038 and the int becomes negative.
  2. When using iTime to compare these 2 conditions
    Why use the function call iTime(Null, 0, X) when you can use the simpler Time[X]?
 
RaptorUK:

a and b are ints, of course you can do this (b>a) really you should use type datetime . . . but an int will work.

Dates and time are stored as . . . "an unsigned integer containing seconds that have passed since 0.00 a.m. on 1 January, 1970." TimeToStr() converts that unsigned int into a man readable date and time . .


Great, thanks

But if I did want to use TimeToStr() for this and lets say I used the datetime a= ?
Can you show a sample of how the TimeToStr is used with iTime ? Or do I used TimeCurrent ? I'm really not sure if I'm using the correct function for this.

Thanks

 
WHRoeder:
  1. RaptorUK:
    a and b are ints, of course you can do this (b>a) really you should use type datetime . . . but an int will work.
    int b>a will work until you reach 2038 and the int becomes negative.
  2. When using iTime to compare these 2 conditions
    Why use the function call iTime(Null, 0, X) when you can use the simpler Time[X]?
So I can call Time[X] Same as Bar[X] just select my shift/bar number that I would like to know about ?
 
Ok so Print (Time[3]);

I see this prints a similar value to iTime this is ok but I guess I should convert just so I can confirm that it's actually doing what I want it to do.

Actually learning a lot just printing stuff to see how it works, thanks everyone
 
Agent86:

Great, thanks

But if I did want to use TimeToStr() for this and lets say I used the datetime a= ?
Can you show a sample of how the TimeToStr is used with iTime ? Or do I used TimeCurrent ? I'm really not sure if I'm using the correct function for this.

Thanks

OK . .

datetime a = iTime(NULL, 0, 3);  

Print("Time of bar no. 3 is ", TimeToStr(a,TIME_DATE|TIME_SECONDS));

or just do it on one line . . .

Print("Time of bar no. 3 is ", TimeToStr(iTime(NULL, 0, 3),TIME_DATE|TIME_SECONDS));
 
RaptorUK:

OK . .

or just do it on one line . . .


Ahh, this is what I was coming up with too, this is really good news that I'm hitting on about 30%- 50% of my ideas now LOL if you can call that progress, but I actually do since I was batting like 0% in the beginning.

So I decided to go with the Time[3] and changed a,b to datetime

 if(val1 > 0 && faster > slower)
      {
       Print (val1, " val1");
       Print(TimeToStr(Time[3],TIME_DATE|TIME_MINUTES), " = val1 time");      
       datetime a = Time[3];  
  
      }
   if(val2 > 0 && faster > slower)
      {
      Print (val2, " val2");
      Print(TimeToStr(Time[3],TIME_DATE|TIME_MINUTES), " = val2 time");
      datetime b = Time[3]; 
      }
      
   if(b>a)
      {
      Print (TimeToStr(a,TIME_DATE|TIME_MINUTES), " a");
      Print (TimeToStr(b,TIME_DATE|TIME_MINUTES), " b");
      }       
2011.10.15 15:20:15 2011.01.05 18:00 Agent86_5min EURUSD,M5: 2011.01.05 17:45 = val1 time
2011.10.15 15:20:15 2011.01.05 18:00 Agent86_5min EURUSD,M5: 1.3156 val1
2011.10.15 15:20:15 2011.01.05 17:59 Agent86_5min EURUSD,M5: 2011.01.05 17:40 b
2011.10.15 15:20:15 2011.01.05 17:59 Agent86_5min EURUSD,M5: 1970.01.01 00:00 a
2011.10.15 15:20:15 2011.01.05 17:59 Agent86_5min EURUSD,M5: 2011.01.05 17:40 = val2 time
2011.10.15 15:20:15 2011.01.05 17:59 Agent86_5min EURUSD,M5: 1.3148 val2


2011.10.15 15:20:15 2011.01.05 17:59 Agent86_5min EURUSD,M5: 1970.01.01 00:00 a <<<what is this ? and why ?






 
Ok, thinking outloud for a moment.

If val1>0 is true, then I get (a)


But if val1>0 is false, then I don't get (a) so what will the value of (a) be if val1>0 is false ?

I'm guessing 0 ? thus defaults to the 1970's LOL ? which is why I'm getting this value for (a) print statement ?
Does my diagnosis seem correct ?


So I dumbed it down and a = 0

if(b>a)
      {
       Print(a, " = a");
       Print(b, " = b");
 
Agent86:
Ok, thinking outloud for a moment.

If val1>0 is true, then I get (a)


But if val1>0 is false, then I don't get (a) so what will the value of (a) be if val1>0 is false ?

I'm guessing 0 ? thus defaults to the 1970's LOL ? which is why I'm getting this value for (a) print statement ?
Does my diagnosis seem correct ?



empty value

the function datetime a = Time[3];

happens only with val1>0 and if at the same time faster > slower

if not true ( val1 =< 0 ) there is no calculation

 
deVries:


empty value

the function datetime a = Time[3];

happens only with val1>0 and if at the same time faster > slower

if not true ( val1 =< 0 ) there is no calculation


Right, that's what it seems like me, but why do I get values for val1 and never a value for (a) which always = 0 empty

On the other hand val2 and b are always printing what I would have expected and never = 0 or empty

Oh and is Time[3] the open time or the close time, because if you noticed my print statement for val1 time it's different then the print statement for (b) ?
And both use Time[3] or shift 3 for calculating and should be the same I would have thought ?
2011.10.15 15:20:15 2011.01.05 18:00 Agent86_5min EURUSD,M5: 2011.01.05 17:45 = val1 time
2011.10.15 15:20:15 2011.01.05 17:59 Agent86_5min EURUSD,M5: 2011.01.05 17:40 b


Please advise thanks

Reason: