コード例 #1
0
        public override bool OnExecution()
        {
            BinanceConnectorNode binanceConnector = this.InParameters["connection"].GetValue() as BinanceConnectorNode;
            var result = binanceConnector.Client.FuturesUsdt.Market.GetKlines(this.InParameters["symbol"].GetValue().ToString(), global::Binance.Net.Enums.KlineInterval.OneHour);

            RSI         rsi      = new RSI(30);
            List <Ohlc> ohlcList = new List <Ohlc>();

            foreach (var candle in result.Data)
            {
                ohlcList.Add(new Ohlc()
                {
                    Date     = candle.CloseTime,
                    Open     = (double)candle.Open,
                    High     = (double)candle.High,
                    Low      = (double)candle.Low,
                    Close    = (double)candle.Close,
                    Volume   = (double)candle.QuoteVolume,
                    AdjClose = 1
                });
            }
            rsi.Load(ohlcList);
            var serie = rsi.Calculate();

            this.OutParameters["RSI"].SetValue(serie.RSI.LastOrDefault());
            return(true);
        }
コード例 #2
0
        public void RSI()
        {
            RSI rsi = new RSI(14);

            rsi.Load(OhlcList);
            RSISerie serie = rsi.Calculate();

            Assert.IsNotNull(serie);
            Assert.IsTrue(serie.RS.Count > 0);
            Assert.IsTrue(serie.RSI.Count > 0);
        }
コード例 #3
0
        public void RSI()
        {
            RSI rsi = new RSI(14);

            rsi.Load(Directory.GetCurrentDirectory() + "\\vas.csv");
            RSISerie serie = rsi.Calculate();

            Assert.IsNotNull(serie);
            //Assert.IsTrue(serie.rsiDataPoint.RS.Count > 0);
            //Assert.IsTrue(serie.rsiDataPoint.RSI.Count > 0);
        }
コード例 #4
0
        public void RSI()
        {
            RSI rsi = new RSI(14);

            rsi.Load(Directory.GetCurrentDirectory() + "\\table.csv");
            RSISerie serie = rsi.Calculate();

            Assert.NotNull(serie);
            Assert.True(serie.RS.Count > 0);
            Assert.True(serie.RSI.Count > 0);
        }
コード例 #5
0
        public void RSI()
        {
            RSI rsi = new RSI(14);

            rsi.Load(csvPath);
            RSISerie serie = rsi.Calculate();

            Assert.NotNull(serie);
            Assert.True(serie.RS.Count > 0);
            Assert.True(serie.RSI.Count > 0);
        }
コード例 #6
0
        private static RSISerie GetRsiSeries(RSI rsi, string stockName)
        {
            string downloadFolderName = ConfigurationManager.AppSettings["downloadLocation"];

            rsi.Load(downloadFolderName + stockName + ".ax.csv");

            RSISerie serie = rsi.Calculate();

            //ExcelUtilities.WriteMacdhistogramDataToExcel(serie, stockName);
            return(serie);
        }
