/// <summary>
 /// Creates a new MACD with the specified parameters
 /// </summary>
 /// <param name="name">The name of this indicator</param>
 /// <param name="fastPeriod">The fast moving average period</param>
 /// <param name="slowPeriod">The slow moving average period</param>
 /// <param name="signalPeriod">The signal period</param>
 /// <param name="type">The type of moving averages to use</param>
 public MovingAverageConvergenceDivergence(string name, int fastPeriod, int slowPeriod, int signalPeriod, MovingAverageType type = MovingAverageType.Simple)
     : base(name)
 {
     Fast = type.AsIndicator(name + "_Fast", fastPeriod);
     Slow = type.AsIndicator(name + "_Slow", slowPeriod);
     Signal = type.AsIndicator(name + "_Signal", signalPeriod);
 }
Example #2
0
 /// <summary>
 /// Initializes a new instance of the CommodityChannelIndex class
 /// </summary>
 /// <param name="name">The name of this indicator</param>
 /// <param name="period">The period of the standard deviation and moving average (middle band)</param>
 /// <param name="movingAverageType">The type of moving average to be used</param>
 public CommodityChannelIndex(string name, int period, MovingAverageType movingAverageType = MovingAverageType.Simple)
     : base(name)
 {
     MovingAverageType = movingAverageType;
     TypicalPriceAverage = movingAverageType.AsIndicator(name + "_TypicalPriceAvg", period);
     TypicalPriceMeanDeviation = new MeanAbsoluteDeviation(name + "_TypicalPriceMAD", period);
 }
Example #3
0
 /// <summary>
 /// Initializes a new instance of the RelativeStrengthIndex class with the specified name and period
 /// </summary>
 /// <param name="name">The name of this indicator</param>
 /// <param name="period">The period used for up and down days</param>
 /// <param name="movingAverageType">The type of moving average to be used for computing the average gain/loss values</param>
 public RelativeStrengthIndex(string name, int period, MovingAverageType movingAverageType = MovingAverageType.Wilders)
     : base(name)
 {
     MovingAverageType = movingAverageType;
     AverageGain = movingAverageType.AsIndicator(name + "Up", period);
     AverageLoss = movingAverageType.AsIndicator(name + "Down", period);
 }
Example #4
0
 /// <summary>
 /// Initializes a new instance of the BollingerBands class
 /// </summary>
 /// <param name="name">The name of this indicator</param>
 /// <param name="period">The period of the standard deviation and moving average (middle band)</param>
 /// <param name="k">The number of standard deviations specifying the distance between the middle band and upper or lower bands</param>
 /// <param name="movingAverageType">The type of moving average to be used</param>
 public BollingerBands(String name, int period, decimal k, MovingAverageType movingAverageType = MovingAverageType.Simple)
     : base(name)
 {
     MovingAverageType = movingAverageType;
     StandardDeviation = new StandardDeviation(name + "_StandardDeviation", period);
     MiddleBand = movingAverageType.AsIndicator(name + "_MiddleBand", period);
     LowerBand = MiddleBand.Minus(StandardDeviation.Times(k), name + "_LowerBand");
     UpperBand = MiddleBand.Plus(StandardDeviation.Times(k), name + "_UpperBand");
 }
Example #5
0
        /// <summary>
        /// Creates a new AverageTrueRange indicator using the specified period and moving average type
        /// </summary>
        /// <param name="name">The name of this indicator</param>
        /// <param name="period">The smoothing period used to smooth the true range values</param>
        /// <param name="movingAverageType">The type of smoothing used to smooth the true range values</param>
        public AverageTrueRange(string name, int period, MovingAverageType movingAverageType = MovingAverageType.Wilders)
            : base(name)
        {
            _smoother = movingAverageType.AsIndicator(string.Format("{0}_{1}", name, movingAverageType), period);

            IBaseDataBar previous = null;
            TrueRange = new FunctionalIndicator<IBaseDataBar>(name + "_TrueRange", currentBar =>
            {
                // in our ComputeNextValue function we'll just call the ComputeTrueRange
                var nextValue = ComputeTrueRange(previous, currentBar);
                previous = currentBar;
                return nextValue;
            }   // in our IsReady function we just need at least one sample
            , trueRangeIndicator => trueRangeIndicator.Samples >= 1
            );
        }
        /// <summary>
        /// Calculates Moving Average Envelopes indicator
        /// </summary>
        /// <param name="input">Input signal</param>
        /// <param name="movingAverageType">Type of moving average to use</param>
        /// <param name="periods">Number of periods</param>
        /// <param name="percentage">Percentage for the envelopes (%)</param>
        /// <returns>Object containing operation results</returns>
        public static MovingAverageEnvelopesResult MovingAverageEnvelopes(IEnumerable<double> input, MovingAverageType movingAverageType, int periods, double percentage)
        {
            List<double> movingAverage = null;
            List<double> upperEnvelope = new List<double>();
            List<double> lowerEnvelope = new List<double>();

            int offset = 0;

            if (movingAverageType == MovingAverageType.Simple)
            {
                var sma = SMA(input, periods);

                movingAverage = sma.Values;
                offset = sma.StartIndexOffset;
            }
            else if (movingAverageType == MovingAverageType.Exponential)
            {
                var ema = EMA(input, periods);

                movingAverage = ema.Values;
                offset = ema.StartIndexOffset;
            }

            foreach (var point in movingAverage)
            {
                double upperEnvelopePoint = point + point * percentage / 100;
                double lowerEnvelopePoint = point - point * percentage / 100;

                upperEnvelope.Add(upperEnvelopePoint);
                lowerEnvelope.Add(lowerEnvelopePoint);
            }

            var result = new MovingAverageEnvelopesResult()
            {
                UpperEnvelope = upperEnvelope,
                MovingAverage = movingAverage,
                LowerEnvelope = lowerEnvelope,
                StartIndexOffset = offset
            };

            return result;
        }
