/// <summary>
		/// Modified SuperTrend Indicator based on a Moving Median
		/// </summary>
		/// <returns></returns>
		public anaSuperTrendM1 anaSuperTrendM1(IDataSeries input, double multiplier, int periodATR, int periodMedian)
		{
			if (cacheanaSuperTrendM1 != null)
				for (int idx = 0; idx < cacheanaSuperTrendM1.Length; idx++)
					if (Math.Abs(cacheanaSuperTrendM1[idx].Multiplier - multiplier) <= double.Epsilon &&
					    cacheanaSuperTrendM1[idx].PeriodAtr == periodATR && cacheanaSuperTrendM1[idx].PeriodMedian == periodMedian &&
					    cacheanaSuperTrendM1[idx].EqualsInput(input))
						return cacheanaSuperTrendM1[idx];

			lock (checkanaSuperTrendM1)
			{
				checkanaSuperTrendM1.Multiplier = multiplier;
				multiplier = checkanaSuperTrendM1.Multiplier;
				checkanaSuperTrendM1.PeriodAtr = periodATR;
				periodATR = checkanaSuperTrendM1.PeriodAtr;
				checkanaSuperTrendM1.PeriodMedian = periodMedian;
				periodMedian = checkanaSuperTrendM1.PeriodMedian;

				if (cacheanaSuperTrendM1 != null)
					for (int idx = 0; idx < cacheanaSuperTrendM1.Length; idx++)
						if (Math.Abs(cacheanaSuperTrendM1[idx].Multiplier - multiplier) <= double.Epsilon &&
						    cacheanaSuperTrendM1[idx].PeriodAtr == periodATR && cacheanaSuperTrendM1[idx].PeriodMedian == periodMedian &&
						    cacheanaSuperTrendM1[idx].EqualsInput(input))
							return cacheanaSuperTrendM1[idx];

				var indicator = new anaSuperTrendM1();
				indicator.BarsRequired = BarsRequired;
				indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
				indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
				indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
				indicator.Input = input;
				indicator.Multiplier = multiplier;
				indicator.PeriodAtr = periodATR;
				indicator.PeriodMedian = periodMedian;
				Indicators.Add(indicator);
				indicator.SetUp();

				var tmp = new anaSuperTrendM1[cacheanaSuperTrendM1 == null ? 1 : cacheanaSuperTrendM1.Length + 1];
				if (cacheanaSuperTrendM1 != null)
					cacheanaSuperTrendM1.CopyTo(tmp, 0);
				tmp[tmp.Length - 1] = indicator;
				cacheanaSuperTrendM1 = tmp;
				return indicator;
			}
		}
Exemple #2
0
        /// <summary>
        /// Modified SuperTrend Indicator based on a Moving Median
        /// </summary>
        /// <returns></returns>
        public anaSuperTrendM1 anaSuperTrendM1(IDataSeries input, double multiplier, int periodATR, int periodMedian)
        {
            if (cacheanaSuperTrendM1 != null)
            {
                for (int idx = 0; idx < cacheanaSuperTrendM1.Length; idx++)
                {
                    if (Math.Abs(cacheanaSuperTrendM1[idx].Multiplier - multiplier) <= double.Epsilon &&
                        cacheanaSuperTrendM1[idx].PeriodAtr == periodATR && cacheanaSuperTrendM1[idx].PeriodMedian == periodMedian &&
                        cacheanaSuperTrendM1[idx].EqualsInput(input))
                    {
                        return(cacheanaSuperTrendM1[idx]);
                    }
                }
            }

            lock (checkanaSuperTrendM1)
            {
                checkanaSuperTrendM1.Multiplier = multiplier;
                multiplier = checkanaSuperTrendM1.Multiplier;
                checkanaSuperTrendM1.PeriodAtr = periodATR;
                periodATR = checkanaSuperTrendM1.PeriodAtr;
                checkanaSuperTrendM1.PeriodMedian = periodMedian;
                periodMedian = checkanaSuperTrendM1.PeriodMedian;

                if (cacheanaSuperTrendM1 != null)
                {
                    for (int idx = 0; idx < cacheanaSuperTrendM1.Length; idx++)
                    {
                        if (Math.Abs(cacheanaSuperTrendM1[idx].Multiplier - multiplier) <= double.Epsilon &&
                            cacheanaSuperTrendM1[idx].PeriodAtr == periodATR && cacheanaSuperTrendM1[idx].PeriodMedian == periodMedian &&
                            cacheanaSuperTrendM1[idx].EqualsInput(input))
                        {
                            return(cacheanaSuperTrendM1[idx]);
                        }
                    }
                }

                var indicator = new anaSuperTrendM1();
                indicator.BarsRequired        = BarsRequired;
                indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
                indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                indicator.MaximumBarsLookBack         = MaximumBarsLookBack;
#endif
                indicator.Input        = input;
                indicator.Multiplier   = multiplier;
                indicator.PeriodAtr    = periodATR;
                indicator.PeriodMedian = periodMedian;
                Indicators.Add(indicator);
                indicator.SetUp();

                var tmp = new anaSuperTrendM1[cacheanaSuperTrendM1 == null ? 1 : cacheanaSuperTrendM1.Length + 1];
                if (cacheanaSuperTrendM1 != null)
                {
                    cacheanaSuperTrendM1.CopyTo(tmp, 0);
                }
                tmp[tmp.Length - 1]  = indicator;
                cacheanaSuperTrendM1 = tmp;
                return(indicator);
            }
        }