public static DateTime addTimeUnits(DateTime date, TimeframeSymbol timeframe, int units) { switch (timeframe) { case TimeframeSymbol.MN1: return addTimeUnits_month(date, units); case TimeframeSymbol.W1: return addTimeUnits_weeks(date.Proper(timeframe), units); case TimeframeSymbol.D1: return addTimeUnits_days(date.Proper(timeframe), units); case TimeframeSymbol.H4: case TimeframeSymbol.H1: case TimeframeSymbol.M30: case TimeframeSymbol.M15: case TimeframeSymbol.M5: return addTimeUnits_shortPeriods(date.Proper(timeframe), timeframe, units); } return date; }
public void proper_weeks_for_sundays_the_same_date_is_returned() { DateTime baseDate = new DateTime(2016, 4, 17); Assert.AreEqual(baseDate, baseDate.Proper(TimeframeSymbol.W1)); }
public void proper_weeks_for_dayOfWeek_other_than_sunday_last_sunday_is_returned() { DateTime baseDate = new DateTime(2016, 4, 21); Assert.AreEqual(new DateTime(2016, 4, 17), baseDate.Proper(TimeframeSymbol.W1)); }
public void proper_months_for_other_than_first_day_of_months_first_day_of_this_month_is_returned() { DateTime baseDate = new DateTime(2016, 8, 15); Assert.AreEqual(new DateTime(2016, 8, 1), baseDate.Proper(TimeframeSymbol.MN1)); }
public void proper_months_for_first_day_of_months_the_same_day_is_returned() { DateTime baseDate = new DateTime(2016, 8, 1); Assert.AreEqual(baseDate, baseDate.Proper(TimeframeSymbol.MN1)); }
public void proper_days_for_non_weekend_day_this_day_is_returned() { DateTime baseDate = new DateTime(2016, 4, 18); Assert.AreEqual(baseDate, baseDate.Proper(TimeframeSymbol.D1)); }
public void proper_m5_for_time_between_full_hours_function_returns_earlier_full_hour() { DateTime baseDate = new DateTime(2016, 8, 11, 15, 41, 31); Assert.AreEqual(new DateTime(2016, 8, 11, 15, 40, 0), baseDate.Proper(TimeframeSymbol.M5)); }
private static int countTimeUnits_shortPeriod(DateTime baseDate, DateTime comparedDate, TimeframeSymbol timeframe) { DateTime properBaseDate = baseDate.Proper(timeframe); DateTime properComparedDate = comparedDate.Proper(timeframe); TimeSpan span = getTimespan(timeframe); int spanMinutes = span.Hours * 60 + span.Minutes; long datesMinutesDifference = (properComparedDate - properBaseDate).Ticks / 600000000; int result = (int) datesMinutesDifference / spanMinutes; int excluded = countExcludedItems(baseDate, comparedDate, timeframe); return result - countExcludedItems(baseDate, comparedDate, timeframe); }
public void proper_m5_for_newYearEve_22__21_of_this_day_is_returned() { DateTime baseDate = new DateTime(2015, 12, 31, 22, 0, 0); Assert.AreEqual(new DateTime(2015, 12, 31, 21, 0, 0), baseDate.Proper(TimeframeSymbol.M5)); }
public void proper_m5_for_newYear_value_function_returns_last_valid_value_before() { DateTime baseDate = new DateTime(2016, 1, 1, 16, 0, 0); Assert.AreEqual(new DateTime(2015, 12, 31, 21, 0, 0), baseDate.Proper(TimeframeSymbol.M5)); }
public void proper_m30_for_christmasEve_2130__21_of_this_day_is_returned() { DateTime baseDate = new DateTime(2015, 12, 24, 21, 30, 0); Assert.AreEqual(new DateTime(2015, 12, 24, 21, 0, 0), baseDate.Proper(TimeframeSymbol.M30)); }
public void proper_days_for_weekend_new_year_friday_before_is_returned() { DateTime baseDate = new DateTime(2017, 1, 1); Assert.AreEqual(new DateTime(2016, 12, 30), baseDate.Proper(TimeframeSymbol.D1)); }
public void proper_days_for_sunday_friday_before_is_returned() { DateTime baseDate = new DateTime(2016, 8, 14); Assert.AreEqual(new DateTime(2016, 8, 12), baseDate.Proper(TimeframeSymbol.D1)); }
private static DateTime addTimeUnits_shortPeriods(DateTime date, TimeframeSymbol timeframe, int units) { DateTime startDate = new DateTime(date.Ticks).Proper(timeframe); TimeSpan span = (Math.Sign(units) == 1 ? getTimespan(timeframe) : getTimespan(timeframe).invert()); int sign = Math.Sign(units); for(var i = 1; i <= Math.Abs(units); i++){ startDate = startDate.Add(span); if (!startDate.isOpenMarketTime()) { DateTime nextOpenMarketTime = startDate.ifNotOpenMarketGetNext(); DateTime proper = startDate.Proper(timeframe); startDate = (sign > 0 ? startDate.ifNotOpenMarketGetNext() : startDate.Proper(timeframe)); } } return startDate; }
public void proper_m5_for_weekendNewYear_value_function_returns_2355PM_last_friday_of_previous_year() { DateTime baseDate = new DateTime(2017, 1, 1, 12, 0, 0); Assert.AreEqual(new DateTime(2016, 12, 30, 23, 55, 0), baseDate.Proper(TimeframeSymbol.M5)); }
private static int countTimeUnits_days(DateTime baseDate, DateTime comparedDate) { DateTime realBaseDate = baseDate.Proper(TimeframeSymbol.D1); DateTime realComparedDate = comparedDate.Proper(TimeframeSymbol.D1); int weeks = countTimeUnits_weeks(realBaseDate, realComparedDate); //Include year breaks. int yearBreaks = realBaseDate.countNewYearBreaks(realComparedDate, false); int christmas = realBaseDate.countChristmas(realComparedDate, false); return (realComparedDate - realBaseDate).Days - (weeks * 2) - (yearBreaks + christmas) * (realBaseDate.CompareTo(realComparedDate) < 0 ? 1 : -1); }
public void proper_m5_for_weekend_value_function_returns_last_value_from_this_week() { DateTime baseDate = new DateTime(2016, 8, 13, 16, 15, 0); Assert.AreEqual(new DateTime(2016, 8, 12, 23, 55, 0), baseDate.Proper(TimeframeSymbol.M5)); }
private static int countWeekendItems(DateTime startDate, DateTime endDate, TimeframeSymbol timeframe) { DateTime realStartDate = startDate.Proper(TimeframeSymbol.W1); DateTime realEndDate = endDate.Proper(TimeframeSymbol.W1); int weeks = countTimeUnits_weeks(realStartDate, realEndDate); return weeks * dayUnitsForTimeframe(timeframe) * 2; }
public void proper_m5_if_proper_value_is_passed_the_same_value_is_returned() { DateTime baseDate = new DateTime(2016, 8, 11, 12, 0, 0); Assert.AreEqual(new DateTime(2016, 8, 11, 12, 0, 0), baseDate.Proper(TimeframeSymbol.M5)); }
public static int countTimeUnits(DateTime baseDate, DateTime comparedDate, TimeframeSymbol timeframe) { DateTime properBaseDate = baseDate.Proper(timeframe); DateTime properComparedDate = comparedDate.Proper(timeframe); switch (timeframe) { case TimeframeSymbol.MN1: return countTimeUnits_month(properBaseDate, properComparedDate); case TimeframeSymbol.W1: return countTimeUnits_weeks(properBaseDate, properComparedDate); case TimeframeSymbol.D1: return countTimeUnits_days(properBaseDate, properComparedDate); case TimeframeSymbol.H4: case TimeframeSymbol.H1: case TimeframeSymbol.M30: case TimeframeSymbol.M15: case TimeframeSymbol.M5: return countTimeUnits_shortPeriod(properBaseDate, properComparedDate, timeframe); } return 0; }
public void proper_days_for_newYear_the_day_before_is_returned() { DateTime baseDate = new DateTime(2016, 1, 1); Assert.AreEqual(new DateTime(2015, 12, 31), baseDate.Proper(TimeframeSymbol.D1)); }