Exemple #1
0
        protected override void Calculate(PriceBars priceAction)
        {
            if (trueRange.HasValue(maxBarIndex) && directionalMovement.HasValue(maxBarIndex))
            {
                double smoothSumOfTrueRange = HasValue(0, SMOOTH_TR_FIELD_INDEX) ? LastItem.Values[SMOOTH_TR_FIELD_INDEX] - (LastItem.Values[SMOOTH_TR_FIELD_INDEX] / barCount) + trueRange.LastItem.Value : trueRange.Sum(barCount);
                double smoothSumOfPlusDM    = HasValue(0, SMOOTH_PLUS_DM_FIELD_INDEX) ? LastItem.Values[SMOOTH_PLUS_DM_FIELD_INDEX] - (LastItem.Values[SMOOTH_PLUS_DM_FIELD_INDEX] / barCount) + directionalMovement.LastItem.Values[DX_FIELD_INDEX] : directionalMovement.Sum(barCount, 0);
                double smoothSumOfMinusDM   = HasValue(0, SMOOTH_MINUS_DM_INDEX) ? LastItem.Values[SMOOTH_MINUS_DM_INDEX] - (LastItem.Values[SMOOTH_MINUS_DM_INDEX] / barCount) + directionalMovement.LastItem.Values[SMOOTH_TR_FIELD_INDEX] : directionalMovement.Sum(barCount, 1);
                double plusDI  = (smoothSumOfPlusDM / smoothSumOfTrueRange) * 100;
                double minusDI = (smoothSumOfMinusDM / smoothSumOfTrueRange) * 100;
                double diDiff  = Math.Abs(plusDI - minusDI);
                double diSum   = plusDI + minusDI;
                double dx      = (diDiff / diSum) * 100;

                this.Add(new MultiValueIndicatorItem(
                             priceAction.LastItem.Time,
                             dx,
                             smoothSumOfTrueRange,
                             smoothSumOfPlusDM,
                             smoothSumOfMinusDM,
                             plusDI,
                             minusDI
                             ));
                lastCalculationSuccessful = true;
            }
        }
Exemple #2
0
        protected override void Calculate(PriceBars priceAction)
        {
            if (trueRangeCore.HasValue(maxBarIndex))
            {
                double smoothAverage = HasValue(0) ? ((LastItem.Value * (barCount - 1)) + trueRangeCore.LastItem.Value) / barCount : trueRangeCore.Average(barCount);

                this.Add(new SingleValueIndicatorItem(
                             priceAction.LastItem.Time,
                             smoothAverage
                             ));
                lastCalculationSuccessful = true;
            }
        }