Esempio n. 1
0
        public static TradeStatus AnalyseIndeces(int treshold, DateTime now, MacdAnalysisResult macdAnalysisResult, PeakAnalysisResult lastRsiPeak, TradeStatus macdSlow)
        {
            if (lastRsiPeak == null || macdAnalysisResult.CrossType == null)
            {
                return(TradeStatus.Unknown);
            }

            var minutesSincePeak  = (now - lastRsiPeak.ExitTrade.DateTime).TotalMinutes;
            var minutesSinceCross = (now - macdAnalysisResult.Trade.DateTime).TotalMinutes;

            if (minutesSinceCross > treshold || minutesSincePeak > treshold)
            {
                return(TradeStatus.Unknown);
            }

            if (macdAnalysisResult.CrossType == CrossType.MacdRises && lastRsiPeak.PeakType == PeakType.Low)
            {
                // return macdSlow == TradeStatus.Buy ? TradeStatus.Buy : TradeStatus.Return;
                return(TradeStatus.Buy);
            }

            if (macdAnalysisResult.CrossType == CrossType.MacdFalls && lastRsiPeak.PeakType == PeakType.High)
            {
                //return macdSlow == TradeStatus.Sell ? TradeStatus.Sell : TradeStatus.Borrow;
                return(TradeStatus.Sell);
            }

            return(TradeStatus.Unknown);
        }
Esempio n. 2
0
        public static MacdAnalysisResult MacdAnalysis(this IEnumerable <MacdResultItem> macd)
        {
            var            list        = macd.OrderByDescending(x => x.DateTime).ToList();
            CrossType?     currentType = null;
            MacdResultItem previous    = null;
            var            result      = new MacdAnalysisResult();

            foreach (var item in list)
            {
                if (currentType == null)
                {
                    currentType = item.Macd < item.Signal ? CrossType.MacdFalls : CrossType.MacdRises;
                }

                if (currentType == CrossType.MacdFalls && item.Macd > item.Signal && previous != null)
                {
                    result.CrossType = CrossType.MacdFalls;
                    result.Trade     = new BaseTrade
                    {
                        DateTime = previous.DateTime,
                        Price    = previous.Macd,
                        Volume   = previous.Signal
                    };
                    break;
                }

                if (currentType == CrossType.MacdRises && item.Macd < item.Signal && previous != null)
                {
                    result.CrossType = CrossType.MacdRises;
                    result.Trade     = new BaseTrade
                    {
                        DateTime = previous.DateTime,
                        Price    = previous.Macd,
                        Volume   = previous.Signal
                    };
                    break;
                }
                previous = item;
            }
            return(result);
        }