コード例 #1
0
        public static List <BuySellSignal> SetSignalType(MACDHistogramData mACDHistogramData, List <BuySellSignal> signals)
        {
            if (GetMarketSentiment(mACDHistogramData) == MarketSentiment.Bearish &&
                IsBullishTrendContinuing(mACDHistogramData) /*&& IsTrendEnding(mACDHistogramData)*/ /*&& macdSerie.MACDHistogramDataList.ElementAt(i).EmaLineDifference < -.3*/)
            {
                signals.Add(BuySellSignal.MacdBuyWithUpperLimitSet);
                if (mACDHistogramData.EmaLineDifference < -.3)
                {
                    signals.Add(BuySellSignal.MacdNegativeBelowThree);
                }
            }

            //else if (IsBullishTrendStarting(macdSerie.MACDHistogramDataList.ElementAt(i)))
            //{
            //    macdSerie.MACDHistogramDataList.ElementAt(i).ActionSignal = SignalTypes.BuyWithUpperLimitSet;
            //}
            return(signals);
        }
コード例 #2
0
        private static MarketSentiment GetMarketSentiment(MACDHistogramData mACDHistogramData)
        {
            MarketSentiment marketSentiment = MarketSentiment.Unknown;

            switch (mACDHistogramData.isConvergingOrDiverging)
            {
            case MomentumDirection.NegativeDivergence:
            case MomentumDirection.NegativeConvergence:
            case MomentumDirection.PositiveToNegativeDivergence:
                marketSentiment = MarketSentiment.Bearish;
                break;

            case MomentumDirection.PositiveDivergence:
            case MomentumDirection.PositiveConvergence:
            case MomentumDirection.NegativeToPositiveDivergence:
                marketSentiment = MarketSentiment.Bullish;
                break;
            }
            return(marketSentiment);
        }
コード例 #3
0
        public override MACDSerie Calculate()
        {
            MACDSerie macdSerie = new MACDSerie();

            EMA ema = new EMA(Fast, false);

            ema.Load(OhlcList);
            List <double?> fastEmaValues = ema.Calculate().Values;

            ema = new EMA(Slow, false);
            ema.Load(OhlcList);
            List <double?> slowEmaValues = ema.Calculate().Values;

            for (int i = 0; i < OhlcList.Count; i++)
            {
                // MACD Line
                if (fastEmaValues[i].HasValue && slowEmaValues[i].HasValue)
                {
                    if (!Percent)
                    {
                        macdSerie.MACDLine.Add(fastEmaValues[i].Value - slowEmaValues[i].Value);
                    }
                    else
                    {
                        // macd <- 100 * ( mavg.fast / mavg.slow - 1 )
                        macdSerie.MACDLine.Add(100 * ((fastEmaValues[i].Value / slowEmaValues[i].Value) - 1));
                    }
                    OhlcList[i].Close = macdSerie.MACDLine[i].Value;
                }
                else
                {
                    macdSerie.MACDLine.Add(null);
                    OhlcList[i].Close = 0.0;
                }
            }

            int zeroCount = macdSerie.MACDLine.Where(x => x == null).Count();

            ema = new EMA(Signal, false);
            ema.Load(OhlcList.Skip(zeroCount).ToList());
            List <double?> signalEmaValues = ema.Calculate().Values;

            for (int i = 0; i < zeroCount; i++)
            {
                signalEmaValues.Insert(0, null);
            }

            // Fill Signal and MACD Histogram lists
            for (int i = 0; i < signalEmaValues.Count; i++)
            {
                macdSerie.Signal.Add(signalEmaValues[i]);

                //macdSerie.MACDHistogram.Add(macdSerie.MACDLine[i] - macdSerie.Signal[i]);
                macdSerie.MACDHistogramDataList.Add(new MACDHistogramData()
                {
                    DataDate = OhlcList[i].Date, EmaLineDifference = macdSerie.MACDLine[i] - macdSerie.Signal[i], ClosingValue = OhlcList[i].AdjClose
                });
            }

            /*
             * 1. Difference between MACD and signal line - For plotting histogram
             * 2. Distance between difference - To find the peak-through- slant pattens
             * 3. For decreasing pattern we need to find the point when the decrease intensity reduces
             */
            for (int i = 1; i < macdSerie.MACDHistogramDataList.Count; i++)
            {
                MACDHistogramData currentElement  = macdSerie.MACDHistogramDataList.ElementAt(i);
                MACDHistogramData previousElement = macdSerie.MACDHistogramDataList.ElementAt(i - 1);
                if (
                    currentElement.EmaLineDifference != null &&
                    previousElement.EmaLineDifference != null)
                {
                    SetConvergenceDivergence(previousElement, currentElement);
                    SetChangeInMomentum(previousElement, currentElement);

                    /* For ith Element
                     * (i-1) - (1) < (i-2)-(i-1)
                     */
                    //macdSerie.MACDHistogramDataList.ElementAt(i).isDiffereneAmountDecreasing =
                    //    (
                    //    macdSerie.MACDHistogramDataList.ElementAt(i - 1).EmaLineDifference -
                    //    macdSerie.MACDHistogramDataList.ElementAt(i).EmaLineDifference) <
                    //    (
                    //    macdSerie.MACDHistogramDataList.ElementAt(i - 2).EmaLineDifference -
                    //    macdSerie.MACDHistogramDataList.ElementAt(i - 1).EmaLineDifference
                    //    ) ? true : false;
                    if (currentElement.changeInDivergenceMomentum != null && previousElement.changeInDivergenceMomentum != null)
                    {
                        currentElement.isDiffereneAmountDecreasing =

                            currentElement.changeInDivergenceMomentum.Value <
                            previousElement.changeInDivergenceMomentum.Value;
                    }
                    //SetSignalType(macdSerie.MACDHistogramDataList.ElementAt(i));
                }
            }

            return(macdSerie);
        }