Example #7
0
        /// <summary>
        /// Initializes a new instance of the KeltnerChannels class
        /// </summary>
        /// <param name="name">The name of this indicator</param>
        /// <param name="period">The period of the average true range and moving average (middle band)</param>
        /// <param name="k">The number of multiples specifying the distance between the middle band and upper or lower bands</param>
        /// <param name="movingAverageType">The type of moving average to be used</param>
        public KeltnerChannels(string name, int period, decimal k, MovingAverageType movingAverageType = MovingAverageType.Simple)
            : base(name)
        {
            WarmUpPeriod = period;

            //Initialise ATR and SMA
            AverageTrueRange = new AverageTrueRange(name + "_AverageTrueRange", period, movingAverageType);
            MiddleBand       = movingAverageType.AsIndicator(name + "_MiddleBand", period);

            //Compute Lower Band
            LowerBand = new FunctionalIndicator <IBaseDataBar>(name + "_LowerBand",
                                                               input => MiddleBand.IsReady ? MiddleBand.Current.Value - AverageTrueRange.Current.Value * k : decimal.Zero,
                                                               lowerBand => MiddleBand.IsReady,
                                                               () => MiddleBand.Reset()
                                                               );

            //Compute Upper Band
            UpperBand = new FunctionalIndicator <IBaseDataBar>(name + "_UpperBand",
                                                               input => MiddleBand.IsReady ? MiddleBand.Current.Value + AverageTrueRange.Current.Value * k : decimal.Zero,
                                                               upperBand => MiddleBand.IsReady,
                                                               () => MiddleBand.Reset()
                                                               );
        }
Example #8
0
        /// <summary>
        /// Initializes a new instance of the KeltnerChannels class
        /// </summary>
        /// <param name="name">The name of this indicator</param>
        /// <param name="period">The period of the average true range and moving average (middle band)</param>
        /// <param name="k">The number of multiples specifying the distance between the middle band and upper or lower bands</param>
        /// <param name="movingAverageType">The type of moving average to be used</param>
        public KeltnerChannels(string name, int period, decimal k, MovingAverageType movingAverageType = MovingAverageType.Simple)
            : base(name)
        {
            _k = k;

            //Initialise ATR and SMA
            AverageTrueRange = new AverageTrueRange(name + "_AverageTrueRange", period, MovingAverageType.Simple);
            MiddleBand = movingAverageType.AsIndicator(name + "_MiddleBand", period);

            //Compute Lower Band
            LowerBand = new FunctionalIndicator<TradeBar>(name + "_LowerBand",
                input => ComputeLowerBand(),
                lowerBand => MiddleBand.IsReady,
                () => MiddleBand.Reset()
                );

            //Compute Upper Band
            UpperBand = new FunctionalIndicator<TradeBar>(name + "_UpperBand",
                input => ComputeUpperBand(),
                upperBand => MiddleBand.IsReady,
                () => MiddleBand.Reset()
                );
        }
