Ejemplo n.º 1
0
        protected override void Calculate(int index)
        {
            double Data1 = double.NaN;

            if (this.fStyle == EIndicatorStyle.QuantStudio)
            {
                double Data2 = 0.0;
                double Data3 = 0.0;
                if (index >= this.fLength + this.fInput.FirstIndex)
                {
                    if (index == this.fLength + this.fInput.FirstIndex)
                    {
                        for (int index1 = index; index1 >= index - this.fLength + 1; --index1)
                        {
                            Data3 += TR.Value(this.fInput, index1);
                            Data2 += PDM.Value(this.fInput, index1);
                        }
                    }
                    else
                    {
                        Data2 = this.fPDM[index - 1] - PDM.Value(this.fInput, index - this.fLength) + PDM.Value(this.fInput, index);
                        Data3 = this.fTR[index - 1] - TR.Value(this.fInput, index - this.fLength) + TR.Value(this.fInput, index);
                    }
                    if (Data3 != 0.0)
                    {
                        Data1 = Data2 / Data3 * 100.0;
                    }
                }
                this.fPDM.Add(this.fInput.GetDateTime(index), Data2);
                this.fTR.Add(this.fInput.GetDateTime(index), Data3);
            }
            else
            {
                double Data2 = 0.0;
                double Data3 = 0.0;
                if (index >= this.fLength + this.fInput.FirstIndex)
                {
                    if (index == this.fLength + this.fInput.FirstIndex)
                    {
                        for (int index1 = index; index1 >= index - this.fLength + 1; --index1)
                        {
                            Data3 += TR.Value(this.fInput, index1);
                            Data2 += PDM.Value(this.fInput, index1);
                        }
                    }
                    else
                    {
                        Data2 = this.fPDM[index - 1] - this.fPDM[index - 1] / (double)this.fLength + PDM.Value(this.fInput, index);
                        Data3 = this.fTR[index - 1] - this.fTR[index - 1] / (double)this.fLength + TR.Value(this.fInput, index);
                    }
                    if (Data3 != 0.0)
                    {
                        Data1 = Data2 / Data3 * 100.0;
                    }
                }
                this.fPDM.Add(this.fInput.GetDateTime(index), Data2);
                this.fTR.Add(this.fInput.GetDateTime(index), Data3);
            }
            this.Add(this.fInput.GetDateTime(index), Data1);
        }
Ejemplo n.º 2
0
        public static double Value(TimeSeries input, int index, int length, EIndicatorStyle style)
        {
            if (index < length + input.FirstIndex)
            {
                return(double.NaN);
            }
            double num1 = 0.0;
            double num2;

            if (style == EIndicatorStyle.QuantStudio)
            {
                for (int index1 = index; index1 > index - length; --index1)
                {
                    num1 += TR.Value(input, index1);
                }
                num2 = num1 / (double)length;
            }
            else
            {
                for (int index1 = length + input.FirstIndex; index1 > input.FirstIndex; --index1)
                {
                    num1 += TR.Value(input, index1);
                }
                double num3 = num1 / (double)length;
                for (int index1 = length + 1 + input.FirstIndex; index1 <= index; ++index1)
                {
                    num3 = (num3 * (double)(length - 1) + TR.Value(input, index1)) / (double)length;
                }
                num2 = num3;
            }
            return(num2);
        }
Ejemplo n.º 3
0
        public static double Value(TimeSeries input, int index, int length)
        {
            if (index < length + input.FirstIndex)
            {
                return(double.NaN);
            }
            double num1 = 0.0;

            for (int index1 = index - length + 1; index1 <= index; ++index1)
            {
                num1 += TR.Value(input, index1);
            }
            double num2 = num1 / (double)length;

            return(SMA.Value(input, index, length, BarData.Typical) - num2);
        }
