List <double> GetMA(List <IMarketData> marketDataList, int n)
        {
            try
            {
                var      valueList = new List <double>();
                int      begin     = 0;
                int      rlength   = 0;
                int      rbegin    = 0;
                double[] values    = new double[marketDataList.Count];
                var      dataList  = marketDataList.Select(v => v.Close).ToArray();
                Core.Sma(begin, marketDataList.Count - 1, dataList, n, out rbegin, out rlength, values);
                valueList = values.ToList();
                CommonProc.TrimDoubleList(valueList);
                if (IsAnalyse)
                {
                    if (valueList.Count > 0)
                    {
                        var o = new TimeValueObject()
                        {
                            Name = Name, Value = valueList.LastOrDefault()
                        };
                        o.Time = marketDataList.LastOrDefault().Time;
                        AddReference(n.ToString(), o);
                    }
                }

                return(valueList);
            }
            catch (Exception ex)
            {
                LogSupport.Error(ex);
                throw ex;
            }
        }
Beispiel #2
0
        protected override ISignal Calculate(IInstrument instrument, DateTime startTime, DateTime endTime, MarketDataGrade?grade)
        {
            isSignalBiggerMeansBetter = true;
            if (grade == null)
            {
                grade = Grade;
            }
            try
            {
                var dl  = AnalyseDataSource.GetDataList(instrument, startTime, endTime, grade.Value);
                var RSI = new double[dl.Count];

                int bindex;
                int element;

                Core.Rsi(0, dl.Count - 1, dl.Select(p => p.Close).ToArray(),
                         Period, out bindex, out element, RSI);
                var valueList = RSI.ToList();
                CommonProc.TrimDoubleList(valueList);
                if (IsAnalyse)
                {
                    //if (!AnalyseValueList.ContainsKey("RSI"))
                    //{
                    //    AnalyseValueList.Add("RSI", new List<TimeValueObject>());
                    //}


                    if (valueList.Count > 0)
                    {
                        //AddSignal(instrument, dl.Max(v => v.Time), valueList.LastOrDefault(), dl.LastOrDefault().Close, "RSI", SignalType.Analyse);
                        var obj = new TimeValueObject()
                        {
                            Name = Name, Value = valueList.LastOrDefault()
                        };
                        obj.Time = dl.Max(v => v.Time);
                        AddReference("RSI", obj);
                        //AnalyseValueList["RSI"].Add(obj);
                        //var dif = dl.Count - valueList.Count;
                        //for (int i = valueList.Count - 1; i >= 0; i--)
                        //{

                        //    var o = new TimeValueObject() { Name = Name, Value = valueList[i] };
                        //    o.Time = dl[dif + i].Time;
                        //    AddReference("RSI", o);
                        //}
                    }
                }
                //var o = new TimeValueObject() { Name = Name, Time = endTime, Value = null };
                //o.Time = dl.Max(v => v.Time);
                //o.Value = RSI.ToArray().LastOrDefault();
                return(CreateSignal(instrument, dl.Max(v => v.Time), RSI.ToArray().LastOrDefault(), dl.LastOrDefault().Close));
            }
            catch (Exception e)
            {
                LogSupport.Error(e);
            }
            return(null);
        }
Beispiel #3
0
        List <double> GetMA(List <IMarketData> marketDataList, int n)
        {
            try
            {
                var valueList = new List <double>();
                int begin     = 0;
                int rlength   = 0;
                int rbegin    = 0;
                //if (MarketDataList.Count > n) { begin = MarketDataList.Count - n; }
                double[] values   = new double[marketDataList.Count];
                var      dataList = marketDataList.Select(v => v.Close).ToArray();
                Core.Sma(begin, marketDataList.Count - 1, dataList, n, out rbegin, out rlength, values);
                valueList = values.ToList();
                CommonProc.TrimDoubleList(valueList);
                if (IsAnalyse)
                {
                    //if (!AnalyseValueList.ContainsKey(n.ToString()))
                    //{
                    //    AnalyseValueList.Add(n.ToString(), new List<TimeValueObject>());
                    //}


                    if (valueList.Count > 0)
                    {
                        //var data = marketDataList.FirstOrDefault();
                        //AddSignal(data.InstrumentTicker, marketDataList.Max(v => v.Time), valueList.LastOrDefault(), marketDataList.LastOrDefault().Close, n.ToString(), SignalType.Analyse);
                        //var dif = marketDataList.Count - valueList.Count;
                        //for (int i =  valueList.Count-1 ;i>=0; i--)
                        //{

                        var o = new TimeValueObject()
                        {
                            Name = Name, Value = valueList.LastOrDefault()
                        };
                        o.Time = marketDataList.LastOrDefault().Time;
                        AddReference(n.ToString(), o);
                        //}
                    }
                }

                //for (int i = 0; i < values.Length - n + 1; i++)
                //{

                //    valueList.Add(values[i]);
                //}
                return(valueList);
            }
            catch (Exception ex)
            {
                LogSupport.Error(ex);
                throw ex;
            }
        }
