/// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            double normdistvalue;
            //double vb;
            double vs;

            if (CurrentBar < 2)
            {
                return;
            }
            deltaPrice[0] = Close[0] - Close[1];
            //Print( "deltaPrice = " + deltaPrice[0] );
            if (CurrentBar < 100)
            {
                return;
            }

            // Formula for bulk volume classification is
            // Vb = V * CDF(deltaP/sigmadeltaP)
            //
            sigmaDeltaP             = StdDev(deltaPrice, 30)[1];
            deltaPriceOverSigmal[0] = deltaPrice[0] / sigmaDeltaP;
            normdistvalue           = NORMDIST(deltaPriceOverSigmal[0], /*SMA(deltaPriceOverSigmal,30)[0]*/ 0, StdDev(deltaPriceOverSigmal, 30)[0], true);
            vb[0] = volumeBarSize * normdistvalue;
            vs    = volumeBarSize - vb[0];
            //Print(" normdistvalue = " + normdistvalue);
            //Print(" vb = " + vb[0]);
            //Print("bar = " + CurrentBar);
            //Print("time = " + Time[0].Date + "  " + "  " + Time[0].Hour + "  " + Time[0].Minute);
            if (Double.IsNaN(vb[0]))
            {
            }
            else
            {
                VolBucketPlot.Set(EMA(vb, 50)[0]);
            }
            //VolBucketPlot.Set(EMA(vb,20)[0]);
            // Sum vb over volume bucket size
            // if vol bucket size is 24000, then you add 3 consecutive vb

            // or, set chart to 24000 vol
            // count if new bar, then count until 8000, calculate vb
        }
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            double normdistvalue = 0;
            double vb_bucket_total;
            double vs_bucket_total;
            double accum_vdelta = 0;
            double sigmaVPIN    = 0;

            if (CurrentBar < 4)
            {
                return;
            }

            deltaPrice[0] = Close[0] - Close[1];
            //Print( "deltaPrice = " + deltaPrice[0] );

            if (CurrentBar < 100)
            {
                return;
            }

            // Formula for bulk volume classification is
            // Vb = V * CDF(deltaP/sigmadeltaP)
            //
            sigmaDeltaP             = StdDev(deltaPrice, 30)[0];
            deltaPriceOverSigmal[0] = deltaPrice[0] / sigmaDeltaP;
            normdistvalue           = NORMDIST(deltaPriceOverSigmal[0], /*SMA(deltaPriceOverSigmal,200)[0]*/ 0, StdDev(deltaPriceOverSigmal, 100)[0], true);
            vb[0] = volumeBarSize * normdistvalue;
            vs[0] = volumeBarSize - vb[0];
            //Print(" normdistvalue = " + normdistvalue);
            //Print(" vb = " + vb[0]);
            //Print("bar = " + CurrentBar);
            //Print("time = " + Time[0].Date + "  " + "  " + Time[0].Hour + "  " + Time[0].Minute);

            // Sum Vb 3 times to make a vol bucket of V = 24000
            if (CurrentBar > 103)
            {
                vb_bucket[0] = vb[0] + vb[1] + vb[2];
                vs_bucket[0] = vs[0] + vs[1] + vs[2];
            }
            // update VPIN calculation
            // Sum of ( |vs_bucket - vb_bucket| ) over n / n.V
            //
            if (CurrentBar > 150)
            {
                for (int i = 0; i < n_windowsize; i++)
                {
                    accum_vdelta += Math.Abs(vs_bucket[i] - vb_bucket[i]);
                }
                VPIN[0] = accum_vdelta / (n_windowsize * 24000);

                // Calculate CDF of VPIN
                sigmaVPIN  = StdDev(VPIN, 100)[0];
                cdfVPIN[0] = NORMDIST(VPIN[0], SMA(VPIN, 200)[0], sigmaVPIN, true);
            }



            if (Double.IsNaN(vb[0]))
            {
                VolBucketPlot.Set(0);
            }
            else
            {
                if (useCDF > 0)
                {
                    //VolBucketPlot.Set(cdfVPIN[0]);
                    VolBucketPlot.Set(JurikJMA(cdfVPIN, 50, 10)[0]);
                }
                else
                {
                    VolBucketPlot.Set(VPIN[0]);
                }
            }

            // Sum vb over volume bucket size
            // if vol bucket size is 24000, then you add 3 consecutive vb

            // or, set chart to 24000 vol
            // count if new bar, then count until 8000, calculate vb
        }