Ejemplo n.º 4
0
        public static double Value(TimeSeries input, int index, int n1, int n2, int n3)
        {
            if (index < Math.Max(n1, Math.Max(n2, n3)) + input.FirstIndex)
            {
                return(double.NaN);
            }
            double num1 = 0.0;
            double num2 = 0.0;

            for (int index1 = index; index1 > index - n1; --index1)
            {
                double num3 = input[index1, BarData.Close];
                double val2 = input[index1 - 1, BarData.Close];
                double val1 = input[index1, BarData.Low];
                num1 += num3 - Math.Min(val1, val2);
                num2 += TR.Value(input, index1);
            }
            double num4 = (double)(n3 / n1) * (num1 / num2);
            double num5 = 0.0;
            double num6 = 0.0;

            for (int index1 = index; index1 > index - n2; --index1)
            {
                double num3 = input[index1, BarData.Close];
                double val2 = input[index1 - 1, BarData.Close];
                double val1 = input[index1, BarData.Low];
                num5 += num3 - Math.Min(val1, val2);
                num6 += TR.Value(input, index1);
            }
            double num7 = (double)(n3 / n2) * (num5 / num6);
            double num8 = 0.0;
            double num9 = 0.0;

            for (int index1 = index; index1 > index - n3; --index1)
            {
                double num3 = input[index1, BarData.Close];
                double val2 = input[index1 - 1, BarData.Close];
                double val1 = input[index1, BarData.Low];
                num8 += num3 - Math.Min(val1, val2);
                num9 += TR.Value(input, index1);
            }
            double num10 = num8 / num9;

            return((num4 + num7 + num10) / (double)(n3 / n1 + n3 / n2 + 1) * 100.0);
        }
Ejemplo n.º 5
0
 protected override void Calculate(int index)
 {
     if (index >= this.fLength + this.fInput.FirstIndex)
     {
         int    num1 = -(Indicator.SyncIndex ? 0 : 1) * this.fLength;
         double Data;
         if (this.fStyle == EIndicatorStyle.QuantStudio)
         {
             if (index == this.fLength + this.fInput.FirstIndex)
             {
                 double num2 = 0.0;
                 for (int index1 = index; index1 > index - this.fLength; --index1)
                 {
                     num2 += TR.Value(this.fInput, index1);
                 }
                 Data = num2 / (double)this.fLength;
             }
             else
             {
                 double num2 = TR.Value(this.fInput, index);
                 Data = (this[index - 1 + num1] * (double)this.fLength + num2 - TR.Value(this.fInput, index - this.fLength)) / (double)this.fLength;
             }
         }
         else if (index == this.fLength + this.fInput.FirstIndex)
         {
             double num2 = 0.0;
             for (int index1 = index; index1 > index - this.fLength; --index1)
             {
                 num2 += TR.Value(this.fInput, index1);
             }
             Data = num2 / (double)this.fLength;
         }
         else
         {
             double num2 = TR.Value(this.fInput, index);
             Data = (this[this.fInput.GetDateTime(index - 1)] * (double)this.fLength + num2 - TR.Value(this.fInput, index - this.fLength)) / (double)this.fLength;
         }
         this.Add(this.fInput.GetDateTime(index), Data);
     }
     else
     {
         this.Add(this.fInput.GetDateTime(index), double.NaN);
     }
 }
Ejemplo n.º 6
0
 public static double Value(TimeSeries input, int index, int length, EIndicatorStyle style)
 {
     if (style == EIndicatorStyle.QuantStudio)
     {
         double num1 = 0.0;
         double num2 = 0.0;
         if (index < length + input.FirstIndex)
         {
             return(double.NaN);
         }
         for (int index1 = index; index1 > index - length; --index1)
         {
             num2 += TR.Value(input, index1);
             num1 += PDM.Value(input, index1);
         }
         return(num1 / num2 * 100.0);
     }
     else
     {
         double num1 = 0.0;
         double num2 = 0.0;
         if (index < length + input.FirstIndex)
         {
             return(double.NaN);
         }
         for (int index1 = length + input.FirstIndex; index1 >= input.FirstIndex + 1; --index1)
         {
             num2 += TR.Value(input, index1);
             num1 += PDM.Value(input, index1);
         }
         for (int index1 = length + 1 + input.FirstIndex; index1 <= index; ++index1)
         {
             num1 = num1 - num1 / (double)length + PDM.Value(input, index1);
             num2 = num2 - num2 / (double)length + TR.Value(input, index1);
         }
         return(num1 / num2 * 100.0);
     }
 }
Ejemplo n.º 7
0
        protected override void Calculate(int index)
        {
            double Data = TR.Value(this.fInput, index);

            this.Add(this.fInput.GetDateTime(index), Data);
        }