Example #9
0
        /// <summary>
        /// Initializes a new instance of the KeltnerChannels class
        /// </summary>
        /// <param name="name">The name of this indicator</param>
        /// <param name="period">The period of the average true range and moving average (middle band)</param>
        /// <param name="k">The number of multiples specifying the distance between the middle band and upper or lower bands</param>
        /// <param name="movingAverageType">The type of moving average to be used</param>
        public KeltnerChannels(string name, int period, decimal k, MovingAverageType movingAverageType = MovingAverageType.Simple)
            : base(name)
        {
            _k = k;

            //Initialize ATR and SMA
            AverageTrueRange = new AverageTrueRange(name + "_AverageTrueRange", period, MovingAverageType.Simple);
            MiddleBand       = movingAverageType.AsIndicator(name + "_MiddleBand", period);

            //Compute Lower Band
            LowerBand = new FunctionalIndicator <DataPointBar>(name + "_LowerBand",
                                                               input => ComputeLowerBand(),
                                                               lowerBand => MiddleBand.IsReady,
                                                               () => MiddleBand.Reset()
                                                               );

            //Compute Upper Band
            UpperBand = new FunctionalIndicator <DataPointBar>(name + "_UpperBand",
                                                               input => ComputeUpperBand(),
                                                               upperBand => MiddleBand.IsReady,
                                                               () => MiddleBand.Reset()
                                                               );
        }
Example #10
0
        /// <summary>
        ///      Initializes a new instance of the KeltnerChannels class
        /// </summary>
        /// <param name="name">The name of this indicator</param>
        /// <param name="period">The period of the average true range and moving average (middle band)</param>
        /// <param name="k">The number of multiples specifying the distance between the middle band and upper or lower bands</param>
        /// <param name="movingAverageType">The type of moving average to be used</param>
        public KeltnerChannels(string name, int period, double k, MovingAverageType movingAverageType = MovingAverageType.Simple)
            : base(name)
        {
            _k           = k;
            WarmUpPeriod = period;

            //Initialise ATR and SMA
            AverageTrueRange = new AverageTrueRange(name + "_AverageTrueRange", period, MovingAverageType.Simple);
            MiddleBand       = movingAverageType.AsIndicator(name + "_MiddleBand", period);

            //Compute Lower Band
            LowerBand = new FunctionalIndicator(name + "_LowerBand",
                                                (time, input) => MiddleBand.IsReady ? MiddleBand - AverageTrueRange * _k : Constants.Zero,
                                                lowerBand => MiddleBand.IsReady,
                                                () => MiddleBand.Reset()
                                                );

            //Compute Upper Band
            UpperBand = new FunctionalIndicator(name + "_UpperBand",
                                                (time, input) => MiddleBand.IsReady ? MiddleBand + AverageTrueRange * _k : Constants.Zero,
                                                upperBand => MiddleBand.IsReady,
                                                () => MiddleBand.Reset()
                                                );
        }
        /* B_BANDS */

        private static BollingerBandsResult B_BANDS(List <Candle> candles,
                                                    int period,
                                                    double stdDevUp,
                                                    double stdDevDown,
                                                    MovingAverageType maType,
                                                    IndicatorCalculationBase calculationBase = IndicatorCalculationBase.Close,
                                                    Func <decimal[], decimal[], decimal[], decimal[], IndicatorSignal> signalLogic = null)
        {
            decimal[] input;
            if (calculationBase == IndicatorCalculationBase.Close)
            {
                input = candles.Select(c => c.Close).ToArray();
            }

            else if (calculationBase == IndicatorCalculationBase.Open)
            {
                input = candles.Select(c => c.Open).ToArray();
            }

            else if (calculationBase == IndicatorCalculationBase.High)
            {
                input = candles.Select(c => c.High).ToArray();
            }

            else if (calculationBase == IndicatorCalculationBase.Low)
            {
                input = candles.Select(c => c.Low).ToArray();
            }

            else
            {
                input = candles.Select(c => c.Close).ToArray();
            }

            return(B_BANDS(input, period, stdDevUp, stdDevDown, maType, signalLogic));
        }
Example #12
0
        protected override bool InternalSetParameters(List <ScriptingParameterBase> parameterBases)
        {
            Series[0].Color     = ((SeriesParam)parameterBases[0]).Color;
            Series[0].Thickness = ((SeriesParam)parameterBases[0]).Thickness;

            Series[1].Color     = ((SeriesParam)parameterBases[1]).Color;
            Series[1].Thickness = ((SeriesParam)parameterBases[1]).Thickness;

            Series[2].Color     = ((SeriesParam)parameterBases[2]).Color;
            Series[2].Thickness = ((SeriesParam)parameterBases[2]).Thickness;

            Period1 = ((IntParam)parameterBases[3]).Value;
            Shift1  = ((IntParam)parameterBases[4]).Value;
            Period2 = ((IntParam)parameterBases[5]).Value;
            Shift2  = ((IntParam)parameterBases[6]).Value;
            Period3 = ((IntParam)parameterBases[7]).Value;
            Shift3  = ((IntParam)parameterBases[8]).Value;

            Smoothing = ParseMovingAverageConstants((StringParam)parameterBases[9]);
            Type      = ParsePriceConstants((StringParam)parameterBases[10]);

            DisplayName = String.Format("{0}_{1}_{2}_{3}_{4}_{5}", Name, Period1, Period2, Period3, Smoothing, Type);
            return(true);
        }
