Beispiel #1
0
 public void Set(double high, double low, double close)
 {
     maxK.Set(high);
     minK.Set(low);
     den = maxK.Get() - minK.Get();
     nom = close - minK.Get();
     sumD.Set(den);
     sumNom.Set(nom);
     K = 100 * sumNom.Get() / (sumD.Get() == 0 ? 1.0 : sumD.Get());
     kSMA.Set(K);
     D = kSMA.Get();
 }
Beispiel #2
0
        public void Set(double curVal)
        {
            if (count == 0)
            {
                up   = 0;
                down = 0;
            }
            else
            {
                down = Math.Max(lastVal - curVal, 0);
                up   = Math.Max(curVal - lastVal, 0);

                if ((count + 1) < Period)
                {
                    if ((count + 1) == (Period - 1))
                    {
                        avg = 50;
                    }
                }
                else
                {
                    if ((count + 1) == Period)
                    {
                        avgDown = downSMA.Get();
                        avgUp   = upSMA.Get();
                    }
                    else
                    {
                        // Rest of averages are smoothed
                        avgDown = (avgDown * (Period - 1) + down) / Period;
                        avgUp   = (avgUp * (Period - 1) + up) / Period;
                    }

                    double rs     = avgUp / (avgDown == 0 ? 1 : avgDown);
                    double rsi    = 100 - (100 / (1 + rs));
                    double rsiAvg = (2.0 / (1 + Smooth)) * rsi + (1 - (2.0 / (1 + Smooth))) * avg;

                    avg = rsiAvg;
                    val = rsi;
                }
            }
            if ((count + 1) <= Period)
            {
                downSMA.Set(down);
                upSMA.Set(up);
            }
            lastVal = curVal;
            count++;
        }
Beispiel #3
0
        public void Set(double curVal)
        {
            buff.Insert(0, curVal);
            if (count == 0)
            {
                val = 0;
            }
            else
            {
                double mean = 0;
                sma.Set(curVal);
                for (int idx = Math.Min(buff.Count - 1, Period - 1); idx >= 0; idx--)
                {
                    mean += Math.Abs((double)buff[idx] - sma.Get());
                }
                val = (curVal - sma.Get()) / (mean == 0 ? 1 : (0.015 * (mean / Math.Min(Period, count + 1))));
            }

            if (buff.Count == Period + 1)
            {
                buff.RemoveAt(Period);
            }
            count++;
        }