public Tendency Classify(DateTime day, CandleTimeSeries series) { AverageDirectionalMovementIndex adx = AverageDirectionalMovementIndex.Create(directionalIndexPeriod, averagePeriod); double adxValue = adx.GetValueAt(series, day.Date); double adxSlope = 0; DateTime previousDay = day.Date.Subtract(TimeSpan.FromDays(1)); bool containsPreviousDayCandle = series.ContainsCandleAt(previousDay); if (containsPreviousDayCandle) { double previousDayAdxValue = adx.GetValueAt(series, previousDay); adxSlope = (adxValue - previousDayAdxValue) / 1; } DirectionalMovementPlus diPlus = DirectionalMovementPlus.Create(); double diPlusValue = diPlus.GetValueAt(series, day.Date); DirectionalMovementMinus diMinus = DirectionalMovementMinus.Create(); double diMinusValue = diMinus.GetValueAt(series, day.Date); if (adxValue >= adxMinimumValue && adxSlope >= 0) { return(diPlusValue > diMinusValue ? Tendency.Up : Tendency.Down); } return(Tendency.Range); }
public static SimpleStrategy Create() { AverageDirectionalMovementIndex indicator = AverageDirectionalMovementIndex.Create(14, 14); ITransaction Function(CandleTimeSeries series, DateTime date) { double d = indicator[series, date]; return(new Transaction()); } return(new SimpleStrategy(Function)); }
public static IEnumerable <(TimeSeries, Color)> GetIndicators(CandleTimeSeries series , int indicatorPeriod , int smoothingPeriod , DateTime?startDate = null) { if (startDate == null) { startDate = series.Candles.Min(candle => candle.Start); } DirectionalIndicatorPlus diPlus = DirectionalIndicatorPlus.Create(indicatorPeriod); TimeSeries diPlusSeries = series.Candles .Where((candle, index) => index > 0 && candle.Start >= startDate) .Select(candle => new DateValue(candle.Start, diPlus[series, candle.Start])) .ToTimeSeries(DiPlusIndicatorName); yield return(diPlusSeries, Color.Blue); DirectionalIndicatorMinus diMinus = DirectionalIndicatorMinus.Create(indicatorPeriod); TimeSeries diMinusSeries = series.Candles .Where((candle, index) => index > 0 && candle.Start >= startDate) .Select(candle => new DateValue(candle.Start, diMinus[series, candle.Start])) .ToTimeSeries(DiMinusIndicatorName); yield return(diMinusSeries, Color.Red); DirectionalMovementIndex dx = DirectionalMovementIndex.Create(indicatorPeriod); TimeSeries dxSeries = series.Candles .Where((candle, index) => index > 0 && candle.Start >= startDate) .Select(candle => new DateValue(candle.Start, dx[series, candle.Start])) .ToTimeSeries(DxIndicatorName); yield return(dxSeries, Color.DarkSlateGray); AverageDirectionalMovementIndex adx = AverageDirectionalMovementIndex.Create(indicatorPeriod, smoothingPeriod); TimeSeries adxSeries = series.Candles .Where((candle, index) => index > 0 && candle.Start >= startDate) .Select(candle => new DateValue(candle.Start, adx[series, candle.Start])) .ToTimeSeries(AdxIndicatorName); yield return(adxSeries, Color.DarkGray); }