public void BuildSeries(ChartControl chart) { seriesRSI.Data.Clear(); seriesBound.data.Clear(); // границы var reg = new BarRegion { Color = Color.Black, UpperBound = 100 - marginPercent, LowerBound = marginPercent }; seriesBound.data.Add(reg); // RSI for (var i = 0; i < Period; i++) { seriesRSI.Data.Add(50); } var dataCount = GetSourceDataCount(); for (var i = Period; i < dataCount; i++) { double sumU = 0, sumD = 0; for (var j = 0; j < Period; j++) { var delta = GetSourcePrice(i - j) - GetSourcePrice(i - j - 1); if (delta < 0) { sumD -= delta; } else { sumU += delta; } } double RSI; if (sumU == sumD && sumU == 0) { RSI = 50; } else if (sumD == 0) { RSI = 100; } else { RSI = 100 - 100.0 / (1 + sumU / sumD); } seriesRSI.Data.Add(RSI); } }
private void AddDivergenceRegion(int endIndex, int sign) { var reg = new BarRegion { IndexStart = endIndex, IndexEnd = endIndex + 1, Color = sign < 0 ? ColorArrowDown : ColorArrowUp }; // найти цены var seriesSrc = SeriesSources[0]; if (seriesSrc is StockSeries) { var candle = ((StockSeries)seriesSrc).Data.Candles[endIndex]; reg.UpperBound = Math.Max(candle.open, candle.close); reg.LowerBound = Math.Min(candle.open, candle.close); } seriesRegion.data.Add(reg); }