using MarketData.Cache;
using MarketData.MarketDataModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MarketData.Generator.CMTrend
{
  public class CMTMACDIndicator
  {
    private CMTMACDIndicator()
    {
    }
    public static bool IsMACDDowntrend(DateTime tradeDate,String symbol,CMTParams parameters)
    {
      Prices prices=GBPriceCache.GetInstance().GetPrices(symbol,tradeDate,parameters.MACDSignalDays*3);
      if(null==prices||!prices[0].Date.Date.Equals(tradeDate.Date)) return true;
      MACDSetup macdSetup=new MACDSetup(parameters.MACDSetup);
      MACDSignals macdSignals=MACDGenerator.GenerateMACD(prices,macdSetup);
      Signals signalsMACD=SignalGenerator.GenerateSignals(macdSignals);
      signalsMACD=new Signals(signalsMACD.Take(parameters.MACDSignalDays).ToList());
      int weakSellSignalCount=(from Signal signal in signalsMACD where signal.IsWeakSell() select signal).Count();
      int strongSellSignalCount=(from Signal signal in signalsMACD where signal.IsStrongSell() select signal).Count();
      if(parameters.MACDRejectWeakSells&&weakSellSignalCount>0) return true;
      if(parameters.MACDRejectStrongSells&&strongSellSignalCount>0) return true;
      return false;
    }
  }
}