Example #13
0
 /// <summary>
 /// Initializes a new instance of the RelativeStrengthIndex class with the specified name and period
 /// </summary>
 /// <param name="period">The period used for up and down days</param>
 /// <param name="movingAverageType">The type of moving average to be used for computing the average gain/loss values</param>
 public RelativeStrengthIndex(int period, MovingAverageType movingAverageType = MovingAverageType.Wilders)
     : this("RSI" + period, period, movingAverageType)
 {
 }
Example #14
0
 public Indicator.TSSuperTrend TSSuperTrend(int length, MovingAverageType maType, double multiplier, int smooth, SuperTrendMode stMode)
 {
     return _indicator.TSSuperTrend(Input, length, maType, multiplier, smooth, stMode);
 }
Example #15
0
        /// <summary>
        /// Creates a MACD indicator for the symbol. The indicator will be automatically updated on the given resolution.
        /// </summary>
        /// <param name="symbol">The symbol whose MACD we want</param>
        /// <param name="fastPeriod">The period for the fast moving average</param>
        /// <param name="slowPeriod">The period for the slow moving average</param>
        /// <param name="signalPeriod">The period for the signal moving average</param>
        /// <param name="type">The type of moving average to use for the MACD</param>
        /// <param name="resolution">The resolution</param>
        /// <param name="selector">Selects a value from the BaseData to send into the indicator, if null defaults to the Value property of BaseData (x => x.Value)</param>
        /// <returns>The moving average convergence divergence between the fast and slow averages</returns>
        public MovingAverageConvergenceDivergence MACD(string symbol, int fastPeriod, int slowPeriod, int signalPeriod, MovingAverageType type = MovingAverageType.Simple, Resolution?resolution = null, Func <BaseData, decimal> selector = null)
        {
            var name = CreateIndicatorName(symbol, string.Format("MACD({0},{1})", fastPeriod, slowPeriod), resolution);
            var macd = new MovingAverageConvergenceDivergence(name, fastPeriod, slowPeriod, signalPeriod, type);

            RegisterIndicator(symbol, macd, resolution, selector);
            return(macd);
        }
Example #16
0
        public void CalculateHeikenAshi(MarketSeries marketSeries, int index, int maPeriods, MovingAverageType maType, int periods = 1)
        {
            int seriesIndex = marketSeries.OpenTime.GetIndexByTime(marketSeries.OpenTime[index]);

            if (seriesIndex <= maPeriods)
            {
                return;
            }

            double barMaOpen  = GetSeriesMovingAverageValue(marketSeries, SeriesType.Open, maPeriods, maType, seriesIndex);
            double barMaHigh  = GetSeriesMovingAverageValue(marketSeries, SeriesType.High, maPeriods, maType, seriesIndex);
            double barMaLow   = GetSeriesMovingAverageValue(marketSeries, SeriesType.Low, maPeriods, maType, seriesIndex);
            double barMaClose = GetSeriesMovingAverageValue(marketSeries, SeriesType.Close, maPeriods, maType, seriesIndex);

            _close[seriesIndex] = (barMaOpen + barMaClose + barMaHigh + barMaLow) / 4;

            if (seriesIndex < periods || double.IsNaN(_open[seriesIndex - 1]))
            {
                _open[seriesIndex] = (barMaOpen + barMaClose) / 2;
                _high[seriesIndex] = barMaHigh;
                _low[seriesIndex]  = barMaLow;
            }
            else
            {
                _open[seriesIndex] = (_open[seriesIndex - periods] + _close[seriesIndex - periods]) / 2;
                _high[seriesIndex] = Math.Max(barMaHigh, Math.Max(_open[seriesIndex], _close[seriesIndex]));
                _low[seriesIndex]  = Math.Min(barMaLow, Math.Min(_open[seriesIndex], _close[seriesIndex]));
            }
        }
Example #17
0
            public SymbolData(QCAlgorithmFramework algorithm, Security security, int fastPeriod, int slowPeriod, int signalPeriod, MovingAverageType movingAverageType, Resolution resolution)
            {
                Security     = security;
                Consolidator = algorithm.ResolveConsolidator(security.Symbol, resolution);
                algorithm.SubscriptionManager.AddConsolidator(security.Symbol, Consolidator);

                MACD = new MovingAverageConvergenceDivergence(fastPeriod, slowPeriod, signalPeriod, movingAverageType);

                algorithm.RegisterIndicator(security.Symbol, MACD, Consolidator);
            }
