Ejemplo n.º 1
0
        public static List <decimal?> Mfi(this IEnumerable <ICandle> candles, int?period = null)
        {
            period ??= 14;

            IIndicatorOptions options = new MfiOptions(period.Value);
            Mfi mfi = new Mfi();

            return(mfi.Get(candles, options));
        }
        internal static TradeIdeasGeneratorArgument Create(List <Signal> signals, HistoricalData historicalData)
        {
            TradeIdeasGeneratorArgument result = new TradeIdeasGeneratorArgument();

            SmaVol smaVol20 = new SmaVol(20);
            Sma    sma50    = new Sma(50);
            Rsi    stRsi5   = new Rsi(5);
            Rsi    rsi14    = new Rsi(14);
            Rsi    ltrsi50  = new Rsi(50);
            Cci    stCci5   = new Cci(5);
            Cci    cci14    = new Cci(14);
            Cci    ltCci50  = new Cci(50);
            Stoch  stoch14  = new Stoch(14, 14, 3);
            WillR  willr14  = new WillR(14);
            Mfi    mfi14    = new Mfi(14);
            Adx    adx20    = new Adx(20);
            Atr    atr20    = new Atr(20);

            //Assuming that signals are sorted by dates descending and all signals are present. otherwize an exception will be thrown during fetching signals (First())

            #region Indicators

            result.Rsi14           = GetValue(signals.LatestForIndicator(rsi14));
            result.YesterdayRsi14  = GetValue(signals.PreviousForIndicator(rsi14, 1));
            result.StRsi5          = GetValue(signals.LatestForIndicator(stRsi5));
            result.YesterdayStRsi5 = GetValue(signals.PreviousForIndicator(stRsi5, 1));
            result.LtRsi50         = GetValue(signals.LatestForIndicator(ltrsi50));

            result.Cci14           = GetValue(signals.LatestForIndicator(cci14));
            result.YesterdayCci14  = GetValue(signals.PreviousForIndicator(cci14, 1));
            result.StCci5          = GetValue(signals.LatestForIndicator(stCci5));
            result.YesterdayStCci5 = GetValue(signals.PreviousForIndicator(stCci5, 1));
            result.LtCci50         = GetValue(signals.LatestForIndicator(ltCci50));

            result.Stoch14          = GetValue(signals.LatestForIndicator(stoch14));
            result.YesterdayStoch14 = GetValue(signals.PreviousForIndicator(stoch14, 1));

            result.WillR14          = GetValue(signals.LatestForIndicator(willr14));
            result.YesterdayWillR14 = GetValue(signals.PreviousForIndicator(willr14, 1));

            result.Mfi14          = GetValue(signals.LatestForIndicator(mfi14));
            result.YesterdayMfi14 = GetValue(signals.PreviousForIndicator(mfi14, 1));

            result.SmaVol20 = GetValue(signals.LatestForIndicator(smaVol20));
            result.Sma50    = GetValue(signals.LatestForIndicator(sma50));

            result.Adx20 = GetValue(signals.LatestForIndicator(adx20));

            result.Atr20 = GetValue(signals.LatestForIndicator(atr20));

            //Long Term Sentiment(6 months)
            Signal syrahSentiment = signals.LatestForIndicator(LongTermSentimentForDependencies);
            int?   sentimentValue = syrahSentiment == null
                ? null
                : (int?)syrahSentiment.Value;
            result.LongTermSentiment = SyrahSentiment.MakeInterpretationInTermsOfSentiment(sentimentValue);

            //Short Term Sentiment(1 month)
            syrahSentiment = signals.LatestForIndicator(ShortTermSentimentForDependencies);
            sentimentValue = syrahSentiment == null
                ? null
                : (int?)syrahSentiment.Value;
            result.ShortTermSentiment = SyrahSentiment.MakeInterpretationInTermsOfSentiment(sentimentValue);

            #endregion

            //if (expandedQuote == null)
            //{
            //    result.LastPrice = historicalData.Close[historicalData.Count - 1];
            //}
            //else
            //{
            //    result.LastPrice = expandedQuote.Last;
            //    result.HasOption = expandedQuote.HasOption;
            //}

            result.RangeStdDev = historicalData.GetPriceRangeStdDevFor6Months();

            //result.NearestSupport = supportAndResistance.GetClosestSupport(expandedQuote.Last);
            //result.NearestResistance = supportAndResistance.GetClosestResistance(expandedQuote.Last);

            //TODO: check
            int yesterdayIndex = historicalData.High.Length - 2;
            result.YesterdayHigh = historicalData.High[yesterdayIndex];
            result.YesterdayLow  = historicalData.Low[yesterdayIndex];

            return(result);
        }