示例#1
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            if (CurrentBar != lastSeen)
            {
                var olded = extdat.getExtraData(1, Bars, CurrentBar);
                lastSeen = CurrentBar;
                if (olded != null)
                {
                    UpCount.Set(1, ((double)olded.UpTicks) / Math.Max(olded.UpCount, 1));
                    DnCount.Set(1, ((double)(-olded.DnTicks)) / Math.Max(olded.DnCount, 1));
                    PlotColors[0][1] = Color.Green;
                    PlotColors[1][1] = Color.Red;
                }
            }

            var ed = extdat.getExtraData(0, Bars, CurrentBar);

            if (ed != null)
            {
                UpCount.Set(((double)(ed.UpTicks)) / Math.Max(ed.UpCount, 1));
                DnCount.Set(((double)(-ed.DnTicks)) / Math.Max(ed.DnCount, 1));
                PlotColors[0][0] = Color.Cyan;
                PlotColors[1][0] = Color.Magenta;
            }
        }
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            var ed = extdat.getExtraData(0, this.Bars, CurrentBar);

            if (ed != null)
            {
                Value.Set(ed.dClose);
            }
            else
            {
                Value.Set(0);
            }
        }
示例#3
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            var ed = extdat.getExtraData(0, Bars, CurrentBar);

            if (ed == null)
            {
                return;
            }
            double denom = ed.UpTicks + ed.DnTicks;
            double unsm  = 0;

            if (denom > 0)
            {
                unsm = (ed.UpTicks - ed.DnTicks) / denom;
            }

            if (lastSeen != CurrentBar)
            {
                lastSeen = CurrentBar;
                osm1     = sm1;
                osm2     = sm2;
            }

            sm1 = osm1 + alpha1 * (unsm - osm1);
            sm2 = osm2 + alpha2 * (sm1 - osm2);
            TVI.Set(sm2);
        }
示例#4
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            var ed = extdat.getExtraData(0, Bars, CurrentBar);

            if (ed != null)
            {
                //Print("DT at "+idx+" is " + ed.dt);
                UpCount.Set(ed.UpTicks);
                DnCount.Set(-ed.DnTicks);
            }
        }
示例#5
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            var ed = extdat.getExtraData(0, Bars, CurrentBar);

            if (ed == null)
            {
                return;
            }


            Value.Set(ed.dClose);
        }
示例#6
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            double bvwap = 0;  double bvol = 0;
            double svwap = 0;  double svol = 0;
            double tvwap = 0;  double tvol = 0;

            for (int i = 0; i < avgLen; ++i)
            {
                var ed = extdat.getExtraData(i, Bars, CurrentBar);
                if (ed == null)
                {
                    break;
                }
                bvwap += ed.UpTicks * Median[i];
                svwap += ed.DnTicks * Median[i];
                tvwap += Volume[i] * Median[i];
                bvol  += ed.UpTicks;
                svol  += ed.DnTicks;
                tvol  += Volume[i];
            }
            if (bvol > 0)
            {
                bvwap /= bvol;
            }
            if (svol > 0)
            {
                svwap /= svol;
            }
            if (tvol > 0)
            {
                tvwap /= tvol;
            }

            var ed2 = extdat.getExtraData(0, Bars, CurrentBar);

            if (ed2 == null)
            {
                return;
            }
            double diff      = Math.Abs(tvwap - bvwap) - Math.Abs(tvwap - svwap);
            bool   biasgreen = true;

            if (diff > 0)
            {
                biasgreen = false;
            }
            else if (diff == 0)
            {
                biasgreen = ed2.UpTicks >= ed2.DnTicks;
            }
            double p1 = (bvwap - svwap) / TickSize;

            if (p1 * p1 > 100)
            {
                p1 = 0.0;
            }
            pones.Set(Math.Abs(p1));
            double denom = ed2.UpTicks + ed2.DnTicks;
            double pct   = 0.5;

            if (denom > 0)
            {
                pct = ed2.UpTicks / denom;
            }

            if (pct > 0.65)
            {
                Values[0].Set(p1);
                Values[1].Reset();
                Values[2].Reset();
                Values[3].Set(-p1);
            }
            else if (pct < 0.35)
            {
                Values[0].Reset();
                Values[1].Set(p1);
                Values[2].Set(-p1);
                Values[3].Reset();
            }
            else
            {
                Values[0].Reset();
                Values[1].Set(p1);
                Values[2].Reset();
                Values[3].Set(-p1);
            }

            var biasnum = 4;

            if (pones[0] >= pones[1])
            {
                BackColor = (biasgreen?uplight:dnlight);
            }
            else
            {
                BackColor = (biasgreen?updark:dndark);
            }
            Values[4].Set(b1.Upper[0]);
            Values[5].Set(b2.Upper[0]);
            Values[6].Set(-b1.Upper[0]);
            Values[7].Set(-b2.Upper[0]);
        }
