Example #1
0
 /// <summary>
 /// Initializes a new instance of the MeanAbsoluteDeviation class with the specified period.
 ///
 /// Evaluates the mean absolute deviation of samples in the lookback period.
 /// </summary>
 /// <param name="name">The name of this indicator</param>
 /// <param name="period">The sample size of the mean absoluate deviation</param>
 public MeanAbsoluteDeviation(string name, int period)
     : base(name, period)
 {
     Mean = MovingAverageType.Simple.AsIndicator(string.Format("{0}_{1}", name, "Mean"), period);
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="AverageDirectionalIndex"/> class.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="period">The period.</param>
        public AverageDirectionalIndex(string name, int period)
            : base(name)
        {
            _period = period;

            TrueRange = new FunctionalIndicator <TradeBar>(name + "_TrueRange",
                                                           currentBar =>
            {
                var value = ComputeTrueRange(currentBar);
                return(value);
            },
                                                           isReady => _previousInput != null
                                                           );

            DirectionalMovementPlus = new FunctionalIndicator <TradeBar>(name + "_PositiveDirectionalMovement",
                                                                         currentBar =>
            {
                var value = ComputePositiveDirectionalMovement(currentBar);
                return(value);
            },
                                                                         isReady => _previousInput != null
                                                                         );


            DirectionalMovementMinus = new FunctionalIndicator <TradeBar>(name + "_NegativeDirectionalMovement",
                                                                          currentBar =>
            {
                var value = ComputeNegativeDirectionalMovement(currentBar);
                return(value);
            },
                                                                          isReady => _previousInput != null
                                                                          );

            PositiveDirectionalIndex = new FunctionalIndicator <IndicatorDataPoint>(name + "_PositiveDirectionalIndex",
                                                                                    input => ComputePositiveDirectionalIndex(),
                                                                                    positiveDirectionalIndex => DirectionalMovementPlus.IsReady && TrueRange.IsReady,
                                                                                    () =>
            {
                DirectionalMovementPlus.Reset();
                TrueRange.Reset();
            }
                                                                                    );

            NegativeDirectionalIndex = new FunctionalIndicator <IndicatorDataPoint>(name + "_NegativeDirectionalIndex",
                                                                                    input => ComputeNegativeDirectionalIndex(),
                                                                                    negativeDirectionalIndex => DirectionalMovementMinus.IsReady && TrueRange.IsReady,
                                                                                    () =>
            {
                DirectionalMovementMinus.Reset();
                TrueRange.Reset();
            }
                                                                                    );

            SmoothedTrueRange = new FunctionalIndicator <IndicatorDataPoint>(name + "_SmoothedTrueRange",
                                                                             currentBar => ComputeSmoothedTrueRange(period),
                                                                             isReady => _previousInput != null
                                                                             );


            SmoothedDirectionalMovementPlus = new FunctionalIndicator <IndicatorDataPoint>(name + "_SmoothedDirectionalMovementPlus",
                                                                                           currentBar => ComputeSmoothedDirectionalMovementPlus(period),
                                                                                           isReady => _previousInput != null
                                                                                           );

            SmoothedDirectionalMovementMinus = new FunctionalIndicator <IndicatorDataPoint>(name + "_SmoothedDirectionalMovementMinus",
                                                                                            currentBar => ComputeSmoothedDirectionalMovementMinus(period),
                                                                                            isReady => _previousInput != null
                                                                                            );
        }