コード例 #1
0
        public PlotCollectionSet GetData(PlotCollectionSet dataset, int nDataIdx, int nLookahead, Guid?guid = null, bool bAddToParams = false)
        {
            RsiData data = GetRsiData(dataset, nDataIdx, nLookahead, bAddToParams);

            return(new PlotCollectionSet(new List <PlotCollection>()
            {
                data.DstData
            }));
        }
コード例 #2
0
        public RsiData GetRsiData(PlotCollectionSet dataset, int nDataIdx, int nLookahead = 0, bool bAddToParams = false)
        {
            RsiData data = Pre(dataset, nDataIdx);

            for (int i = 0; i < data.SrcData.Count; i++)
            {
                Process(data, i, null, nLookahead, bAddToParams);
            }

            MinMax minmax = new MinMax();

            minmax.Add(0);
            minmax.Add(100);

            data.DstData.SetMinMax(minmax);

            return(data);
        }
コード例 #3
0
        /// <summary>
        /// Calculate the RSI based on Wilder's formula.
        /// </summary>
        /// <remarks>
        /// @see [Relative Strength Index](https://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:relative_strength_index_rsi)
        /// </remarks>
        /// <param name="data">Specifies the RSI data from the previous cycle.</param>
        /// <param name="i">Specifies the current data index.</param>
        /// <param name="minmax">Currently, not used here.</param>
        /// <param name="nLookahead">Specifies the look ahead value if any.</param>
        /// <param name="bAddToParams">Optionally, specifies whether or not to add the RSI to the parameters of the original data.</param>
        /// <returns>The new RSI value is returned.</returns>
        public double Process(RsiData data, int i, MinMax minmax = null, int nLookahead = 0, bool bAddToParams = false, bool bIgnoreDst = false)
        {
            bool bActive = false;

            if (!bIgnoreDst)
            {
                Plot plot = new Plot(data.SrcData[i].X, 0, null, false, data.SrcData[i].Index, data.SrcData[i].Action1Active, data.SrcData[i].Action2Active);
                data.DstData.Add(plot, false);
            }

            if (i > 0)
            {
                double dfChange = data.SrcData[i].Y - data.SrcData[i - 1].Y;

                if (i <= m_config.Interval + 1)
                {
                    if (dfChange < 0)
                    {
                        data.AveLoss += (dfChange * -1);
                    }
                    else
                    {
                        data.AveGain += dfChange;
                    }

                    if (i == m_config.Interval + 1)
                    {
                        data.AveLoss /= data.Interval;
                        data.AveGain /= data.Interval;
                        data.Rs       = (data.AveLoss == 0) ? 0 : data.AveGain / data.AveLoss;
                        data.RSI      = 100 - (100 / (1 + data.Rs));
                        bActive       = true;
                    }
                }
                else if (i > data.Interval + 1)
                {
                    if (dfChange < 0)
                    {
                        data.AveLoss = ((data.AveLoss * (data.Interval - 1)) + (-1 * dfChange)) / data.Interval;
                        data.AveGain = ((data.AveGain * (data.Interval - 1)) + (0)) / data.Interval;
                    }
                    else
                    {
                        data.AveLoss = ((data.AveLoss * (data.Interval - 1)) + (0)) / data.Interval;
                        data.AveGain = ((data.AveGain * (data.Interval - 1)) + (dfChange)) / data.Interval;
                    }

                    data.Rs  = (data.AveLoss == 0) ? 0 : data.AveGain / data.AveLoss;
                    data.RSI = 100 - (100 / (1 + data.Rs));
                    bActive  = true;
                }
            }

            if (!bIgnoreDst)
            {
                data.DstData[i].Y      = (float)data.RSI;
                data.DstData[i].Active = bActive;
            }

            if (bAddToParams && bActive)
            {
                data.SrcData[i].SetParameter(data.DstData.Name, (float)data.RSI);
            }

            return(data.RSI);
        }