public static void WriteMacdhistogramDataToExcel(MACDSerie mACDSerie, RSISerie rsiSeries, SingleDoubleSerieV2 shorttermSingleDoubleSerieV2, SingleDoubleSerieV2 longtermSingleDoubleSerieV2, string sheetName) { var subset = mACDSerie.MACDHistogramDataList.GetRange(mACDSerie.MACDHistogramDataList.Count - 60, 60); //Search For the template file XSSFWorkbook workbook; string excelFile = sheetName + "Data.xlsx"; File.Delete(excelFile); // File.Copy(@"MacdHDataTemplate.xlsx", excelFile); using (FileStream file = new FileStream(@"MacdHDataTemplate.xlsx", FileMode.Open, FileAccess.Read)) { workbook = new XSSFWorkbook(file); ISheet sheet = workbook.GetSheet("template"); //sheet = sheet.CopySheet(sheetName); // sheet = workbook.CloneSheet(workbook.IndexOf(sheet)); int i = 1; foreach (var item in subset) { List <BuySellSignal> signals = new List <BuySellSignal>(); signals = MACD.SetSignalType(item, signals); var row = sheet.CreateRow(i); var rsiData = rsiSeries.rsiDataPoints.Where(x => x.Date == item.DataDate).FirstOrDefault(); var shortTermSingleDoubleSeriesData = shorttermSingleDoubleSerieV2.Values.Where(x => x.date == item.DataDate).FirstOrDefault(); var longTermSingleDoubleSeriesData = longtermSingleDoubleSerieV2.Values.Where(x => x.date == item.DataDate).FirstOrDefault(); shortTermSingleDoubleSeriesData.findSignals(longTermSingleDoubleSeriesData, signals, item.ClosingValue); row.CreateCell(0).SetCellValue(item.DataDate.Date.ToString("dd/MM/yyyy")); row.CreateCell(1).SetCellValue(item.isConvergingOrDiverging.ToString()); row.CreateCell(2).SetCellValue(item.EmaLineDifference.Value); row.CreateCell(3).SetCellValue(item.changeInDivergenceMomentum.Value); row.CreateCell(4).SetCellValue(item.isDiffereneAmountDecreasing); //if (rsiData != null) //{ // row.CreateCell(5).SetCellValue(rsiData.RS.Value); // row.CreateCell(6).SetCellValue(rsiData.RSI.Value); //} if (longTermSingleDoubleSeriesData != null && shortTermSingleDoubleSeriesData != null) { row.CreateCell(7).SetCellValue(shortTermSingleDoubleSeriesData.data.Value); row.CreateCell(8).SetCellValue(longTermSingleDoubleSeriesData.data.Value); row.CreateCell(9).SetCellValue(shortTermSingleDoubleSeriesData.data.Value < longTermSingleDoubleSeriesData.data.Value); } row.CreateCell(10).SetCellValue(item.ClosingValue); row.CreateCell(11).SetCellValue(string.Join(Environment.NewLine, signals.ToArray())); i++; } } using (FileStream file = new FileStream(excelFile, FileMode.CreateNew, FileAccess.Write)) { workbook.Write(file); file.Close(); } //Write to specific Rows in the excel file }
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); }
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); }
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); }
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); }
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); }
static void Main(string[] args) { DownloadAllStockFiles(); string[] stockNames = ConfigurationManager.AppSettings["StockNames"].Split(','); foreach (var stockName in stockNames) { MACD macd = new MACD(false); MACDSerie macdSeries = GetMacdSeries(macd, stockName); RSI rsi = new RSI(14); RSISerie rsiSeries = GetRsiSeries(rsi, stockName); SMAV2 shortTermSma = new SMAV2(14); SingleDoubleSerieV2 shorttermSingleDoubleSerieV2 = GetSingleDoubleSeriesV2(shortTermSma, stockName); SMAV2 longTermSma = new SMAV2(60); SingleDoubleSerieV2 longtermSingleDoubleSerieV2 = GetSingleDoubleSeriesV2(longTermSma, stockName); ExcelUtilities.WriteMacdhistogramDataToExcel(macdSeries, rsiSeries, shorttermSingleDoubleSerieV2, longtermSingleDoubleSerieV2, stockName); } }
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]); } } }
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); }