コード例 #4
0
        private void SetConvergenceDivergence(MACDHistogramData previousElement, MACDHistogramData currentElement)
        {
            var currentDataPoint  = currentElement.EmaLineDifference;
            var previousDataPoint = previousElement.EmaLineDifference;

            if (previousDataPoint > 0)
            {
                if (currentDataPoint > 0)
                {
                    if (currentDataPoint > previousDataPoint)
                    {
                        currentElement.isConvergingOrDiverging = MomentumDirection.PositiveDivergence;
                    }
                    else if (currentDataPoint < previousDataPoint)
                    {
                        currentElement.isConvergingOrDiverging = MomentumDirection.PositiveConvergence;
                    }
                }
                else if (currentDataPoint == 0)
                {
                    currentElement.isConvergingOrDiverging = MomentumDirection.PositiveConvergence;;
                }
                else if (currentDataPoint < 0)
                {
                    currentElement.isConvergingOrDiverging = MomentumDirection.PositiveToNegativeDivergence;
                }
            }
            else if (previousDataPoint == 0)
            {
                if (currentDataPoint > 0)
                {
                    currentElement.isConvergingOrDiverging = MomentumDirection.PositiveDivergence;
                }
                else if (currentDataPoint == 0)
                {
                    currentElement.isConvergingOrDiverging = MomentumDirection.NoChange;
                }
                else if (currentDataPoint < 0)
                {
                    currentElement.isConvergingOrDiverging = MomentumDirection.NegativeDivergence;
                }
            }
            else if (previousDataPoint < 0)
            {
                if (currentDataPoint > 0)
                {
                    currentElement.isConvergingOrDiverging = MomentumDirection.NegativeToPositiveDivergence;
                }
                else if (currentDataPoint == 0)
                {
                    currentElement.isConvergingOrDiverging = MomentumDirection.NegativeConvergence;
                }
                else if (currentDataPoint < 0)
                {
                    if (currentDataPoint > previousDataPoint)
                    {
                        currentElement.isConvergingOrDiverging = MomentumDirection.NegativeConvergence;;
                    }
                    else if (currentDataPoint < previousDataPoint)
                    {
                        currentElement.isConvergingOrDiverging = MomentumDirection.NegativeDivergence;
                    }
                }
            }
        }
コード例 #5
0
 private void SetChangeInMomentum(MACDHistogramData previousElement, MACDHistogramData currentElement)
 {
     currentElement.changeInDivergenceMomentum = Math.Abs(previousElement.EmaLineDifference.Value - currentElement.EmaLineDifference.Value);
 }
コード例 #6
0
 private static bool IsTrendEnding(MACDHistogramData mACDHistogramData)
 {
     return(mACDHistogramData.isDiffereneAmountDecreasing);
 }
コード例 #7
0
 private static bool IsBullishTrendContinuing(MACDHistogramData mACDHistogramData)
 {
     return(mACDHistogramData.isConvergingOrDiverging == MomentumDirection.NegativeDivergence ||
            mACDHistogramData.isConvergingOrDiverging == MomentumDirection.PositiveToNegativeDivergence);
 }
コード例 #8
0
 private static bool IsBullishTrendStarting(MACDHistogramData currentElement)
 {
     return(currentElement.isConvergingOrDiverging == MomentumDirection.PositiveToNegativeDivergence);
 }