Beispiel #4
0
 List <double> GetMA(List <IMarketData> marketDataList, int n)
 {
     try
     {
         var valueList = new List <double>();
         int begin     = 0;
         int rlength   = 0;
         int rbegin    = 0;
         //if (MarketDataList.Count > n) { begin = MarketDataList.Count - n; }
         double[] values   = new double[marketDataList.Count];
         var      dataList = marketDataList.Select(v => v.Volume).ToArray();
         Core.Sma(begin, marketDataList.Count - 1, dataList, n, out rbegin, out rlength, values);
         var l = values.ToList <double>();
         CommonProc.TrimDoubleList(l);
         return(l);
     }
     catch (Exception ex)
     {
         LogSupport.Error(ex);
         throw ex;
     }
 }
Beispiel #5
0
        protected override ISignal Calculate(IInstrument instrument, DateTime startTime, DateTime endTime, MarketDataGrade?grade)
        {
            isSignalBiggerMeansBetter = true;
            if (grade == null)
            {
                grade = Grade;
            }
            try
            {
                var dl = GetMarketData(instrument, startTime, endTime, grade.Value);
                if (dl.Count == 0)
                {
                    return(null);
                }
                var macd       = new double[dl.Count];
                var macdhis    = new double[dl.Count];
                var macdsignal = new double[dl.Count];
                int bindex;
                int element;

                Core.Macd(0, dl.Count - 1, dl.Select(p => p.Close).ToArray(), FastPeriod, SlowPeriod, SignalPeriod, out bindex, out element, macd, macdsignal, macdhis);
                var signal = macdsignal.ToList();
                CommonProc.TrimDoubleList(signal);
                if (IsAnalyse)
                {
                    var macdList = macd.ToList();
                    CommonProc.TrimDoubleList(macdList);
                    var his = macdhis.ToList();
                    CommonProc.TrimDoubleList(his);
                    //if (!AnalyseValueList.ContainsKey("MACD"))
                    //{
                    //    AnalyseValueList.Add("MACD", new List<TimeValueObject>());
                    //}
                    //if (!AnalyseValueList.ContainsKey("Signal"))
                    //{
                    //    AnalyseValueList.Add("Signal", new List<TimeValueObject>());
                    //}
                    //if (!AnalyseValueList.ContainsKey("His"))
                    //{
                    //    AnalyseValueList.Add("His", new List<TimeValueObject>());
                    //}
                    if (macdList.Count > 0)
                    {
                        //AddSignal(instrument, dl.Max(v => v.Time), macdList.LastOrDefault(), dl.LastOrDefault().Close, "MACD", SignalType.Analyse);
                        //var dif = dl.Count - macdList.Count;
                        //for (int i = macdList.Count - 1; i >= 0; i--)
                        //{

                        //    var o = new TimeValueObject() { Name = Name, Value = macdList[i] };
                        //    o.Time = dl[dif + i].Time;
                        //    AddReference("MACD", o);
                        //}
                        var o = new TimeValueObject()
                        {
                            Name = Name, Value = macdList.LastOrDefault()
                        };
                        o.Time = dl.Max(v => v.Time);
                        AddReference("MACD", o);
                    }
                    if (signal.Count > 0)
                    {
                        //var dif = dl.Count - signal.Count;
                        //for (int i = signal.Count - 1; i >= 0; i--)
                        //{

                        //    var o = new TimeValueObject() { Name = Name, Value = signal[i] };
                        //    o.Time = dl[dif + i].Time;
                        //    AddReference("Signal", o);
                        //}
                        //AddSignal(instrument, dl.Max(v => v.Time), signal.LastOrDefault(), dl.LastOrDefault().Close, "Signal", SignalType.Analyse);
                        var o = new TimeValueObject()
                        {
                            Name = Name, Value = signal.LastOrDefault()
                        };
                        o.Time = dl.Max(v => v.Time);
                        AddReference("Signal", o);
                        //AnalyseValueList["Signal"].Add(o);
                    }
                    if (his.Count > 0)
                    {
                        //var dif = dl.Count - his.Count;
                        //for (int i = his.Count - 1; i >= 0; i--)
                        //{

                        //    var o = new TimeValueObject() { Name = Name, Value = his[i] };
                        //    o.Time = dl[dif + i].Time;
                        //    AddReference("His", o);
                        //}
                        //AddSignal(instrument, dl.Max(v => v.Time), his.LastOrDefault(), dl.LastOrDefault().Close, "His", SignalType.Analyse);
                        var o = new TimeValueObject()
                        {
                            Name = Name, Value = his.LastOrDefault()
                        };
                        o.Time = dl.Max(v => v.Time);
                        AddReference("His", o);
                        //AnalyseValueList["His"].Add(o);
                    }
                }
                if (signal.Count > 1 && signal[signal.Count - 2] < 0 && signal[signal.Count - 1] > 0)
                {
                    //var o = new TimeValueObject() { Name = Name, Time = dl.Max(v=>v.Time), Value = null };
                    //o.Value = signal[signal.Count - 1] - signal[signal.Count - 2];

                    //return o;
                    return(CreateSignal(instrument, dl.Max(v => v.Time), signal[signal.Count - 1] - signal[signal.Count - 2], dl.LastOrDefault().Close));
                }
            }
            catch (Exception e)
            {
                //LogSupport.Error(e);
            }
            return(null);
        }
