我正在尝试使用Microsoft Charting库计算RelativeStrengthIndex RSI。但我无法理解如何实际计算RSI。在官方文档中,它将Close price作为输入,UpperBand,Lower band作为最后一个参数。我的RSI错了。这是我的代码。
我正以近似价格计算10期RSI。
This is to calculate Bollinger band using TA-lib library
double[] input = _stockData.Select("Convert.ToDouble(Close)", null).Cast<double>().Reverse().Take(40).ToArray();
int startIdx = 0;
int endIdx = input.Length - 1;
int outBegIdx = 0;
int outNBElement = 0;
double[] output = new double[input.Length];
double[] realUpperBand = new double[input.Length];
double[] realMiddleBand = new double[input.Length];
double[] realLowerBand = new double[input.Length];
TaLib.Bbands(startIdx, endIdx, input, period * 2, upperDeviation, lowerDeviation, TaLib.MAType.Ema, out outBegIdx, out outNBElement, realUpperBand, realMiddleBand, realLowerBand);
realUpperBand = realUpperBand.Where(e => e != default(double)).Select(e => e).ToArray();
realMiddleBand = realMiddleBand.Where(e => e != default(double)).Select(e => e).ToArray();
realLowerBand = realLowerBand.Where(e => e != default(double)).Select(e => e).ToArray();
THis is where Ia m using MS charting library to calculate RSI
var chart = new Chart();
chart.Series.Add("Series1");
chart.Series.Add("Series2");
chart.Series.Add("Series3");
chart.Series.Add("Series4");
var xvals = new double[21];
for (int i = 0; i < xvals.Length; i++)
{
xvals[i] = 1 * i;
}
chart.Series["Series1"].Points.DataBindY(input.Take(21).ToArray());
chart.Series["Series3"].Points.DataBindY(realUpperBand);
chart.Series["Series4"].Points.DataBindY(realLowerBand);
chart.DataManipulator.FinancialFormula(FinancialFormula.RelativeStrengthIndex, "10,2", "Series1", "Series2,Series3,Series4");
foreach (var item in chart.Series["Series2"].Points)
{
Console.WriteLine(string.Format("{0}::{1}", item.XValue, item.YValues[0]));
}
我得到的10个值是这些,因为我正在使用10个句点。这些值是错误的。
67.8321678321678
48.6230583575715
44.8883076981673
25.6904113625767
24.5922535440154
19.5463410734941
19.2588576538431
16.4244652418174
30.2733037135866
22.7200114375465
52.3084521817947
如何获得RSI 10期间的正确值。
例如,如果我们尝试计算RSI(3,关闭),则这些是数据点。
These data points are from 10/26/2016 to 10/21/2016 for stock symbol AAPL
115.59,118.25,117.65,116.6
RSI应
24.5075 for 10/26/2016
也是为了正确的结果访问该网站。 https://www.tradingview.com/chart/OqPrDeTV/