public static double Value(ISeries input, int index, int length, IndicatorStyle style = IndicatorStyle.QuantStudio) { if (style == IndicatorStyle.QuantStudio) { var pdm = 0.0; var tr = 0.0; if (index >= length) { for (int i = index; i > index - length; i--) { tr += TR.Value(input, i); pdm += PDM.Value(input, i); } return(pdm / tr * 100.0); } return(double.NaN); } else { var pdm = 0.0; var tr = 0.0; if (index >= length) { for (var j = length; j >= 1; j--) { tr += TR.Value(input, j); pdm += PDM.Value(input, j); } for (var k = length + 1; k <= index; k++) { pdm = pdm - pdm / length + PDM.Value(input, k); tr = tr - tr / length + TR.Value(input, k); } return(pdm / tr * 100.0); } return(double.NaN); } }
// 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); } }
public override void Calculate(int index) { if (this.style == IndicatorStyle.QuantStudio) { var pdm = 0.0; var tr = 0.0; if (index >= this.length) { if (index == this.length) { for (var i = index; i >= index - this.length + 1; i--) { tr += TR.Value(this.input, i); pdm += PDM.Value(this.input, i); } } else { pdm = this.pdmTS[index - 1] - PDM.Value(this.input, index - this.length) + PDM.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) { var value = pdm / tr * 100.0; if (!double.IsNaN(value)) { Add(this.input.GetDateTime(index), value); } } } this.pdmTS.Add(this.input.GetDateTime(index), pdm); this.trTS.Add(this.input.GetDateTime(index), tr); } else { var pdm = 0.0; var tr = 0.0; if (index >= this.length) { if (index == this.length) { for (int j = index; j >= index - this.length + 1; j--) { tr += TR.Value(this.input, j); pdm += PDM.Value(this.input, j); } } else { pdm = this.pdmTS[index - 1] - this.pdmTS[index - 1] / this.length + PDM.Value(this.input, index); tr = this.trTS[index - 1] - this.trTS[index - 1] / this.length + TR.Value(this.input, index); } if (tr != 0.0) { var value = pdm / tr * 100.0; if (!double.IsNaN(value)) { Add(this.input.GetDateTime(index), value); } } } this.pdmTS.Add(this.input.GetDateTime(index), pdm); this.trTS.Add(this.input.GetDateTime(index), tr); } }