Beispiel #6
0
        protected override ISignal Calculate(IInstrument instrument, DateTime startTime, DateTime endTime, MarketDataGrade?grade)
        {
            isSignalBiggerMeansBetter = true;
            if (grade == null)
            {
                grade = Grade;
            }
            try
            {
                var dl    = AnalyseDataSource.GetDataList(instrument, startTime, endTime, grade.Value);
                var slowK = new double[dl.Count];
                var slowD = new double[dl.Count];

                int bindex;
                int element;

                Core.Stoch(0, dl.Count - 1, dl.Select(p => p.High).ToArray(), dl.Select(p => p.Low).ToArray(), dl.Select(p => p.Close).ToArray(),
                           FastKPeriod, SlowKPeriod, SlowKType, SlowDPeriod, SlowDType, out bindex, out element, slowK, slowD);
                var skl = slowK.ToList <double>();
                var sdl = slowD.ToList <double>();
                CommonProc.TrimDoubleList(skl);
                CommonProc.TrimDoubleList(sdl);
                if (IsAnalyse)
                {
                    //if (!AnalyseValueList.ContainsKey("K"))
                    //{
                    //    AnalyseValueList.Add("K", new List<TimeValueObject>());
                    //}
                    //if (!AnalyseValueList.ContainsKey("D"))
                    //{
                    //    AnalyseValueList.Add("D", new List<TimeValueObject>());
                    //}
                    if (skl.Count > 0)
                    {
                        //var dif = dl.Count - skl.Count;
                        //for (int i = skl.Count - 1; i >= 0; i--)
                        //{

                        //    var o = new TimeValueObject() { Name = Name, Value = skl[i] };
                        //    o.Time = dl[dif + i].Time;
                        //    AddReference("K", o);
                        //}
                        var o = new TimeValueObject()
                        {
                            Name = Name, Value = skl.LastOrDefault()
                        };
                        o.Time = dl.Max(v => v.Time);
                        AddReference("K", o);
                        //AddSignal(instrument, dl.Max(v => v.Time), skl.LastOrDefault(), dl.LastOrDefault().Close, "K", SignalType.Analyse);
                        //AnalyseValueList["K"].Add(o);
                    }
                    if (sdl.Count > 0)
                    {
                        //var dif = dl.Count - sdl.Count;
                        //for (int i = skl.Count - 1; i >= 0; i--)
                        //{

                        //    var o = new TimeValueObject() { Name = Name, Value = sdl[i] };
                        //    o.Time = dl[dif + i].Time;
                        //    AddReference("D", o);
                        //}
                        var o = new TimeValueObject()
                        {
                            Name = Name, Value = sdl.LastOrDefault()
                        };
                        o.Time = dl.Max(v => v.Time);
                        AddReference("D", o);
                        //AnalyseValueList["D"].Add(o);
                        //AddSignal(instrument, dl.Max(v => v.Time), sdl.LastOrDefault(), dl.LastOrDefault().Close, "D", SignalType.Analyse);
                    }
                }
                if (skl[skl.Count - 2] < skl[skl.Count - 1] && sdl[sdl.Count - 2] < sdl[sdl.Count - 1])//current K,D increase
                {
                    return(CreateSignal(instrument, dl.Max(v => v.Time), ((skl[skl.Count - 1] - skl[skl.Count - 2]) + (sdl[sdl.Count - 1] - sdl[sdl.Count - 2])) / 2d, dl.LastOrDefault().Close));
                    //var o = new TimeValueObject() { Name = Name, Time = endTime, Value = null };
                    //o.Time = dl.Max(v => v.Time);
                    //o.Value= ((skl[skl.Count - 1] - skl[skl.Count - 2]) + (sdl[sdl.Count - 1] - sdl[sdl.Count - 2])) / 2d;
                    //return o;
                }
            }
            catch (Exception e)
            {
                LogSupport.Error(e);
            }
            return(null);
        }