示例#7
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            var ed = extdat.getExtraData(0, Bars, CurrentBar);

            if (CurrentBar != lastBarSeen)
            {
                memGotNewBar();
                lastBarSeen = CurrentBar;

                if (ed != null)
                {
                    prevUp = ed.UpTicks;
                    prevDn = ed.DnTicks;
                    for (double p = Low[0]; p <= High[0]; p += TickSize)
                    {
                        long upt; long dnt;
                        ed.getUpDnTicksAtPrice(TickSize, p, out upt, out dnt);
                        if (upt > 0)
                        {
                            memInsertDeltaUp(p, upt);
                        }
                        if (dnt > 0)
                        {
                            memInsertDeltaDn(p, dnt);
                        }
                    }
                }
            }
            else
            {
                if (ed != null)
                {
                    if (ed.UpTicks > prevUp)
                    {
                        memInsertDeltaUp(Close[0], ed.UpTicks - prevUp);
                        prevUp = ed.UpTicks;
                    }
                    if (ed.DnTicks > prevDn)
                    {
                        memInsertDeltaDn(Close[0], ed.DnTicks - prevDn);
                        prevDn = ed.DnTicks;
                    }
                }
            }


            double totalUp, totalDn, currentUp, currentDn;

            memPressureForBar(out totalUp, out currentUp, out totalDn, out currentDn);

            if (compactForm)
            {
                if (totalUp > totalDn)
                {
                    totalUp -= totalDn; totalDn = 0;
                }
                else
                {
                    totalDn -= totalUp; totalUp = 0;
                }
            }

            Buyers.Set(totalUp);
            Sellers.Set(-totalDn);
            BuyersThisBar.Set(currentUp);
            SellersThisBar.Set(-currentDn);
        }
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            var ed = extdat.getExtraData(0, Bars, CurrentBar);

            if (ed == null)
            {
                return;
            }

            if (CurrentBar != lastSeenBar)
            {
                for (int i = 0; i < 4; ++i)
                {
                    pol[i] = ol[i];         // remember previous bar value...
                    phl[i] = hl[i];
                    pll[i] = ll[i];
                    pcl[i] = cl[i];
                }
                lastSeenBar = CurrentBar;
            }


            // update all the Laguerre numbers....
            ol[0] = (1 - gamma) * ed.dOpen + gamma * pol[0];
            hl[0] = (1 - gamma) * ed.dHigh + gamma * phl[0];
            ll[0] = (1 - gamma) * ed.dLow + gamma * pll[0];
            cl[0] = (1 - gamma) * ed.dClose + gamma * pcl[0];
            for (int i = 1; i < 4; ++i)
            {
                ol[i] = -gamma * ol[i - 1] + pol[i - 1] + gamma * pol[i];
                hl[i] = -gamma * hl[i - 1] + phl[i - 1] + gamma * phl[i];
                ll[i] = -gamma * ll[i - 1] + pll[i - 1] + gamma * pll[i];
                cl[i] = -gamma * cl[i - 1] + pcl[i - 1] + gamma * pcl[i];
            }

            double value1 = 0.0;
            double value2 = 0.0;

            for (int i = 0; i < 4; ++i)
            {
                value1 += (cl[i] - ol[i]);
                value2 += (hl[i] - ll[i]);
            }

            if (value2 != 0.0)
            {
                unsmoothed.Set(100.0 * value1 / value2);
            }
            else
            {
                if ((CurrentBar > 1) && unsmoothed.ContainsValue(1))
                {
                    unsmoothed.Set(unsmoothed[1]);
                }
                else
                {
                    unsmoothed.Set(0);
                }
            }

            if (weightma == null)
            {
                weightma = WMA(unsmoothed, smoothing);
                expma    = EMA(weightma.Value, trigger);
            }

            ECO.Set(weightma[0]);
            TriggerLine.Set(expma[0]);
            Histogram.Set(weightma[0] - expma[0]);
        }
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            double bvwap = 0;  double bvol = 0;
            double svwap = 0;  double svol = 0;
            double tvwap = 0;  double tvol = 0;
            var    ed = extdat.getExtraData(0, Bars, CurrentBar);

            if (ed == null)
            {
                pones.Set(0); return;
            }
            double lowbound = Low[0] - TickSize / 2.0;
            long   upcount, dncount;
            double totalup = 0;
            double totaldn = 0;

            for (double p = High[0]; p > lowbound; p -= TickSize)
            {
                ed.getUpDnTicksAtPrice(TickSize, p, out upcount, out dncount);
                totalup += (p * upcount);
                totaldn += (p * dncount);
            }
            buytotals.Set(totalup);
            selltotals.Set(totaldn);

            for (int i = 0; i < avgLen; ++i)
            {
                var ed2 = extdat.getExtraData(i, Bars, CurrentBar);
                if (ed2 == null)
                {
                    break;
                }
                bvwap += buytotals[i];
                svwap += selltotals[i];
                bvol  += ed2.UpTicks;
                svol  += ed2.DnTicks;
            }

            tvwap = bvwap + svwap;
            tvol  = bvol + svol;
            if (bvol > 0)
            {
                bvwap /= bvol;
            }
            if (svol > 0)
            {
                svwap /= svol;
            }
            if (tvol > 0)
            {
                tvwap /= tvol;
            }

            double diff      = Math.Abs(tvwap - bvwap) - Math.Abs(tvwap - svwap);
            bool   biasgreen = true;

            if (diff > 0)
            {
                biasgreen = false;
            }
            else if (diff == 0)
            {
                biasgreen = ed.UpTicks >= ed.DnTicks;
            }
            double p1 = (bvwap - svwap) / TickSize;

            if (p1 * p1 > 100)
            {
                p1 = 0.0;
            }
            pones.Set(Math.Abs(p1));
            double denom = ed.UpTicks + ed.DnTicks;
            double pct   = 0.5;

            if (denom > 0)
            {
                pct = ed.UpTicks / denom;
            }

            if (pct > 0.65)
            {
                Values[0].Set(p1);
                Values[1].Reset();
                Values[2].Reset();
                Values[3].Set(-p1);
            }
            else if (pct < 0.35)
            {
                Values[0].Reset();
                Values[1].Set(p1);
                Values[2].Set(-p1);
                Values[3].Reset();
            }
            else
            {
                Values[0].Reset();
                Values[1].Set(p1);
                Values[2].Reset();
                Values[3].Set(-p1);
            }

            var biasnum = 4;

            if (pones[0] >= pones[1])
            {
                BackColor = (biasgreen?uplight:dnlight);
            }
            else
            {
                BackColor = (biasgreen?updark:dndark);
            }
            Values[4].Set(b1.Upper[0]);
            Values[5].Set(b2.Upper[0]);
            Values[6].Set(-b1.Upper[0]);
            Values[7].Set(-b2.Upper[0]);
        }
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            double bvwap = 0;  double bvol = 0;
            double svwap = 0;  double svol = 0;
            double tvwap = 0;  double tvol = 0;

            for (int i = 0; i < avgLen; ++i)
            {
                var ed = extdat.getExtraData(i, Bars, CurrentBar);
                if (ed == null)
                {
                    break;
                }
                bvwap += ed.UpTicks * Median[i];
                svwap += ed.DnTicks * Median[i];
                tvwap += Volume[i] * Median[i];
                bvol  += ed.UpTicks;
                svol  += ed.DnTicks;
                tvol  += Volume[i];
            }
            if (bvol > 0)
            {
                bvwap /= bvol;
            }
            if (svol > 0)
            {
                svwap /= svol;
            }
            if (tvol > 0)
            {
                tvwap /= tvol;
            }

            var ed2 = extdat.getExtraData(0, Bars, CurrentBar);

            if (ed2 == null)
            {
                return;
            }
            double diff      = Math.Abs(tvwap - bvwap) - Math.Abs(tvwap - svwap);
            bool   biasgreen = true;

            if (diff > 0)
            {
                biasgreen = false;
            }
            else if (diff == 0)
            {
                biasgreen = ed2.UpTicks >= ed2.DnTicks;
            }
            double p1 = 0.5 * (bvwap - svwap);

            if (ed2.UpTicks > ed2.DnTicks)
            {
                Values[0].Set(p1);
                Values[3].Set(-p1);
                if (biasgreen)
                {
                    Values[4].Set(0);
                }
                else
                {
                    Values[7].Set(0);
                }
            }
            else if (ed2.UpTicks == ed2.DnTicks)
            {
                Values[1].Set(p1);
                Values[3].Set(-p1);
                if (biasgreen)
                {
                    Values[4].Set(0);
                }
                else
                {
                    Values[7].Set(0);
                }
            }
            else
            {
                Values[1].Set(p1);
                Values[2].Set(-p1);
                if (biasgreen)
                {
                    Values[5].Set(0);
                }
                else
                {
                    Values[6].Set(0);
                }
            }
        }
