/// <summary>
 /// This method is used to configure the indicator and is called once before any bar data is loaded.
 /// </summary>
 protected override void Initialize()
 {
     CalculateOnBarClose = false;
     Overlay             = false;
     PriceTypeSupported  = false;
     volstats            = null;
 }
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            if (volstats == null)
            {
                volstats = Z20091129VolumeStats(bundleMilliseconds, bundleTrades, calcMethod, maxSize, minSize);
            }

            double curDelta = (calcWithTicks?(volstats.UpTradeCount[0] - volstats.DnTradeCount[0]):volstats.OneBarDelta[0]);

            if (CurrentBar > 1)
            {
                dsClose.Set(dsClose[1] + curDelta);
            }
            else
            {
                dsClose.Set(curDelta);
            }

            if (lastBar != CurrentBar)
            {
                lastBar = CurrentBar;

                dsOpen.Set(dsClose[0]);
                dsHigh.Set(dsClose[0]);
                dsLow.Set(dsClose[0]);
            }

            if (dsClose[0] > dsHigh[0])
            {
                dsHigh.Set(dsClose[0]);
            }
            if (dsClose[0] < dsLow[0])
            {
                dsLow.Set(dsClose[0]);
            }
            Value.Set(dsClose[0]);
        }
Exemple #3
0
        /// <summary>
        /// A helper indicator for tracking volume stats
        /// </summary>
        /// <returns></returns>
        public Z20091129VolumeStats Z20091129VolumeStats(Data.IDataSeries input, long bundleMilliseconds, bool bundleTrades, VolumeStatsMode calcMethod, double maxSize, double minSize)
        {
            if (cacheZ20091129VolumeStats != null)
            {
                for (int idx = 0; idx < cacheZ20091129VolumeStats.Length; idx++)
                {
                    if (cacheZ20091129VolumeStats[idx].BundleMilliseconds == bundleMilliseconds && cacheZ20091129VolumeStats[idx].BundleTrades == bundleTrades && cacheZ20091129VolumeStats[idx].CalcMethod == calcMethod && Math.Abs(cacheZ20091129VolumeStats[idx].MaxSize - maxSize) <= double.Epsilon && Math.Abs(cacheZ20091129VolumeStats[idx].MinSize - minSize) <= double.Epsilon && cacheZ20091129VolumeStats[idx].EqualsInput(input))
                    {
                        return(cacheZ20091129VolumeStats[idx]);
                    }
                }
            }

            lock (checkZ20091129VolumeStats)
            {
                checkZ20091129VolumeStats.BundleMilliseconds = bundleMilliseconds;
                bundleMilliseconds = checkZ20091129VolumeStats.BundleMilliseconds;
                checkZ20091129VolumeStats.BundleTrades = bundleTrades;
                bundleTrades = checkZ20091129VolumeStats.BundleTrades;
                checkZ20091129VolumeStats.CalcMethod = calcMethod;
                calcMethod = checkZ20091129VolumeStats.CalcMethod;
                checkZ20091129VolumeStats.MaxSize = maxSize;
                maxSize = checkZ20091129VolumeStats.MaxSize;
                checkZ20091129VolumeStats.MinSize = minSize;
                minSize = checkZ20091129VolumeStats.MinSize;

                if (cacheZ20091129VolumeStats != null)
                {
                    for (int idx = 0; idx < cacheZ20091129VolumeStats.Length; idx++)
                    {
                        if (cacheZ20091129VolumeStats[idx].BundleMilliseconds == bundleMilliseconds && cacheZ20091129VolumeStats[idx].BundleTrades == bundleTrades && cacheZ20091129VolumeStats[idx].CalcMethod == calcMethod && Math.Abs(cacheZ20091129VolumeStats[idx].MaxSize - maxSize) <= double.Epsilon && Math.Abs(cacheZ20091129VolumeStats[idx].MinSize - minSize) <= double.Epsilon && cacheZ20091129VolumeStats[idx].EqualsInput(input))
                        {
                            return(cacheZ20091129VolumeStats[idx]);
                        }
                    }
                }

                Z20091129VolumeStats indicator = new Z20091129VolumeStats();
                indicator.BarsRequired        = BarsRequired;
                indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
                indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                indicator.MaximumBarsLookBack         = MaximumBarsLookBack;
#endif
                indicator.Input = input;
                indicator.BundleMilliseconds = bundleMilliseconds;
                indicator.BundleTrades       = bundleTrades;
                indicator.CalcMethod         = calcMethod;
                indicator.MaxSize            = maxSize;
                indicator.MinSize            = minSize;
                Indicators.Add(indicator);
                indicator.SetUp();

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