// where fileSubPath like @"\Binance\BTCUSDT-12h-20210211-102146.csv" // where timePeriod like 7 static void CreateCsvCryptoTA(string fileSubPath, int timePeriod = 14) { var csvFilepath = Path.Join($"{rootDataPath}", fileSubPath); var csv = new Csv(new Uri(csvFilepath)); var time = csv.ColumnData <string>("OpenTime"); var close = csv.ColumnData <decimal>("Close"); var ta = new TechnicalAnalysis(close); var rvRsi = ta.Rsi(timePeriod); var rsi = rvRsi.Values; var rvRoc = ta.Roc(timePeriod); var roc = rvRoc.Values; var rvMacd = ta.Macd(); var macd = rvMacd.Values; var filepath = $"{rootDataPath}\\ta{timePeriod}.csv"; using (var f = new StreamWriter(filepath)) { f.Write("OpenTime,Close,RSI,ROC%,MACDHist\n"); for (int i = 0; i < close.Count; ++i) { f.Write("{0},{1},{2:n2},{3:n2},{4:n2}", nullZero(time, i), nullZero(close, i), nullZero(rsi, i), nullZero(roc, i), nullZero(macd, i)); if (i < close.Count - 1) { f.Write("\n"); } } f.Flush(); } }
// where csvFilepath like @"C:\Users\mhatm\Downloads\data\BTCUSDT-1d-20210208-070457.csv" static void DemoCsvTA1(string csvFilepath) { // Read from historical: Prices in csv are OLDEST to NEWEST var csvUri = new Uri(csvFilepath); var hist = new Csv(csvUri, reverseOrder: true); Console.WriteLine(hist.Headers); //var str = hist["Close"]; //Console.WriteLine("{0} {1} {2}", str[0], str[1], str[2]); var closes = hist.ColumnData <decimal>("Close"); var highs = hist.ColumnData <decimal>("High"); var lows = hist.ColumnData <decimal>("Low"); //var closes = new List<decimal>() { 109, 108, 107, 106, 105, 104, 103, 102, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120 }; //PrintColumnData(closes); //var ta = new TechnicalAnalysis(closes); var ta = new TechnicalAnalysis(closes, highs, lows); var rvRsi = ta.Rsi(14); var rsi = rvRsi.Values; var rvRoc = ta.Roc(14); var roc = rvRoc.Values; var rvMacd = ta.Macd(); var macd = rvMacd.Values; for (int i = 0; i < closes.Count; ++i) { Console.WriteLine("{0} {1:n2} {2:n2} % {3:n2}", i < closes.Count ? closes[i] : 0, i < rsi.Count ? rsi[i] : 0, i < roc.Count ? roc[i] : 0, i < macd.Count ? macd[i] : 0); } }
// where code like "CME_MGC1" // where timePeriod like 7 static void CreateCsvContinuousFuturesTA(string code, int timePeriod = 14) { var cfDir = $"{rootDataPath}\\Quandl\\ContinuousFutures"; var csv = new Csv(new Uri($"{cfDir}\\{code}.csv")); var date = csv.ColumnData <string>("Date"); var settle = csv.ColumnData <decimal>("Settle"); var ta = new TechnicalAnalysis(settle); var rvRsi = ta.Rsi(timePeriod); var rsi = rvRsi.Values; var rvRoc = ta.Roc(timePeriod); var roc = rvRoc.Values; var rvMacd = ta.Macd(); var macd = rvMacd.Values; var filepath = $"{rootDataPath}\\ta{timePeriod}.csv"; using (var f = new StreamWriter(filepath)) { f.Write("Date,Settle,RSI,ROC%,MACDHist\n"); for (int i = 0; i < settle.Count; ++i) { f.Write("{0},{1},{2:n2},{3:n2},{4:n2}", nullZero(date, i), nullZero(settle, i), nullZero(rsi, i), nullZero(roc, i), nullZero(macd, i)); if (i < settle.Count - 1) { f.Write("\n"); } } f.Flush(); } }