Exemplo n.º 1
0
        /// <summary>
        /// The TMA (Triangular Moving Average) is a weighted moving average. Compared to the WMA which puts more weight on the latest price bar, the TMA puts more weight on the data in the middle of the specified period.
        /// </summary>
        /// <returns></returns>
        public TMA TMA(Data.IDataSeries input, int period)
        {
            if (cacheTMA != null)
            {
                for (int idx = 0; idx < cacheTMA.Length; idx++)
                {
                    if (cacheTMA[idx].Period == period && cacheTMA[idx].EqualsInput(input))
                    {
                        return(cacheTMA[idx]);
                    }
                }
            }

            lock (checkTMA)
            {
                checkTMA.Period = period;
                period          = checkTMA.Period;

                if (cacheTMA != null)
                {
                    for (int idx = 0; idx < cacheTMA.Length; idx++)
                    {
                        if (cacheTMA[idx].Period == period && cacheTMA[idx].EqualsInput(input))
                        {
                            return(cacheTMA[idx]);
                        }
                    }
                }

                TMA indicator = new TMA();
                indicator.BarsRequired        = BarsRequired;
                indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
                indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                indicator.MaximumBarsLookBack         = MaximumBarsLookBack;
#endif
                indicator.Input  = input;
                indicator.Period = period;
                Indicators.Add(indicator);
                indicator.SetUp();

                TMA[] tmp = new TMA[cacheTMA == null ? 1 : cacheTMA.Length + 1];
                if (cacheTMA != null)
                {
                    cacheTMA.CopyTo(tmp, 0);
                }
                tmp[tmp.Length - 1] = indicator;
                cacheTMA            = tmp;
                return(indicator);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// The TMA (Triangular Moving Average) is a weighted moving average. Compared to the WMA which puts more weight on the latest price bar, the TMA puts more weight on the data in the middle of the specified period.
        /// </summary>
        /// <returns></returns>
        public TMA TMA(Data.IDataSeries input, int period)
        {
            if (cacheTMA != null)
                for (int idx = 0; idx < cacheTMA.Length; idx++)
                    if (cacheTMA[idx].Period == period && cacheTMA[idx].EqualsInput(input))
                        return cacheTMA[idx];

            lock (checkTMA)
            {
                checkTMA.Period = period;
                period = checkTMA.Period;

                if (cacheTMA != null)
                    for (int idx = 0; idx < cacheTMA.Length; idx++)
                        if (cacheTMA[idx].Period == period && cacheTMA[idx].EqualsInput(input))
                            return cacheTMA[idx];

                TMA indicator = new TMA();
                indicator.BarsRequired = BarsRequired;
                indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
                indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
                indicator.Input = input;
                indicator.Period = period;
                Indicators.Add(indicator);
                indicator.SetUp();

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