public void ValueLessThenTimeFrame() { var wr = new WilliamsRIndicator(new ClosePriceIndicator(_data), 100, new MaxPriceIndicator(_data), new MinPriceIndicator(_data)); TaTestsUtils.AssertDecimalEquals(wr.GetValue(0), -100d * (0.12 / 0.21)); TaTestsUtils.AssertDecimalEquals(wr.GetValue(1), -100d * (0.07 / 0.21)); TaTestsUtils.AssertDecimalEquals(wr.GetValue(2), -100d * (0.13 / 0.36)); TaTestsUtils.AssertDecimalEquals(wr.GetValue(3), -100d * (0.18 / 0.36)); }
public void WilliamsRUsingTimeFrame10UsingClosePrice() { var wr = new WilliamsRIndicator(new ClosePriceIndicator(_data), 10, new MaxPriceIndicator(_data), new MinPriceIndicator(_data)); TaTestsUtils.AssertDecimalEquals(wr.GetValue(9), -4.0816); TaTestsUtils.AssertDecimalEquals(wr.GetValue(10), -11.7647); TaTestsUtils.AssertDecimalEquals(wr.GetValue(11), -8.9286); TaTestsUtils.AssertDecimalEquals(wr.GetValue(12), -10.5263); }
public void valueLessThenTimeFrame() { WilliamsRIndicator wr = new WilliamsRIndicator(new ClosePriceIndicator(data), 100, new MaxPriceIndicator(data), new MinPriceIndicator(data)); Assert.AreEqual(-100M * (0.12M / 0.21M), wr.GetValue(0)); Assert.AreEqual(-100M * (0.07M / 0.21M), wr.GetValue(1)); Assert.AreEqual(-100M * (0.13M / 0.36M), wr.GetValue(2)); Assert.AreEqual(-100M * (0.18M / 0.36M), wr.GetValue(3)); }
public void williamsRUsingTimeFrame10UsingClosePrice() { WilliamsRIndicator wr = new WilliamsRIndicator(new ClosePriceIndicator(data), 10, new MaxPriceIndicator(data), new MinPriceIndicator(data)); Assert.AreEqual(wr.GetValue(9), -4.0816326530612244897959183700M); Assert.AreEqual(wr.GetValue(10), -11.764705882352941176470588240M); Assert.AreEqual(wr.GetValue(11), -8.928571428571428571428571430M); Assert.AreEqual(wr.GetValue(12), -10.526315789473684210526315790M); }
public void WilliamsRUsingTimeFrame5UsingClosePrice() { var wr = new WilliamsRIndicator(new ClosePriceIndicator(_data), 5, new MaxPriceIndicator(_data), new MinPriceIndicator(_data)); TaTestsUtils.AssertDecimalEquals(wr.GetValue(4), -47.2222); TaTestsUtils.AssertDecimalEquals(wr.GetValue(5), -54.5454); TaTestsUtils.AssertDecimalEquals(wr.GetValue(6), -78.5714); TaTestsUtils.AssertDecimalEquals(wr.GetValue(7), -47.6190); TaTestsUtils.AssertDecimalEquals(wr.GetValue(8), -25d); TaTestsUtils.AssertDecimalEquals(wr.GetValue(9), -5.2632); TaTestsUtils.AssertDecimalEquals(wr.GetValue(10), -13.9535); }
public void williamsRUsingTimeFrame5UsingClosePrice() { WilliamsRIndicator wr = new WilliamsRIndicator(new ClosePriceIndicator(data), 5, new MaxPriceIndicator(data), new MinPriceIndicator(data)); Assert.AreEqual(wr.GetValue(4), -47.222222222222222222222222220M); Assert.AreEqual(wr.GetValue(5), -54.545454545454545454545454550M); Assert.AreEqual(wr.GetValue(6), -78.571428571428571428571428570M); Assert.AreEqual(wr.GetValue(7), -47.619047619047619047619047620M); Assert.AreEqual(wr.GetValue(8), -25M); Assert.AreEqual(wr.GetValue(9), -5.2631578947368421052631578900M); Assert.AreEqual(wr.GetValue(10), -13.953488372093023255813953490M); }
public static void Main(string[] args) { /// <summary> /// Getting time series /// </summary> TimeSeries series = CsvTradesLoader.loadBitstampSeries(); /// <summary> /// Creating indicators /// </summary> // Close price ClosePriceIndicator closePrice = new ClosePriceIndicator(series); // Typical price TypicalPriceIndicator typicalPrice = new TypicalPriceIndicator(series); // Price variation PriceVariationIndicator priceVariation = new PriceVariationIndicator(series); // Simple moving averages SMAIndicator shortSma = new SMAIndicator(closePrice, 8); SMAIndicator longSma = new SMAIndicator(closePrice, 20); // Exponential moving averages EMAIndicator shortEma = new EMAIndicator(closePrice, 8); EMAIndicator longEma = new EMAIndicator(closePrice, 20); // Percentage price oscillator PPOIndicator ppo = new PPOIndicator(closePrice, 12, 26); // Rate of change ROCIndicator roc = new ROCIndicator(closePrice, 100); // Relative strength index RSIIndicator rsi = new RSIIndicator(closePrice, 14); // Williams %R WilliamsRIndicator williamsR = new WilliamsRIndicator(series, 20); // Average true range AverageTrueRangeIndicator atr = new AverageTrueRangeIndicator(series, 20); // Standard deviation StandardDeviationIndicator sd = new StandardDeviationIndicator(closePrice, 14); /// <summary> /// Building header /// </summary> StringBuilder sb = new StringBuilder("timestamp,close,typical,variation,sma8,sma20,ema8,ema20,ppo,roc,rsi,williamsr,atr,sd\n"); /// <summary> /// Adding indicators values /// </summary> //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int nbTicks = series.getTickCount(); int nbTicks = series.TickCount; for (int i = 0; i < nbTicks; i++) { sb.Append(series.getTick(i).EndTime.Millis / 1000d).Append(',').Append(closePrice.getValue(i)).Append(',').Append(typicalPrice.getValue(i)).Append(',').Append(priceVariation.getValue(i)).Append(',').Append(shortSma.getValue(i)).Append(',').Append(longSma.getValue(i)).Append(',').Append(shortEma.getValue(i)).Append(',').Append(longEma.getValue(i)).Append(',').Append(ppo.getValue(i)).Append(',').Append(roc.getValue(i)).Append(',').Append(rsi.getValue(i)).Append(',').Append(williamsR.getValue(i)).Append(',').Append(atr.getValue(i)).Append(',').Append(sd.getValue(i)).Append('\n'); } /// <summary> /// Writing CSV file /// </summary> System.IO.StreamWriter writer = null; try { writer = new System.IO.StreamWriter("indicators.csv"); writer.Write(sb.ToString()); } catch (IOException ioe) { //JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method: Logger.getLogger(typeof(IndicatorsToCsv).FullName).log(Level.SEVERE, "Unable to write CSV file", ioe); } finally { try { if (writer != null) { writer.Close(); } } catch (IOException) { } } }