TimespanMT4(int) convert to Datetime(datetime)cTrader
Created at 04 Oct 2014, 20:49
TimespanMT4(int) convert to Datetime(datetime)cTrader
04 Oct 2014, 20:49
Hello,
how can i convert datetime(int) in format MT4 to datetime cTrader ?
thx Mijo.
Replies
algotrader
06 Oct 2014, 09:25
class Mq4TimeSeries { private readonly TimeSeries _timeSeries; private static readonly DateTime StartDateTime = new DateTime(1970, 1, 1); public Mq4TimeSeries(TimeSeries timeSeries) { _timeSeries = timeSeries; } public static int ToInteger(DateTime dateTime) { return (int)(dateTime - StartDateTime).TotalSeconds; } public static DateTime ToDateTime(int seconds) { return StartDateTime.AddSeconds(seconds); } public int this[int index] { get { if (index < 0 || index >= _timeSeries.Count) return 0; DateTime dateTime = _timeSeries[_timeSeries.Count - 1 - index]; return ToInteger(dateTime); } } }
Example of usage:
DateTime cSharpTime = Mq4TimeSeries.ToDateTime(mt4Time);
@algotrader
algotrader
06 Oct 2014, 09:26
class Mq4TimeSeries { private static readonly DateTime StartDateTime = new DateTime(1970, 1, 1); public static int ToInteger(DateTime dateTime) { return (int)(dateTime - StartDateTime).TotalSeconds; } public static DateTime ToDateTime(int seconds) { return StartDateTime.AddSeconds(seconds); } }
Example of usage:
DateTime cSharpTime = Mq4TimeSeries.ToDateTime(mt4Time);
DateTime cSharpTime = Mq4TimeSeries.ToDateTime(mt4Time);
@algotrader
Invalid
06 Oct 2014, 09:14
RE:
mijo212 said:
@Invalid