public void DoExperiment() { DateTimeUTC week_start = new DateTimeUTC(2007, 1, 1); List <ForexFactoryEvent> all_event_list = new List <ForexFactoryEvent>(); while (week_start < DateTimeUTC.Now) { Console.WriteLine(week_start); all_event_list.AddRange(ToolsForexFactory.GetForexFactoryEvents(week_start)); week_start = week_start.AddDays(7); Thread.Sleep(1000); } string[,] table = new string[all_event_list.Count, 9]; for (int index = 0; index < all_event_list.Count; index++) { table[index, 0] = all_event_list[index].WeekStartDay.ToString(); table[index, 1] = all_event_list[index].DateString; table[index, 2] = all_event_list[index].TimeString; table[index, 3] = all_event_list[index].Symbol; table[index, 4] = all_event_list[index].Impact; table[index, 5] = all_event_list[index].Description; table[index, 6] = all_event_list[index].Actual; table[index, 7] = all_event_list[index].Forecast; table[index, 8] = all_event_list[index].Previous; } ToolsIOCSV.WriteCSVFile(@"D:\GoogleDrive\TestData\Trading\events.csv", table, Delimiter.SemiColon); }
public static DateTimeUTC GetCloseTime(DateTimeUTC time, TimeScale time_scale) { DateTimeUTC open_time = GetOpenTime(time, time_scale); switch (time_scale) { case TimeScale.Second1: return(open_time.AddSeconds(1)); case TimeScale.Minute1: return(open_time.AddMinutes(1)); case TimeScale.Minute15: return(open_time.AddMinutes(15)); case TimeScale.Minute30: return(open_time.AddMinutes(30)); case TimeScale.Hour1: return(open_time.AddHours(1)); case TimeScale.Hour4: return(open_time.AddHours(4)); case TimeScale.Day1: return(open_time.AddDays(1)); case TimeScale.Week1: return(open_time.AddDays(7)); case TimeScale.Month1: return(open_time.AddMonths(1)); default: throw new Exception("Unknown Timescale"); } }
public static DateTimeUTC GetOpenTime(DateTimeUTC time, TimeScale time_scale) { switch (time_scale) { case TimeScale.Second1: return(new DateTimeUTC(time.Year, time.Month, time.Day, time.Hour, time.Minute, time.Second)); case TimeScale.Minute1: return(new DateTimeUTC(time.Year, time.Month, time.Day, time.Hour, time.Minute, 0)); case TimeScale.Minute15: return(new DateTimeUTC(time.Year, time.Month, time.Day, time.Hour, time.Minute - time.Minute % 15, 0)); case TimeScale.Minute30: return(new DateTimeUTC(time.Year, time.Month, time.Day, time.Hour, time.Minute - time.Minute % 30, 0)); case TimeScale.Hour1: return(new DateTimeUTC(time.Year, time.Month, time.Day, time.Hour, 0, 0)); case TimeScale.Hour4: return(new DateTimeUTC(time.Year, time.Month, time.Day, time.Hour - time.Hour % 4, 0, 0)); case TimeScale.Day1: return(new DateTimeUTC(time.Year, time.Month, time.Day, 0, 0, 0)); case TimeScale.Week1: DateTimeUTC temp = new DateTimeUTC(time.Year, time.Month, time.Day, 0, 0, 0); return(temp.AddDays(-(int)time.DayOfWeek)); case TimeScale.Month1: return(new DateTimeUTC(time.Year, time.Month, 1, 0, 0, 0)); default: throw new Exception("Unknown Timescale"); } }