public void getValueWithEma10AndEma20() { PPOIndicator ppo = new PPOIndicator(closePriceIndicator, 10, 20); Assert.AreEqual(ppo.GetValue(21), 1.67780570148937817231578600M); Assert.AreEqual(ppo.GetValue(22), 1.5669258195342456701776811500M); Assert.AreEqual(ppo.GetValue(23), 1.2884438234398944188665800700M); Assert.AreEqual(ppo.GetValue(28), -0.2925826973018672921767644400M); Assert.AreEqual(ppo.GetValue(29), -1.3088299887349524021082730300M); }
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) { } } }