/// <summary>
 /// Initializes a new instance of the <see cref="NormalizedAverageTrueRange"/> class using the specified name and period.
 /// </summary>
 /// <param name="name">The name of this indicator</param>
 /// <param name="period">The period of the NATR</param>
 public NormalizedAverageTrueRange(string name, int period) :
     base(name)
 {
     _period = period;
     _tr     = new TrueRange(name + "_TR");
     _atr    = new AverageTrueRange(name + "_ATR", period, MovingAverageType.Simple);
 }
Exemplo n.º 2
0
 /// <summary>
 /// Resets this indicator to its initial state
 /// </summary>
 public override void Reset()
 {
     _previous = null;
     _smoother.Reset();
     TrueRange.Reset();
     base.Reset();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="NormalizedAverageTrueRange"/> class using the specified name and period.
 /// </summary> 
 /// <param name="name">The name of this indicator</param>
 /// <param name="period">The period of the NATR</param>
 public NormalizedAverageTrueRange(string name, int period) : 
     base(name)
 {
     _period = period;
     _tr = new TrueRange(name + "_TR");
     _atr = new AverageTrueRange(name + "_ATR", period, MovingAverageType.Simple);
 }
Exemplo n.º 4
0
        /// <summary>
        /// Computes the next value of this indicator from the given state
        /// </summary>
        /// <param name="input">The input given to the indicator</param>
        /// <returns>A new value for this indicator</returns>
        protected override decimal ComputeNextValue(IBaseDataBar input)
        {
            // compute the true range and then send it to our smoother
            TrueRange.Update(input);
            _smoother.Update(input.Time, TrueRange);

            return(_smoother.Current.Value);
        }
Exemplo n.º 5
0
        public void ComparesAgainstExternalDataAfterReset()
        {
            var tr = new TrueRange("TR");

            RunTestIndicator(tr);
            tr.Reset();
            RunTestIndicator(tr);
        }
 /// <summary>
 /// Resets this indicator to its initial state
 /// </summary>
 public override void Reset()
 {
     base.Reset();
     TrueRange.Reset();
     DirectionalMovementPlus.Reset();
     DirectionalMovementMinus.Reset();
     SmoothedTrueRange.Reset();
     SmoothedDirectionalMovementMinus.Reset();
     SmoothedDirectionalMovementPlus.Reset();
     PositiveDirectionalIndex.Reset();
     NegativeDirectionalIndex.Reset();
 }
Exemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UltimateOscillator"/> class using the specified parameters
 /// </summary>
 /// <param name="name">The name of this indicator</param>
 /// <param name="period1">The first period</param>
 /// <param name="period2">The second period</param>
 /// <param name="period3">The third period</param>
 public UltimateOscillator(string name, int period1, int period2, int period3)
     : base(name)
 {
     _period = Math.Max(Math.Max(period1, period2), period3);
     _trueRange = new TrueRange(name + "_TR");
     _sumBuyingPressure1 = new Sum(name + "_BP1", period1);
     _sumBuyingPressure2 = new Sum(name + "_BP2", period2);
     _sumBuyingPressure3 = new Sum(name + "_BP3", period3);
     _sumTrueRange1 = new Sum(name + "_TR1", period1);
     _sumTrueRange2 = new Sum(name + "_TR2", period2);
     _sumTrueRange3 = new Sum(name + "_TR3", period3);
 }
Exemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UltimateOscillator"/> class using the specified parameters
 /// </summary>
 /// <param name="name">The name of this indicator</param>
 /// <param name="period1">The first period</param>
 /// <param name="period2">The second period</param>
 /// <param name="period3">The third period</param>
 public UltimateOscillator(string name, int period1, int period2, int period3)
     : base(name)
 {
     _period = Math.Max(Math.Max(period1, period2), period3);
     _trueRange = new TrueRange(name + "_TR");
     _sumBuyingPressure1 = new Sum(name + "_BP1", period1);
     _sumBuyingPressure2 = new Sum(name + "_BP2", period2);
     _sumBuyingPressure3 = new Sum(name + "_BP3", period3);
     _sumTrueRange1 = new Sum(name + "_TR1", period1);
     _sumTrueRange2 = new Sum(name + "_TR2", period2);
     _sumTrueRange3 = new Sum(name + "_TR3", period3);
 }
Exemplo n.º 9
0
        public void ResetsProperly()
        {
            var tr = new TrueRange("TR");
            foreach (var data in TestHelper.GetTradeBarStream("spy_tr.txt", false))
            {
                tr.Update(data);
            }

            Assert.IsTrue(tr.IsReady);

            tr.Reset();

            TestHelper.AssertIndicatorIsInDefaultState(tr);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Computes the next value of this indicator from the given state
        /// </summary>
        /// <param name="input">The input given to the indicator</param>
        /// <returns>A new value for this indicator</returns>
        protected override decimal ComputeNextValue(IBaseDataBar input)
        {
            TrueRange.Update(input);
            DirectionalMovementPlus.Update(input);
            DirectionalMovementMinus.Update(input);
            SmoothedTrueRange.Update(Current);
            SmoothedDirectionalMovementMinus.Update(Current);
            SmoothedDirectionalMovementPlus.Update(Current);
            if (_previousInput != null)
            {
                PositiveDirectionalIndex.Update(Current);
                NegativeDirectionalIndex.Update(Current);
            }
            var diff  = Math.Abs(PositiveDirectionalIndex - NegativeDirectionalIndex);
            var sum   = PositiveDirectionalIndex + NegativeDirectionalIndex;
            var value = sum == 0 ? 50 : ((_period - 1) * Current.Value + 100 * diff / sum) / _period;

            _previousInput = input;
            return(value);
        }
Exemplo n.º 11
0
 /// <summary>
 /// Resets this indicator to its initial state
 /// </summary>
 public override void Reset()
 {
     _smoother.Reset();
     TrueRange.Reset();
     base.Reset();
 }
Exemplo n.º 12
0
        public void ComparesAgainstExternalData()
        {
            var tr = new TrueRange("TR");

            TestHelper.TestIndicator(tr, "spy_tr.txt", "TR", (ind, expected) => Assert.AreEqual(expected, (double)ind.Current.Value, 1e-3));
        }
Exemplo n.º 13
0
 private static void RunTestIndicator(TrueRange tr)
 {
     TestHelper.TestIndicator(tr, "spy_tr.txt", "TR", (ind, expected) => Assert.AreEqual(expected, (double)ind.Current.Value, 1e-3));
 }
Exemplo n.º 14
0
        public void ResetsProperly()
        {
            var tr = new TrueRange("TR");

            TestHelper.TestIndicatorReset(tr, "spy_tr.txt");
        }