Exemple #1
0
 public static double Value(ISeries input, int index, int length, IndicatorStyle style = IndicatorStyle.QuantStudio)
 {
     if (index >= length)
     {
         double num = 0.0;
         double result;
         if (style == IndicatorStyle.QuantStudio)
         {
             for (int i = index; i > index - length; i--)
             {
                 num += TR.Value(input, i);
             }
             result = num / (double)length;
         }
         else
         {
             for (int j = length; j > 0; j--)
             {
                 num += TR.Value(input, j);
             }
             num /= (double)length;
             for (int k = length + 1; k <= index; k++)
             {
                 num = (num * (double)(length - 1) + TR.Value(input, k)) / (double)length;
             }
             result = num;
         }
         return(result);
     }
     return(double.NaN);
 }
Exemple #2
0
 public static double Value(ISeries input, int index, int length)
 {
     if (index >= length)
     {
         double num = 0.0;
         for (int i = index - length + 1; i <= index; i++)
         {
             num += TR.Value(input, i);
         }
         num /= (double)length;
         return(SMA.Value(input, index, length, BarData.Typical) - num);
     }
     return(double.NaN);
 }
Exemple #3
0
        protected internal override void Calculate(int index)
        {
            if (this.calculate)
            {
                this.Calculate();
                return;
            }
            double num = TR.Value(this.input, index);

            if (!double.IsNaN(num))
            {
                base.Add(this.input.GetDateTime(index), num);
            }
        }
Exemple #4
0
 protected internal override void Calculate(int index)
 {
     if (this.calculate)
     {
         this.Calculate();
         return;
     }
     if (index >= this.length)
     {
         int    num = -1 * this.length;
         double value;
         if (this.style == IndicatorStyle.QuantStudio)
         {
             if (index == this.length)
             {
                 double num2 = 0.0;
                 for (int i = index; i > index - this.length; i--)
                 {
                     num2 += TR.Value(this.input, i);
                 }
                 value = num2 / (double)this.length;
             }
             else
             {
                 double num3 = TR.Value(this.input, index);
                 value = (this[index - 1 + num] * (double)this.length + num3 - TR.Value(this.input, index - this.length)) / (double)this.length;
             }
         }
         else
         {
             if (index == this.length)
             {
                 double num4 = 0.0;
                 for (int j = index; j > index - this.length; j--)
                 {
                     num4 += TR.Value(this.input, j);
                 }
                 value = num4 / (double)this.length;
             }
             else
             {
                 double num3 = TR.Value(this.input, index);
                 value = (base[this.input.GetDateTime(index - 1), SearchOption.Exact] * (double)this.length + num3 - TR.Value(this.input, index - this.length)) / (double)this.length;
             }
         }
         base.Add(this.input.GetDateTime(index), value);
     }
 }
Exemple #5
0
 public static double Value(ISeries input, int index, int n1, int n2, int n3)
 {
     if (index >= Math.Max(n1, Math.Max(n2, n3)))
     {
         double num  = 0.0;
         double num2 = 0.0;
         for (int i = index; i > index - n1; i--)
         {
             double num3 = input[i, BarData.Close];
             double val  = input[i - 1, BarData.Close];
             double val2 = input[i, BarData.Low];
             num  += num3 - Math.Min(val2, val);
             num2 += TR.Value(input, i);
         }
         double num4 = (double)(n3 / n1) * (num / num2);
         num  = 0.0;
         num2 = 0.0;
         for (int j = index; j > index - n2; j--)
         {
             double num3 = input[j, BarData.Close];
             double val  = input[j - 1, BarData.Close];
             double val2 = input[j, BarData.Low];
             num  += num3 - Math.Min(val2, val);
             num2 += TR.Value(input, j);
         }
         double num5 = (double)(n3 / n2) * (num / num2);
         num  = 0.0;
         num2 = 0.0;
         for (int k = index; k > index - n3; k--)
         {
             double num3 = input[k, BarData.Close];
             double val  = input[k - 1, BarData.Close];
             double val2 = input[k, BarData.Low];
             num  += num3 - Math.Min(val2, val);
             num2 += TR.Value(input, k);
         }
         double num6 = num / num2;
         return((num4 + num5 + num6) / (double)(n3 / n1 + n3 / n2 + 1) * 100.0);
     }
     return(double.NaN);
 }
Exemple #6
0
 public static double Value(ISeries input, int index, int length, IndicatorStyle style = IndicatorStyle.QuantStudio)
 {
     if (style == IndicatorStyle.QuantStudio)
     {
         double num  = 0.0;
         double num2 = 0.0;
         if (index >= length)
         {
             for (int i = index; i > index - length; i--)
             {
                 num2 += TR.Value(input, i);
                 num  += PDM.Value(input, i);
             }
             return(num / num2 * 100.0);
         }
         return(double.NaN);
     }
     else
     {
         double num3 = 0.0;
         double num4 = 0.0;
         if (index >= length)
         {
             for (int j = length; j >= 1; j--)
             {
                 num4 += TR.Value(input, j);
                 num3 += PDM.Value(input, j);
             }
             for (int k = length + 1; k <= index; k++)
             {
                 num3 = num3 - num3 / (double)length + PDM.Value(input, k);
                 num4 = num4 - num4 / (double)length + TR.Value(input, k);
             }
             return(num3 / num4 * 100.0);
         }
         return(double.NaN);
     }
 }
Exemple #7
0
        protected internal override void Calculate(int index)
        {
            if (this.calculate)
            {
                this.Calculate();
                return;
            }
            if (this.style == IndicatorStyle.QuantStudio)
            {
                double num  = 0.0;
                double num2 = 0.0;
                if (index >= this.length)
                {
                    if (index == this.length)
                    {
                        for (int i = index; i >= index - this.length + 1; i--)
                        {
                            num2 += TR.Value(this.input, i);
                            num  += PDM.Value(this.input, i);
                        }
                    }
                    else
                    {
                        num  = this.pdmTS[index - 1] - PDM.Value(this.input, index - this.length) + PDM.Value(this.input, index);
                        num2 = this.trTS[index - 1] - TR.Value(this.input, index - this.length) + TR.Value(this.input, index);
                    }
                    if (num2 != 0.0)
                    {
                        double num3 = num / num2 * 100.0;
                        if (!double.IsNaN(num3))
                        {
                            base.Add(this.input.GetDateTime(index), num3);
                        }
                    }
                }
                this.pdmTS.Add(this.input.GetDateTime(index), num);
                this.trTS.Add(this.input.GetDateTime(index), num2);
                return;
            }
            double num4 = 0.0;
            double num5 = 0.0;

            if (index >= this.length)
            {
                if (index == this.length)
                {
                    for (int j = index; j >= index - this.length + 1; j--)
                    {
                        num5 += TR.Value(this.input, j);
                        num4 += PDM.Value(this.input, j);
                    }
                }
                else
                {
                    num4 = this.pdmTS[index - 1] - this.pdmTS[index - 1] / (double)this.length + PDM.Value(this.input, index);
                    num5 = this.trTS[index - 1] - this.trTS[index - 1] / (double)this.length + TR.Value(this.input, index);
                }
                if (num5 != 0.0)
                {
                    double num6 = num4 / num5 * 100.0;
                    if (!double.IsNaN(num6))
                    {
                        base.Add(this.input.GetDateTime(index), num6);
                    }
                }
            }
            this.pdmTS.Add(this.input.GetDateTime(index), num4);
            this.trTS.Add(this.input.GetDateTime(index), num5);
        }