Download MetaTrader 5
To add comments, please log in or register
Have you developed a profitable strategy? Share it with millions of traders via Signals!
Michael
492
Michael 2014.03.13 03:07 

I'm getting a headache from trying to figure this out.

Code:

   datetime Diff=Time[1]-Time[1+1];
   int iDiff=TimeSeconds(Diff);
   Alert(iDiff);

Needless to say, I'm trying to get the integer value of the seconds elapsed from both times. Diff comes out correct (1/1/1970 04:00 on a 4hr chart). iDiff comes out to 0. Why? My "stroked" out brain can't figure this out.

Michael
492
Michael 2014.03.13 03:25  

Figures I'd solve right after I put it up.

Code:

   int Diff=Time[1]-Time[1+1];
   int intSeconds=Diff%60;
   int intMinutes=(Diff-intSeconds)/60;
   Alert("Mins:",intMinutes,"  Secs:",intSeconds);

My only problem with this is I get a compiler warning: "possible loss of data due to type conversion" on the first line. Anyone know a fix/away around that?

Keith Watford
Moderator
7875
Keith Watford 2014.03.13 04:45  
nondisclosure:

Figures I'd solve right after I put it up.

Code:

My only problem with this is I get a compiler warning: "possible loss of data due to type conversion" on the first line. Anyone know a fix/away around that?


I think that it is only a warning, but can be annoying when you get a lot of them

datetime Diff=Time[1]-Time[1+1];
int intDiff = (int)Diff;
whroeder1
13596
whroeder1 2014.03.13 12:14  
The difference between two date/times is not a date/time. 11:30 - 09:00 is not D'1970.01.01 02:30' it's 480 seconds
datetime Diff=Time[1]-Time[1+1];
datetime - datetime is a Long int, but we don't have 68 year timeframes.
int Diff=(int)(Time[1]-Time[1+1]);
/
To add comments, please log in or register