Example #18
0
        public Interfaces.Indicators.MovingAverage MovingAverage(int period, MovingAverageType maType, DataStream stream)
        {
            var nmodule = new MovingAverage(period, maType, stream, _manager.Agent.TimeFrame);

            return(_manager.Subscribe <MovingAverage>(nmodule));
        }
 public MovingAverageConvergenceDivergence(string name, int fastPeriod, int slowPeriod, int signalPeriod, MovingAverageType type = MovingAverageType.Simple)
     : base(name)
 {
     Fast      = type.AsIndicator(name + "_Fast", fastPeriod);
     Slow      = type.AsIndicator(name + "_Slow", slowPeriod);
     Signal    = type.AsIndicator(name + "_Signal", signalPeriod);
     Histogram = new Identity(name + "_Histogram");
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="PercentagePriceOscillator"/> class using the specified parameters.
 /// </summary>
 /// <param name="fastPeriod">The fast moving average period</param>
 /// <param name="slowPeriod">The slow moving average period</param>
 /// <param name="movingAverageType">The type of moving average to use</param>
 public PercentagePriceOscillator(int fastPeriod, int slowPeriod, MovingAverageType movingAverageType = MovingAverageType.Simple)
     : this(string.Format("PPO({0},{1})", fastPeriod, slowPeriod), fastPeriod, slowPeriod, movingAverageType)
 {
 }
Example #21
0
 /// <summary>
 /// Initializes a new instance of the DeMarkerIndicator class with the specified period
 /// </summary>
 /// <param name="period">The period of the  DeMarker Indicator</param>
 /// <param name="type">The type of moving average to use in calculations</param>
 public DeMarkerIndicator(int period, MovingAverageType type = MovingAverageType.Simple)
     : this($"DEM({period},{type})", period, type)
 {
 }
Example #22
0
		public MovingAverageDefinition(MovingAverageType type, int period, PriceFormula formula)
		{
			MovingAverageType = type;
			Period = period;
			Formula = formula;
		}
Example #23
0
 /// <summary>
 /// Creates a new AverageTrueRange indicator using the specified period and moving average type
 /// </summary>
 /// <param name="name">The name of this indicator</param>
 /// <param name="period">The smoothing period used to smooth the true range values</param>
 /// <param name="movingAverageType">The type of smoothing used to smooth the true range values</param>
 public AverageTrueRange(string name, int period, MovingAverageType movingAverageType = MovingAverageType.Wilders)
     : base(name)
 {
     _smoother = movingAverageType.AsIndicator(string.Format("{0}_{1}", name, movingAverageType), period);
 }
Example #24
0
 /// <summary>
 /// Initializes a new instance of the BollingerBands class
 /// </summary>
 /// <param name="period">The period of the standard deviation and moving average (middle band)</param>
 /// <param name="k">The number of standard deviations specifying the distance between the middle band and upper or lower bands</param>
 /// <param name="movingAverageType">The type of moving average to be used</param>
 public BollingerBands(int period, decimal k, MovingAverageType movingAverageType = MovingAverageType.Simple)
     : this($"BB({period},{k})", period, k, movingAverageType)
 {
 }
Example #25
0
 /// <summary>
 /// Initializes a new instance of the CommodityChannelIndex class
 /// </summary>
 /// <param name="period">The period of the standard deviation and moving average (middle band)</param>
 /// <param name="movingAverageType">The type of moving average to be used</param>
 public CommodityChannelIndex(int period, MovingAverageType movingAverageType = MovingAverageType.Simple)
     : this("CCI" + period, period, movingAverageType)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="PercentagePriceOscillator"/> class using the specified parameters.
 /// </summary> 
 /// <param name="fastPeriod">The fast moving average period</param>
 /// <param name="slowPeriod">The slow moving average period</param>
 /// <param name="movingAverageType">The type of moving average to use</param>
 public PercentagePriceOscillator(int fastPeriod, int slowPeriod, MovingAverageType movingAverageType = MovingAverageType.Simple)
     : this(string.Format("PPO({0},{1})", fastPeriod, slowPeriod), fastPeriod, slowPeriod, movingAverageType)
 {
 }
Example #27
0
 /// <summary>
 /// Creates a new AverageTrueRange indicator using the specified period and moving average type
 /// </summary>
 /// <param name="period">The smoothing period used to smooth the true range values</param>
 /// <param name="movingAverageType">The type of smoothing used to smooth the true range values</param>
 public AverageTrueRange(int period, MovingAverageType movingAverageType = MovingAverageType.Wilders)
     : this("ATR" + period, period, movingAverageType)
 {
 }
Example #28
0
 /// <summary>
 /// Initializes a new instance of the KeltnerChannels class
 /// </summary>
 /// <param name="period">The period of the average true range and moving average (middle band)</param>
 /// <param name="k">The number of multiplies specifying the distance between the middle band and upper or lower bands</param>
 /// <param name="movingAverageType">The type of moving average to be used</param>
 public KeltnerChannels(int period, decimal k, MovingAverageType movingAverageType = MovingAverageType.Simple)
     : this(string.Format("KC({0},{1})", period, k), period, k, movingAverageType)
 {
 }
Example #29
0
 /// <summary>
 /// Creates a new SuperTrend indicator using the specified period, multiplier and moving average type
 /// </summary>
 /// <param name="period">The smoothing period used in average true range</param>
 /// <param name="multiplier">The coefficient used in calculations of basic upper and lower bands</param>
 /// <param name="movingAverageType">The type of smoothing used to smooth the true range values</param>
 public SuperTrend(int period, decimal multiplier, MovingAverageType movingAverageType = MovingAverageType.Wilders)
     : this($"SuperTrend({period},{multiplier})", period, multiplier, movingAverageType)
 {
 }
 /// <summary>
 /// Creates a new MACD with the specified parameters
 /// </summary>
 /// <param name="fastPeriod">The fast moving average period</param>
 /// <param name="slowPeriod">The slow moving average period</param>
 /// <param name="signalPeriod">The signal period</param>
 /// <param name="type">The type of moving averages to use</param>
 public MovingAverageConvergenceDivergence(int fastPeriod, int slowPeriod, int signalPeriod, MovingAverageType type = MovingAverageType.Simple)
     : this(string.Format("MACD({0},{1})", fastPeriod, slowPeriod), fastPeriod, slowPeriod, signalPeriod, type)
 {
 }
Example #31
0
 public BollingerStrategy(Robot robot, DataSeries source, int periods, double deviations, MovingAverageType ma, string condition = null)
     : base(robot)
 {
     this.Source     = source;
     this.Periods    = periods;
     this.Deviations = deviations;
     this.MAType     = ma;
     this.Condition  = condition;
     Initialize();
 }
Example #32
0
 /// <summary>
 /// Initializes a new instance of the KeltnerChannels class
 /// </summary>
 /// <param name="period">The period of the average true range and moving average (middle band)</param>
 /// <param name="k">The number of multiplies specifying the distance between the middle band and upper or lower bands</param>
 /// <param name="movingAverageType">The type of moving average to be used</param>
 public KeltnerChannels(int period, decimal k, MovingAverageType movingAverageType = MovingAverageType.Simple)
     : this(string.Format("KC({0},{1})", period, k), period, k, movingAverageType)
 {
 }
Example #33
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PercentagePriceOscillator"/> class using the specified parameters.
 /// </summary>
 /// <param name="fastPeriod">The fast moving average period</param>
 /// <param name="slowPeriod">The slow moving average period</param>
 /// <param name="movingAverageType">The type of moving average to use</param>
 public PercentagePriceOscillator(int fastPeriod, int slowPeriod, MovingAverageType movingAverageType = MovingAverageType.Simple)
     : this($"PPO({fastPeriod},{slowPeriod})", fastPeriod, slowPeriod, movingAverageType)
 {
 }
 /// <summary>
 /// Creates a new MACD with the specified parameters
 /// </summary>
 /// <param name="fastPeriod">The fast moving average period</param>
 /// <param name="slowPeriod">The slow moving average period</param>
 /// <param name="signalPeriod">The signal period</param>
 /// <param name="type">The type of moving averages to use</param>
 public MovingAverageConvergenceDivergence(int fastPeriod, int slowPeriod, int signalPeriod, MovingAverageType type = MovingAverageType.Simple)
     : this(string.Format("MACD({0},{1})", fastPeriod, slowPeriod), fastPeriod, slowPeriod, signalPeriod, type)
 {
 }
 /// <summary>
 /// Initializes a new instance of the CommodityChannelIndex class
 /// </summary>
 /// <param name="period">The period of the standard deviation and moving average (middle band)</param>
 /// <param name="movingAverageType">The type of moving average to be used</param>
 public CommodityChannelIndex(int period, MovingAverageType movingAverageType = MovingAverageType.Simple)
     : this($"CCI({period})", period, movingAverageType)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="PercentagePriceOscillator"/> class using the specified name and parameters.
 /// </summary>
 /// <param name="name">The name of this indicator</param>
 /// <param name="fastPeriod">The fast moving average period</param>
 /// <param name="slowPeriod">The slow moving average period</param>
 /// <param name="movingAverageType">The type of moving average to use</param>
 public PercentagePriceOscillator(string name, int fastPeriod, int slowPeriod, MovingAverageType movingAverageType = MovingAverageType.Simple)
     : base(name, fastPeriod, slowPeriod, movingAverageType)
 {
 }
Example #37
0
        public Interfaces.Indicators.BollingerBands BollingerBands(int period, double sdUp, double sdDown, DataStream stream, TimeSpan barSize, MovingAverageType maType)
        {
            var ntemplate = new BollingerBands(period, sdUp, sdDown, stream, barSize, maType);

            return(_manager.Subscribe <BollingerBands>(ntemplate));
        }
Example #38
0
 /// <summary>
 /// Initializes a new instance of the BollingerBands class
 /// </summary>
 /// <param name="period">The period of the standard deviation and moving average (middle band)</param>
 /// <param name="k">The number of standard deviations specifying the distance between the middle band and upper or lower bands</param>
 /// <param name="movingAverageType">The type of moving average to be used</param>
 public BollingerBands(int period, decimal k, MovingAverageType movingAverageType = MovingAverageType.Simple)
     : this(string.Format("BB({0},{1})", period, k), period, k, movingAverageType)
 {
 }
Example #39
0
 private void Construct(int period, DataStream stream, TimeSpan barSize, double sdUp, double sdDown, Func <Bar, decimal> compute, MovingAverageType maType)
 {
     _timeSpan   = barSize;
     Period      = period;
     DataStreams = new[] { stream };
     _maType     = maType;
     Compute     = compute ?? (x => (x.Close));
     _sdUp       = sdUp;
     _sdDown     = sdDown;
     Period      = sdUp > sdDown ? (int)sdUp : (int)sdDown;
     _upperBand  = new IndicatorDataSerie();
     _middleBand = new IndicatorDataSerie();
     _lowerBand  = new IndicatorDataSerie();
 }
Example #40
0
        public Interfaces.Indicators.BollingerBands BollingerBands(int period, double sdUp, double sdDown, DataStream stream, TimeSpan barSize, MovingAverageType maType, Func <Bar, decimal> compute)
        {
            var nmodule = new BollingerBands(period, sdUp, sdDown, stream, barSize, maType, compute);

            return(_manager.Subscribe <BollingerBands>(nmodule));
        }
Example #41
0
 public BollingerBands(int period, double sdUp, double sdDown, DataStream stream, TimeSpan barSize, MovingAverageType maType)
 {
     Construct(period, stream, barSize, sdUp, sdDown, null, maType);
 }
Example #42
0
        public Interfaces.Indicators.MovingAverage MovingAverage(int period, MovingAverageType maType, DataStream stream, TimeSpan barSize, Func <Bar, decimal> comp = null)
        {
            var nmodule = new MovingAverage(period, barSize, maType, stream, comp);

            return(_manager.Subscribe <MovingAverage>(nmodule));
        }
Example #43
0
 public BollingerBands(int period, double sdUp, double sdDown, DataStream stream, TimeSpan barSize, MovingAverageType maType, Func <Bar, decimal> compute)
 {
     Construct(period, stream, barSize, sdUp, sdDown, compute, maType);
 }
Example #44
0
 /// <summary>
 /// Initializes a new instance of the BollingerBands class
 /// </summary>
 /// <param name="period">The period of the standard deviation and moving average (middle band)</param>
 /// <param name="k">The number of standard deviations specifying the distance between the middle band and upper or lower bands</param>
 /// <param name="movingAverageType">The type of moving average to be used</param>
 public BollingerBands(int period, decimal k, MovingAverageType movingAverageType = MovingAverageType.Simple)
     : this(string.Format("BB({0},{1})", period, k), period, k, movingAverageType)
 {
 }
Example #45
0
		public IList<double> AddMovingAverageCalculator(MovingAverageType type, int period, PriceFormula formula)
		{
			IMovingAverageCalculator ma;

			switch (type)
			{
				case MovingAverageType.Simple :
					ma = new SimpleMACalculator();
					break;

				case MovingAverageType.Exponential:
					ma = new ExponentialMACalculator();
					break;

				default: throw new NotImplementedException();
			}

			int id = _dataCollection.AddMovingAverageCollection();
			_movingAverageCalculators.Add(id, new KeyValuePair<PriceCalculator, IMovingAverageCalculator>(GetPriceCalculator(formula), ma));

			IList<double> values = _dataCollection.GetMovingAverageCollection(id);
			System.Diagnostics.Debug.Assert(values != null);
			if (values == null)
				throw new InvalidOperationException();

			ma.Initialize(period);
			return values;
		}
Example #46
0
 /// <summary>
 /// Creates a new AverageTrueRange indicator using the specified period and moving average type
 /// </summary>
 /// <param name="period">The smoothing period used to smooth the true range values</param>
 /// <param name="movingAverageType">The type of smoothing used to smooth the true range values</param>
 public AverageTrueRange(int period, MovingAverageType movingAverageType = MovingAverageType.Wilders)
     : this("ATR" + period, period, movingAverageType)
 {
 }
Example #47
0
 /// <summary>
 /// Initializes a new instance of the KeltnerChannels class
 /// </summary>
 /// <param name="period">The period of the average true range and moving average (middle band)</param>
 /// <param name="k">The number of multiplies specifying the distance between the middle band and upper or lower bands</param>
 /// <param name="movingAverageType">The type of moving average to be used</param>
 public KeltnerChannels(int period, decimal k, MovingAverageType movingAverageType = MovingAverageType.Simple)
     : this($"KC({period},{k})", period, k, movingAverageType)
 {
 }
Example #48
0
        /// <summary>
        /// TSSuperTrend Indicator developed by TradingStudies.com (Version 2.5)
        /// </summary>
        /// <returns></returns>
        public TSSuperTrend TSSuperTrend(Data.IDataSeries input, int length, MovingAverageType maType, double multiplier, int smooth, SuperTrendMode stMode)
        {
            if (cacheTSSuperTrend != null)
                for (int idx = 0; idx < cacheTSSuperTrend.Length; idx++)
                    if (cacheTSSuperTrend[idx].Length == length && cacheTSSuperTrend[idx].MaType == maType && Math.Abs(cacheTSSuperTrend[idx].Multiplier - multiplier) <= double.Epsilon && cacheTSSuperTrend[idx].Smooth == smooth && cacheTSSuperTrend[idx].StMode == stMode && cacheTSSuperTrend[idx].EqualsInput(input))
                        return cacheTSSuperTrend[idx];

            lock (checkTSSuperTrend)
            {
                checkTSSuperTrend.Length = length;
                length = checkTSSuperTrend.Length;
                checkTSSuperTrend.MaType = maType;
                maType = checkTSSuperTrend.MaType;
                checkTSSuperTrend.Multiplier = multiplier;
                multiplier = checkTSSuperTrend.Multiplier;
                checkTSSuperTrend.Smooth = smooth;
                smooth = checkTSSuperTrend.Smooth;
                checkTSSuperTrend.StMode = stMode;
                stMode = checkTSSuperTrend.StMode;

                if (cacheTSSuperTrend != null)
                    for (int idx = 0; idx < cacheTSSuperTrend.Length; idx++)
                        if (cacheTSSuperTrend[idx].Length == length && cacheTSSuperTrend[idx].MaType == maType && Math.Abs(cacheTSSuperTrend[idx].Multiplier - multiplier) <= double.Epsilon && cacheTSSuperTrend[idx].Smooth == smooth && cacheTSSuperTrend[idx].StMode == stMode && cacheTSSuperTrend[idx].EqualsInput(input))
                            return cacheTSSuperTrend[idx];

                TSSuperTrend indicator = new TSSuperTrend();
                indicator.BarsRequired = BarsRequired;
                indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
                indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
                indicator.Input = input;
                indicator.Length = length;
                indicator.MaType = maType;
                indicator.Multiplier = multiplier;
                indicator.Smooth = smooth;
                indicator.StMode = stMode;
                Indicators.Add(indicator);
                indicator.SetUp();

                TSSuperTrend[] tmp = new TSSuperTrend[cacheTSSuperTrend == null ? 1 : cacheTSSuperTrend.Length + 1];
                if (cacheTSSuperTrend != null)
                    cacheTSSuperTrend.CopyTo(tmp, 0);
                tmp[tmp.Length - 1] = indicator;
                cacheTSSuperTrend = tmp;
                return indicator;
            }
        }
Example #49
0
 public BollingerBands BollingerBands(DataSeries series, int periods, double standardDeviation, MovingAverageType movingAverageType)
 {
     return(new BollingerBands(new TBollingerBands
     {
         TimeFrame = owner.TimeFrame,
         Symbol = owner.Symbol.Code,
         Periods = periods,
         StandardDev = standardDeviation,
         MovingAverageType = movingAverageType,
         IndicatorBarSource = series,
     }));
 }
Example #50
0
        /// <summary>
        /// TSSuperTrend Indicator developed by TradingStudies.com (Version 2.5)
        /// </summary>
        /// <returns></returns>
        public Indicator.TSSuperTrend TSSuperTrend(Data.IDataSeries input, int length, MovingAverageType maType, double multiplier, int smooth, SuperTrendMode stMode)
        {
            if (InInitialize && input == null)
                throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");

            return _indicator.TSSuperTrend(input, length, maType, multiplier, smooth, stMode);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="PercentagePriceOscillator"/> class using the specified name and parameters.
 /// </summary> 
 /// <param name="name">The name of this indicator</param>
 /// <param name="fastPeriod">The fast moving average period</param>
 /// <param name="slowPeriod">The slow moving average period</param>
 /// <param name="movingAverageType">The type of moving average to use</param>
 public PercentagePriceOscillator(string name, int fastPeriod, int slowPeriod, MovingAverageType movingAverageType = MovingAverageType.Simple)
     : base(name, fastPeriod, slowPeriod, movingAverageType)
 {
 }