示例#11
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            if (CurrentBar != lastBarSeen)
            {
                lastBarSeen = CurrentBar;

                // update session's volume profile...
                if (displayvolprofile)
                {
                    if (useprevsession)
                    {
                        if (Bars.FirstBarOfSession)
                        {
                            vprofClear();
                            for (int bn = CurrentBar - lastSessionBarNum; bn >= 1; --bn)
                            {
                                addApproximateData(High[bn], Low[bn], Volume[bn]);
                            }
                            lastSessionBarNum = CurrentBar;                             // remember for next session
                        }
                    }
                    else
                    {
                        if (Bars.FirstBarOfSession)
                        {
                            vprofClear();
                        }
                        else
                        {
                            var ed = extdat.getExtraData(1, Bars, CurrentBar);
                            if (ed != null)
                            {
                                addExtendedData(ed, High[1], Low[1]);
                            }
                        }
                    }
                }

                if (displaytradedamounts)
                {
                    lastVolume = 0;
                }
            }
            else
            {
                rt = true;
            }

            if (displaytradedamounts)
            {
                var c = Close[0];
                var v = ((long)(Volume[0])) - lastVolume;
                if (c == tradedPrices[0])
                {
                    if (rt)
                    {
                        tradedAmounts[0] += v;
                    }
                }
                else if (c == tradedPrices[1])
                {
                    if (rt)
                    {
                        tradedAmounts[1] += v;
                    }
                }
                else
                {
                    if (c > tradedPrices[0])
                    {
                        taIdx = 0;
                    }
                    else if (c < tradedPrices[1])
                    {
                        taIdx = 1;
                    }
                    else
                    {
                        ++taIdx; if (taIdx > 1)
                        {
                            taIdx = 0;
                        }
                    }
                    // update traded prices...
                    tradedPrices[taIdx]  = c;
                    tradedAmounts[taIdx] = (rt?v:0);
                }
                lastVolume = ((long)Volume[0]);
            }
        }