Inheritance: Indicator
Beispiel #1
0
 public static double Value(ISeries input, int index, int length, IndicatorStyle style = IndicatorStyle.QuantStudio)
 {
     if (style == IndicatorStyle.QuantStudio)
     {
         var mdm = 0.0;
         var tr  = 0.0;
         if (index >= length)
         {
             for (var i = index; i > index - length; i--)
             {
                 tr  += TR.Value(input, i);
                 mdm += MDM.Value(input, i);
             }
             return(mdm / tr * 100);
         }
         return(double.NaN);
     }
     else
     {
         double mdm = 0.0;
         double tr  = 0.0;
         if (index >= length)
         {
             for (var j = length; j >= 1; j--)
             {
                 tr  += TR.Value(input, j);
                 mdm += MDM.Value(input, j);
             }
             for (var k = length + 1; k <= index; k++)
             {
                 mdm = mdm - mdm / length + MDM.Value(input, k);
                 tr  = tr - tr / length + TR.Value(input, k);
             }
             return(mdm / tr * 100);
         }
         return(double.NaN);
     }
 }
Beispiel #2
0
 // TODO: rewrite
 public override void Calculate(int index)
 {
     if (this.style == IndicatorStyle.QuantStudio)
     {
         double num   = 0.0;
         double num2  = 0.0;
         double value = 0.0;
         if (index >= this.length)
         {
             if (index == this.length)
             {
                 for (int i = index; i >= index - this.length + 1; i--)
                 {
                     num  += PDM.Value(this.input, i);
                     num2 += MDM.Value(this.input, i);
                 }
             }
             else
             {
                 num2 = this.mdmTS[index - 1] - MDM.Value(this.input, index - this.length) +
                        MDM.Value(this.input, index);
                 num = this.pdmTS[index - 1] - PDM.Value(this.input, index - this.length) +
                       PDM.Value(this.input, index);
             }
             if (num + num2 != 0.0)
             {
                 value = Math.Abs(num - num2) / (num + num2) * 100.0;
             }
             Add(this.input.GetDateTime(index), value);
         }
         this.pdmTS.Add(this.input.GetDateTime(index), num);
         this.mdmTS.Add(this.input.GetDateTime(index), num2);
     }
     else
     {
         double num3   = 0.0;
         double num4   = 0.0;
         double value2 = 0.0;
         if (index >= this.length)
         {
             if (index == this.length)
             {
                 for (int j = index; j >= index - this.length + 1; j--)
                 {
                     num3 += PDM.Value(this.input, j);
                     num4 += MDM.Value(this.input, j);
                 }
             }
             else
             {
                 num3 = this.pdmTS[index - 1] - this.pdmTS[index - 1] / (double)this.length +
                        PDM.Value(this.input, index);
                 num4 = this.mdmTS[index - 1] - this.mdmTS[index - 1] / (double)this.length +
                        MDM.Value(this.input, index);
             }
             if (num3 + num4 != 0.0)
             {
                 value2 = Math.Abs(num3 - num4) / (num3 + num4) * 100.0;
             }
             base.Add(this.input.GetDateTime(index), value2);
         }
         this.pdmTS.Add(this.input.GetDateTime(index), num3);
         this.mdmTS.Add(this.input.GetDateTime(index), num4);
     }
 }
Beispiel #3
0
 public override void Calculate(int index)
 {
     if (this.style == IndicatorStyle.QuantStudio)
     {
         double mdm = 0.0;
         double tr  = 0.0;
         if (index >= this.length)
         {
             if (index == this.length)
             {
                 for (int i = index; i >= index - this.length + 1; i--)
                 {
                     tr  += TR.Value(this.input, i);
                     mdm += MDM.Value(this.input, i);
                 }
             }
             else
             {
                 mdm = this.mdmTS[index - 1] - MDM.Value(this.input, index - this.length) +
                       MDM.Value(this.input, index);
                 tr = this.trTS[index - 1] - TR.Value(this.input, index - this.length) +
                      TR.Value(this.input, index);
             }
             if (tr != 0.0)
             {
                 double value = mdm / tr * 100.0;
                 if (!double.IsNaN(value))
                 {
                     Add(this.input.GetDateTime(index), value);
                 }
             }
         }
         this.mdmTS.Add(this.input.GetDateTime(index), mdm);
         this.trTS.Add(this.input.GetDateTime(index), tr);
     }
     else
     {
         double mdm = 0.0;
         double tr  = 0.0;
         if (index >= this.length)
         {
             if (index == this.length)
             {
                 for (var j = index; j >= index - this.length + 1; j--)
                 {
                     tr  += TR.Value(this.input, j);
                     mdm += MDM.Value(this.input, j);
                 }
             }
             else
             {
                 mdm = this.mdmTS[index - 1] - this.mdmTS[index - 1] / this.length + MDM.Value(this.input, index);
                 tr  = this.trTS[index - 1] - this.trTS[index - 1] / this.length + TR.Value(this.input, index);
             }
             if (tr != 0.0)
             {
                 double value = mdm / tr * 100.0;
                 if (!double.IsNaN(value))
                 {
                     Add(this.input.GetDateTime(index), value);
                 }
             }
         }
         this.mdmTS.Add(this.input.GetDateTime(index), mdm);
         this.trTS.Add(this.input.GetDateTime(index), tr);
     }
 }