コード例 #7
0
        public Form1()
        {
            InitializeComponent();
            chart1.Series.Clear();
            Int32 timeStampStart = (Int32)(DateTime.UtcNow.AddMonths(-12).Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
            Int32 timeStampNow   = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;

            String yahooAPI = $"https://query1.finance.yahoo.com/v7/finance/download/BTC-EUR?period1={timeStampStart}&period2={timeStampNow}&interval=1d&events=history";

            using (var client = new WebClient())
            {
                client.DownloadFile(yahooAPI, "fileLOG");
            }

            String       csvFile  = @"fileLOG";
            List <Ohlc>  ohlcList = new List <Ohlc>();
            StreamReader r        = new StreamReader(csvFile);
            String       file     = r.ReadToEnd();

            String[] pricesClose = file.Split(new String[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);
            chart1.Series.Add("Price").ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.FastPoint;
            // chart1.Series["Price"].Color = Color.Black;
            int             j     = 0;
            List <DateTime> dates = new List <DateTime>();

            foreach (var s in pricesClose)
            {
                String[] pricesOscillation = s.Split(new String[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                try
                {
                    int      index    = 0;
                    DateTime date     = DateTime.Parse(pricesOscillation[index++]);
                    double   open     = double.Parse(pricesOscillation[index++]);
                    double   high     = double.Parse(pricesOscillation[index++]);
                    double   low      = double.Parse(pricesOscillation[index++]);
                    double   close    = double.Parse(pricesOscillation[index++]);
                    double   adjClose = double.Parse(pricesOscillation[index++]);
                    double   volume   = double.Parse(pricesOscillation[index++]);

                    Ohlc newOhlc = new Ohlc();
                    newOhlc.Open     = open;
                    newOhlc.High     = high;
                    newOhlc.Low      = low;
                    newOhlc.Close    = close;
                    newOhlc.AdjClose = adjClose;
                    newOhlc.Volume   = volume;

                    ohlcList.Add(newOhlc);

                    dates.Add(date);
                    chart1.Series["Price"].Points.AddXY(date, close);
                }
                catch (Exception err)
                {
                }
            }


            BollingerBand bollingerBand = new BollingerBand();

            bollingerBand.Load(ohlcList);
            BollingerBandSerie serie = bollingerBand.Calculate();

            MACD macd = new MACD();

            macd.Load(ohlcList);
            MACDSerie macdserie = macd.Calculate();

            EMA ema = new EMA();

            ema.Load(ohlcList);
            SingleDoubleSerie singleDoubleSerie = ema.Calculate();


            RSI rsi = new RSI(14);

            rsi.Load(ohlcList);
            RSISerie serieRSI = rsi.Calculate();

            chart1.Series.Add("bUP").ChartType           = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            chart1.Series.Add("bDOWN").ChartType         = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            chart1.Series.Add("bMIDDLE").ChartType       = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            chart1.Series.Add("RSI").ChartType           = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            chart1.Series.Add("EMA").ChartType           = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            chart1.Series.Add("MACD").ChartType          = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            chart1.Series.Add("MACDHistogram").ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;

            for (int i = 0; i < serie.BandWidth.Count; i++)
            {
                if (macdserie.MACDLine[i] != null)
                {
                    chart1.Series["MACD"].Points.AddXY(dates[i], macdserie.MACDLine[i]);
                }

                if (macdserie.MACDHistogram[i] != null)
                {
                    chart1.Series["MACDHistogram"].Points.AddXY(dates[i], macdserie.MACDHistogram[i]);
                }

                if (singleDoubleSerie.Values[i] != null)
                {
                    chart1.Series["EMA"].Points.AddXY(dates[i], singleDoubleSerie.Values[i]);
                }

                if (serie.UpperBand[i] != null)
                {
                    chart1.Series["bUP"].Points.AddXY(dates[i], serie.UpperBand[i]);
                }

                if (serie.MidBand[i] != null)
                {
                    chart1.Series["bMIDDLE"].Points.AddXY(dates[i], serie.MidBand[i]);
                }

                if (serie.LowerBand[i] != null)
                {
                    chart1.Series["bDOWN"].Points.AddXY(dates[i], serie.LowerBand[i]);
                }

                if (serieRSI.RSI[i] != null)
                {
                    chart1.Series["RSI"].Points.AddXY(dates[i], serieRSI.RSI[i]);
                }
            }
        }
コード例 #8
0
        public void RSIWithHardCodedValues()
        {
            RSI         rsi      = new RSI(14);
            List <Ohlc> ohlcList = new List <Ohlc>
            {
                new Ohlc {
                    Close = 44.34
                },
                new Ohlc {
                    Close = 44.09
                },
                new Ohlc {
                    Close = 44.15
                },
                new Ohlc {
                    Close = 43.61
                },
                new Ohlc {
                    Close = 44.33
                },
                new Ohlc {
                    Close = 44.83
                },
                new Ohlc {
                    Close = 45.10
                },
                new Ohlc {
                    Close = 45.42
                },
                new Ohlc {
                    Close = 45.84
                },
                new Ohlc {
                    Close = 46.08
                },
                new Ohlc {
                    Close = 45.89
                },
                new Ohlc {
                    Close = 46.03
                },
                new Ohlc {
                    Close = 45.61
                },
                new Ohlc {
                    Close = 46.28
                },
                new Ohlc {
                    Close = 46.28
                },
                new Ohlc {
                    Close = 46.00
                },
                new Ohlc {
                    Close = 46.03
                },
                new Ohlc {
                    Close = 46.41
                },
                new Ohlc {
                    Close = 46.22
                },
                new Ohlc {
                    Close = 45.64
                }
            };

            rsi.Load(ohlcList);
            RSISerie serie = rsi.Calculate();

            Assert.NotNull(serie);

            Assert.True(serie.RS.Count > 0);

            Assert.True(Math.Round(serie.RS[14].Value, 2) == 2.39);
            Assert.True(Math.Round(serie.RS[15].Value, 2) == 1.96);
            Assert.True(Math.Round(serie.RS[16].Value, 2) == 1.98);
            Assert.True(Math.Round(serie.RS[17].Value, 2) == 2.26);
            Assert.True(Math.Round(serie.RS[18].Value, 2) == 1.97);
            Assert.True(Math.Round(serie.RS[19].Value, 2) == 1.38);

            Assert.True(serie.RSI.Count > 0);

            Assert.True(Math.Round(serie.RSI[14].Value, 2) == 70.46);
            Assert.True(Math.Round(serie.RSI[15].Value, 2) == 66.25);
            Assert.True(Math.Round(serie.RSI[16].Value, 2) == 66.48);
            Assert.True(Math.Round(serie.RSI[17].Value, 2) == 69.35);
            Assert.True(Math.Round(serie.RSI[18].Value, 2) == 66.29);
            Assert.True(Math.Round(serie.RSI[19].Value, 2) == 57.92);
        }