Beispiel #1
0
        /// <summary>
        /// Creates a new IchimokuKinkoHyo indicator from the specific periods
        /// </summary>
        /// <param name="name">The name of this indicator</param>
        /// <param name="tenkanPeriod">The Tenkan-sen period</param>
        /// <param name="kijunPeriod">The Kijun-sen period</param>
        /// <param name="senkouAPeriod">The Senkou A Span period</param>
        /// <param name="senkouBPeriod">The Senkou B Span period</param>
        /// <param name="senkouADelayPeriod">The Senkou A Span delay</param>
        /// <param name="senkouBDelayPeriod">The Senkou B Span delay</param>
        public IchimokuKinkoHyo(string name, int tenkanPeriod = 9, int kijunPeriod = 26, int senkouAPeriod = 26, int senkouBPeriod = 52, int senkouADelayPeriod = 26, int senkouBDelayPeriod = 26)
            : base(name)
        {
            TenkanMaximum         = new Maximum(name + "_TenkanMax", tenkanPeriod);
            TenkanMinimum         = new Minimum(name + "_TenkanMin", tenkanPeriod);
            KijunMaximum          = new Maximum(name + "_KijunMax", kijunPeriod);
            KijunMinimum          = new Minimum(name + "_KijunMin", kijunPeriod);
            SenkouBMaximum        = new Maximum(name + "_SenkouBMaximum", senkouBPeriod);
            SenkouBMinimum        = new Minimum(name + "_SenkouBMinimum", senkouBPeriod);
            DelayedTenkanSenkouA  = new Delay(name + "DelayedTenkan", senkouADelayPeriod);
            DelayedKijunSenkouA   = new Delay(name + "DelayedKijun", senkouADelayPeriod);
            DelayedMaximumSenkouB = new Delay(name + "DelayedMax", senkouBDelayPeriod);
            DelayedMinimumSenkouB = new Delay(name + "DelayedMin", senkouBDelayPeriod);

            SenkouA = new FunctionalIndicator <DataPointBar>(
                name + "_SenkouA",
                input => computeSenkouA(senkouAPeriod, input),
                senkouA => DelayedTenkanSenkouA.IsReady && DelayedKijunSenkouA.IsReady,
                () =>
            {
                Tenkan.Reset();
                Kijun.Reset();
            });

            SenkouB = new FunctionalIndicator <DataPointBar>(
                name + "_SenkouB",
                input => computeSenkouB(senkouBPeriod, input),
                senkouA => DelayedMaximumSenkouB.IsReady && DelayedMinimumSenkouB.IsReady,
                () =>
            {
                Tenkan.Reset();
                Kijun.Reset();
            });

            Tenkan = new FunctionalIndicator <DataPointBar>(
                name + "_Tenkan",
                input => ComputeTenkan(tenkanPeriod, input),
                tenkan => TenkanMaximum.IsReady && TenkanMinimum.IsReady,
                () =>
            {
                TenkanMaximum.Reset();
                TenkanMinimum.Reset();
            });

            Kijun = new FunctionalIndicator <DataPointBar>(
                name + "_Kijun",
                input => ComputeKijun(kijunPeriod, input),
                kijun => KijunMaximum.IsReady && KijunMinimum.IsReady,
                () =>
            {
                KijunMaximum.Reset();
                KijunMinimum.Reset();
            });
        }
Beispiel #2
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(DataPointBar input)
        {
            Minimum.Update(input.Occured, input.TimeZone, input.Low);
            Maximum.Update(input.Occured, input.TimeZone, input.High);

            if (!IsReady)
            {
                return(0);
            }

            var range = (Maximum.Current.Price - Minimum.Current.Price);

            return(range == 0 ? 0 : -100m * (Maximum.Current.Price - input.Close) / range);
        }
Beispiel #3
0
        /// <summary>
        /// Creates a new AroonOscillator from the specified up/down periods.
        /// </summary>
        /// <param name="name">The name of this indicator</param>
        /// <param name="upPeriod">The lookback period to determine the highest high for the AroonDown</param>
        /// <param name="downPeriod">The lookback period to determine the lowest low for the AroonUp</param>
        public AroonOscillator(string name, int upPeriod, int downPeriod)
            : base(name)
        {
            var max = new Maximum(name + "_Max", upPeriod + 1);

            AroonUp = new FunctionalIndicator <IndicatorDataPoint>(name + "_AroonUp",
                                                                   input => ComputeAroonUp(upPeriod, max, input),
                                                                   aroonUp => max.IsReady,
                                                                   () => max.Reset()
                                                                   );

            var min = new Minimum(name + "_Min", downPeriod + 1);

            AroonDown = new FunctionalIndicator <IndicatorDataPoint>(name + "_AroonDown",
                                                                     input => ComputeAroonDown(downPeriod, min, input),
                                                                     aroonDown => min.IsReady,
                                                                     () => min.Reset()
                                                                     );
        }
Beispiel #4
0
 /// <summary>
 /// AroonUp = 100 * (period - {periods since max})/period
 /// </summary>
 /// <param name="upPeriod">The AroonUp period</param>
 /// <param name="max">A Maximum indicator used to compute periods since max</param>
 /// <param name="input">The next input data</param>
 /// <returns>The AroonUp value</returns>
 private static decimal ComputeAroonUp(int upPeriod, Maximum max, IndicatorDataPoint input)
 {
     max.Update(input);
     return(100m * (upPeriod - max.PeriodsSinceMaximum) / upPeriod);
 }
Beispiel #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DonchianChannel"/> class.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="upperPeriod">The period for the upper channel.</param>
 /// <param name="lowerPeriod">The period for the lower channel</param>
 public DonchianChannel(string name, int upperPeriod, int lowerPeriod)
     : base(name)
 {
     UpperBand = new Maximum(name + "_UpperBand", upperPeriod);
     LowerBand = new Minimum(name + "_LowerBand", lowerPeriod);
 }
Beispiel #6
0
 /// <summary>
 /// Resets this indicator and both sub-indicators (Max and Min)
 /// </summary>
 public override void Reset()
 {
     Maximum.Reset();
     Minimum.Reset();
     base.Reset();
 }
Beispiel #7
0
 /// <summary>
 /// Creates a new Williams %R.
 /// </summary>
 /// <param name="name">The name of this indicator</param>
 /// <param name="period">The lookback period to determine the highest high for the AroonDown</param>
 public WilliamsPercentR(string name, int period)
     : base(name)
 {
     Maximum = new Maximum(name + "_Max", period);
     Minimum = new Minimum(name + "_Min", period);
 }