Beispiel #1
0
        void drawQuotePoint(xGraphics g, int x)
        {
            stPriceboardState ps = mContext.mPriceboard.getPriceboard(mAlarm.code);

            //  current price
            float price = ps.getCurrentPrice();
            uint  color = mContext.valToColorF(price, ps.getCe(), ps.getRef(), ps.getFloor());

            if (price == 0)
            {
                price = ps.getRef();
            }

            Font          f  = mContext.getBigFont();
            StringBuilder sb = Utils.getSB();

            //  current price
            sb.AppendFormat("{0:F2}", (float)price);
            int y = 0;

            //l.setFont(f);
            g.setColor(color);
            g.drawString(f, sb.ToString(), x, y);

            y += f.Height;
            //  change
            float change        = price - ps.getRef();
            float changePercent = 0;

            if (ps.getRef() > 0)
            {
                changePercent = (change * 100) / ps.getRef();
            }
            sb.Length = 0;
            sb.AppendFormat("{0:F1} ({1:F2}%)", (float)change, changePercent);

            f = mContext.getFontText();

            g.setColor(color);
            g.drawString(f, sb.ToString(), x, y);
        }
Beispiel #2
0
        public void update()
        {
            if (mShare.isIndex())
            {
                if (mShare.mMarketID == 1)
                {
                    setImageIndex(0);
                }
                else if (mShare.mMarketID == 2)
                {
                    setImageIndex(1);
                }
                //  truncate the code
                StringBuilder sb = Utils.sb;
                sb.Length = 0;
                for (int i = 0; i < mShare.mCode.Length; i++)
                {
                    if (mShare.mCode[i] == '^')
                    {
                        continue;
                    }
                    sb.Append(mShare.mCode[i]);
                    //if (sb.Length > 5)
                    //break;
                }
                setTextFont(P_CODE, mContext.getFontSmall());
                setTextForCell(P_CODE, sb.ToString(), C.COLOR_WHITE);

                stPriceboardStateIndex pi = mContext.mPriceboard.getPriceboardIndexOfMarket(mShare.mMarketID);
                //  khop
                uint color = C.COLOR_YELLOW;
                if (pi.changed_point > 0)
                {
                    color = C.COLOR_GREEN;
                }
                else
                {
                    color = C.COLOR_RED;
                }

                setTextForCell(P_PRICE, String.Format("{0:F2}", pi.current_point), color);

                Utils.sb.Length = 0;
                if (pi.changed_point > 0)
                {
                    Utils.sb.AppendFormat("+{0:F2}", (float)(pi.changed_point / 100));
                }
                else
                {
                    Utils.sb.AppendFormat("{0:F2}", ((float)pi.changed_point / 100));
                }
                //  change
                setTextForCell(P_COMPARE, Utils.sb.ToString(), color);
            }
            else
            {
                stPriceboardState ps = mContext.mPriceboard.getPriceboard(mShare.mID);
                if (ps != null)
                {
                    if (ps.getMarketID() == 1)
                    {
                        if (mContext.mAlarmManager.isAlarmInstalled(ps.getCode()))
                        {
                            setImageIndex(2);
                        }
                        else
                        {
                            setImageIndex(0);
                        }
                    }
                    else if (ps.getMarketID() == 2)
                    {
                        if (mContext.mAlarmManager.isAlarmInstalled(ps.getCode()))
                        {
                            setImageIndex(3);
                        }
                        else
                        {
                            setImageIndex(1);
                        }
                    }
                    //  code
                    setTextForCell(P_CODE, ps.getCode(), C.COLOR_WHITE);
                    //setID(ps.getID());
                    //  ref
                    float reference = ps.getRef();
                    float ce        = ps.getCe();
                    float floor     = ps.getFloor();
                    float price     = ps.getCurrentPrice();

                    if (price == 0)
                    {
                        price = ps.getRef();
                    }

                    //  khop
                    uint color = mContext.valToColorF(price, ce, reference, floor);
                    Utils.sb.Length = 0;
                    Utils.sb.AppendFormat("{0:F2}", (float)price);
                    setTextForCell(P_PRICE, Utils.sb.ToString(), color);

                    //  extra info
                    if (mShare.mCompareText == null)
                    {
                        Utils.sb.Length = 0;
                        Utils.sb.AppendFormat("{0:F2}", (float)ps.getChange());
                        mShare.mCompareText = Utils.sb.ToString();
                    }

                    if (mShare.mCompareText != null)
                    {
                        setTextForCell(P_COMPARE, mShare.mCompareText, C.COLOR_WHITE);
                    }
                }
            }
        }
        //  code | _ref | KL1 | G1 |= GiaKhop | KLKhop | TongKL =| KL1 | G1 |=== TB | Cao | Thap
        virtual protected void updateQuote()
        {
            if (getID() < 0)
            {
                return;
            }

            Context ctx = Context.getInstance();
            stCell  c;

            if (getID() == 0)
            {
                //  code
                setCellValue(0, "▼ Mã\nTC", C.COLOR_ORANGE);

                setCellValue(2, "M3/KL", C.COLOR_GRAY);
                setCellValue(3, "M2/KL", C.COLOR_GRAY);
                setCellValue(4, "M1/KL", C.COLOR_GRAY);

                setCellValue(5, "Khớp", C.COLOR_GRAY);
                setCellValue(6, "+/-", C.COLOR_GRAY);

                setCellValue(7, "B1/KL", C.COLOR_GRAY);
                setCellValue(8, "B2/KL", C.COLOR_GRAY);
                setCellValue(9, "B3/KL", C.COLOR_GRAY);

                setCellValue(10, "H/L", C.COLOR_GRAY);

                setCellValue(11, "TổngKL", C.COLOR_GRAY);

                /*
                 * c = getCellAt(11);
                 * if (c != null)
                 * {
                 *  c.text2 = "DưB";
                 *  c.textColor2 = C.COLOR_GRAY;
                 * }
                 */

                if (sortType == ShareSortUtils.SORT_DUMUA_DUBAN)
                {
                    setCellValue(12, "▼ Dư\nM/B", C.COLOR_ORANGE);
                }
                else
                {
                    setCellValue(12, "▼ " + ShareSortUtils.sortTypeToString(sortType), C.COLOR_ORANGE);
                }
            }

            if (getID() == 0)
            {
                return;
            }

            String code = (String)getUserData();

            if (code == null)
            {
                return;
            }
            stPriceboardState item = ctx.mPriceboard.getPriceboard(code);
            stPriceboardState ps   = item;

            if (item == null)
            {
                return;
            }

            Share share = ctx.mShareManager.getShare(ps.id);

            if (share == null)
            {
                return;
            }

            String s;

            //  code
            uint color;

            setCellValue(0, code, C.COLOR_WHITE);
            addCellValue1(0, String.Format("{0:F2}", item.getRef()), C.COLOR_YELLOW);
            float _ref = item.getRef();

            int   j = 0;
            float v;

            int[]   rbc = { 2, 3, 4 };  //	remain buy col
            float[] rb  = { ps.getRemainBuyPrice2(), ps.getRemainBuyPrice1(), ps.getRemainBuyPrice0() };
            int[]   rbv = { ps.getRemainBuyVolume2(), ps.getRemainBuyVolume1(), ps.getRemainBuyVolume0() };

            int[]   rsc = { 7, 8, 9 };
            float[] rs  = { ps.getRemainSellPrice0(), ps.getRemainSellPrice1(), ps.getRemainSellPrice2() };
            int[]   rsv = { ps.getRemainSellVolume0(), ps.getRemainSellVolume1(), ps.getRemainSellVolume2() };
            //	mua1, mua2, mua3

            for (j = 0; j < 3; j++)
            {
                //	price
                color = ctx.valToColorF(rb[j], item.getCe(), item.getRef(), item.getFloor());
                setCellValue(rbc[j], String.Format("{0:F2}", rb[j]), color);
                //	vol
                s = volumeToString(rbv[j]);

                addCellValue1(rbc[j], s);
            }

            //  Khop
            float currentPrice = item.getCurrentPrice();
            int   currentVol   = item.getCurrentVolume();

            color = ctx.valToColorF(currentPrice, item.getCe(), item.getRef(), item.getFloor());
            setCellValue(5, String.Format("{0:F2}", currentPrice), color);

            s = volumeToString(currentVol);

            addCellValue1(5, s);

            //  change +/-
            v = currentPrice - item.getRef();
            s = String.Format("{0:F2}", (float)v);
            if (currentPrice == 0)
            {
                s = "-";
            }
            setCellValue(6, s, color);

            //	sell1, sell2, sell3
            for (j = 0; j < 3; j++)
            {
                //	price
                color = ctx.valToColorF(rs[j], item.getCe(), item.getRef(), item.getFloor());
                setCellValue(rsc[j], String.Format("{0:F2}", rs[j]), color);
                //	vol
                s = volumeToString(rsv[j]);

                addCellValue1(rsc[j], s);
            }

            //  cao - thap
            setCellValue(10, String.Format("{0:F2}", item.getMax()), ctx.valToColorF(item.getMax(), item.getCe(), item.getRef(), item.getFloor()));
            addCellValue1(10, String.Format("{0:F2}", item.getMin()), ctx.valToColorF(item.getMin(), item.getCe(), item.getRef(), item.getFloor()));

            //  total volume
//            s = volumeToString(item.getTotalVolume());
//            setCellValue(11, s, C.COLOR_WHITE);
            mVolumeColumn = 11;

            //  cung - cau
            if (sortType == ShareSortUtils.SORT_DUMUA_DUBAN)
            {
                int    buy   = item.getRemainBuyVolume0() + item.getRemainBuyVolume1() + item.getRemainBuyVolume2();
                int    sell  = item.getRemainSellVolume0() + item.getRemainSellVolume1() + item.getRemainSellVolume2();
                String sbuy  = volumeToString(buy);
                String ssell = volumeToString(sell);
                setCellValue(12, sbuy, C.COLOR_ORANGE);
                c = getCellAt(12);
                if (c != null)
                {
                    c.text2      = ssell;
                    c.textColor2 = C.COLOR_ORANGE;
                }
            }
            else
            {
                setCellValue(12, share.mCompareText, C.COLOR_ORANGE);
                c = getCellAt(12);
                if (c != null)
                {
                    c.text2      = null;
                    c.textColor2 = C.COLOR_ORANGE;
                }
            }
        }
Beispiel #4
0
        void update()
        {
            if (mTrade == null)
            {
                return;
            }
            if (mTradeIndex >= 0 && mTradeIndex < mTrade.getTransactionCount())
            {
                int   time  = mTrade.getTime(mTradeIndex);
                float price = mTrade.getPrice(mTradeIndex);
                int   vol   = mTrade.getTradeVolume(mTradeIndex);

                StringBuilder sb = Utils.sb;
                sb.Length = 0;
                //  time
                sb.AppendFormat("{0:D2}:{1:D2}:{2:D2}", ((time >> 16) & 0xff), ((time >> 8) & 0xff), (time & 0xff));
                setTextForCell(P_TIME, sb.ToString(), C.COLOR_WHITE);

                //  price
                stPriceboardState ps = mContext.mPriceboard.getPriceboard(mTrade.mShareID);
                if (ps != null)
                {
                    uint color = mContext.valToColorF(price, ps.getCe(), ps.getRef(), ps.getFloor());
                    sb.Length = 0;
                    sb.AppendFormat("{0:F2}", (float)price);
                    setTextForCell(P_PRICE, sb.ToString(), color);
                    //  volume
                    string sv = Utils.formatNumber(vol);
                    setTextForCell(P_VOLUME, sv, color);
                }
            }
        }
Beispiel #5
0
        //  code | ref | KL1 | G1 |= GiaKhop | KLKhop | TongKL =| KL1 | G1 |=== TB | Cao | Thap
        override protected void updateQuote()
        {
            if (getID() < 0)
            {
                return;
            }
            Context ctx = Context.getInstance();

            if (getID() == 0)
            {
                //  code
                setCellValue(0, "Mã/TC", C.COLOR_GRAY);

                setCellValue(2, "Giá", C.COLOR_GRAY);

                setCellValue(3, "+/-", C.COLOR_GRAY);

                setCellValue(4, "GiáMua/KL", C.COLOR_GRAY);

                setCellValue(5, "Vốn (tr)", C.COLOR_WHITE);

                setCellValue(6, "Lãi  % / vnd", C.COLOR_GRAY);

                setCellValue(7, "Ngày mua", C.COLOR_WHITE);
            }

            if (getID() == 0)
            {
                return;
            }

            stGainloss gainloss = (stGainloss)getUserData();

            if (gainloss == null)
            {
                return;
            }
            String            code = gainloss.code;
            stPriceboardState item = ctx.mPriceboard.getPriceboard(code);

            if (item == null)
            {
                return;
            }

            String s;

            //  code
            uint color;

            setCellValue(0, item.getCode(), C.COLOR_WHITE);
            addCellValue1(0, String.Format("{0:F2}", item.getRef()), C.COLOR_YELLOW);
            float reference = item.getRef();
            float price     = item.getCurrentPrice();

            if (price == 0)
            {
                price = reference;
            }

            int j = 0;

            //  price
            color = ctx.valToColorF(item.getCurrentPrice(), item.getCe(), item.getRef(), item.getFloor());
            setCellValue(2, String.Format("{0:F2}", item.getCurrentPrice()), color);
            //	vol
            //s = volumeToString(item.getCurrentVolume());
            //addCellValue1(1, s);

            //  change +/-
            float v = price - reference;

            s = String.Format("{0:F2}", (float)v);
            if (item.getCurrentPrice() == 0)
            {
                s = "-";
            }
            setCellValue(3, s, color);

            //  GiaMua
            s = String.Format("{0:F2}", gainloss.price);
            setCellValue(4, s, C.COLOR_WHITE);
            //  KLMua
            s = String.Format("{0:D}", gainloss.volume);
            addCellValue1(4, s);

            //  Tien von
            double capital = gainloss.price * gainloss.volume / 1000.0f;

            s = String.Format("{0:F} tr", capital);
            setCellValue(5, s, C.COLOR_WHITE);

            //========================
            //  %GainLoss
            stPriceboardState ps           = item;
            float             currentPrice = ps.getCurrentPrice();

            if (currentPrice == 0)
            {
                currentPrice = ps.getRef();
            }

            price = gainloss.price;
            float percent = 0;

            if (price > 0)
            {
                percent = (float)(100 * (currentPrice - price)) / price;
            }
            if (percent > 0)
            {
                s = String.Format("+{0:F2} %", percent);
            }
            else
            {
                s = String.Format("{0:F2} %", percent);
            }
            if (percent > 0)
            {
                color = C.COLOR_GREEN;
            }
            else if (percent == 0)
            {
                color = C.COLOR_YELLOW;
            }
            else
            {
                color = C.COLOR_RED;
            }

            setCellValue(6, s, color);
            //  gainloss money
            double oValue  = price * gainloss.volume;
            double cValue  = currentPrice * gainloss.volume;
            double benefit = (cValue - oValue) / 1000;

            if (benefit > 0)
            {
                s = String.Format("+{0:F2} tr", benefit);
            }
            else
            {
                s = String.Format("{0:F2} tr", benefit);
            }

            addCellValue1(6, s);
            //  date
            //s = Utils.dateIntToString4(gainloss.date);
            //setCellValue(7, s, C.COLOR_WHITE);
        }
Beispiel #6
0
        void drawCandle(xGraphics g, int x, int y0, int w, int h)
        {
            Share share = mShare;

            int  y = 0;
            Font f = mContext.getFontSmall();

            uint color;

            stPriceboardState ps = mContext.mPriceboard.getPriceboard(share.getID());

            if (ps == null)
            {
                return;
            }

            TradeHistory trade = mContext.getTradeHistory(share.getID());
            float        price = ps.getCurrentPrice();
            float        open  = price;//ps.getRef(); //  should be open - testing

            if (trade != null && trade.getTransactionCount() > 0)
            {
                open = trade.getPrice(0);
            }
            else
            {
                open = mContext.mPriceboard.getOpen(mShare.mID);
            }

            if (open != 0 && mContext.mPriceboard.getOpen(mShare.mID) == 0 && !share.isIndex())
            {
                mContext.mPriceboard.setOpen(mShare.mID, (int)open);
            }

            float hi       = ps.getMax();
            float lo       = ps.getMin();
            float priceLen = hi - lo;

            float reference = ps.getRef();
            float min       = ps.getFloor() - (float)reference / 30;
            float max       = ps.getCe() + (float)reference / 30;

            if (share.isIndex())
            {
                price     = trade.mClose / 10.0f;
                open      = trade.mOpen / 10.0f;
                reference = trade.mPriceRef / 10.0f;
                hi        = trade.mHighest / 10.0f;
                lo        = trade.mLowest / 10.0f;
                min       = reference - reference / 40;
                max       = reference + reference / 40;

                if (min > lo)
                {
                    min = lo;
                }
                if (max < hi)
                {
                    max = hi;
                }

                priceLen = (int)(hi - lo);
            }

            if (price == 0)
            {
                return;
            }

            //if (min > ps.getMin() && ps.getMin() > 0) min = ps.getMin();
            //if (max < ps.getMax()) max = ps.getMax();

            float totalPrice = (max - min);  //(10%);

            if (totalPrice < priceLen)
            {
                totalPrice = priceLen;
            }

            if (totalPrice == 0)
            {
                return;
            }

            float ry = (float)(h) / totalPrice;

            int           totalH = (int)(ry * totalPrice);
            int           bodyW  = w / 3;
            StringBuilder sb     = Utils.getSB();

            //================frame=============================
            //  line ref
            g.setColor(0x30ffff00);
            y = (int)(y0 + totalH - (reference - min) * ry);
            g.drawLineDotHorizontal(1, y, getW() - 2, y);
            g.setColor(0xa0ffff00);

/*
 *          if (mDrawRefLabel)
 *          {
 *              sb.AppendFormat("{0:F1}", (float)reference / 10);
 *              g.drawString(f, sb.ToString(), 1, y - f.Height / 2, 0);
 *          }
 */
            //  CE line
            if (!share.isIndex())
            {
                g.setColor(0x30ff00ff);
                y = (int)(y0 + totalH - (ps.getCe() - min) * ry);
                g.drawLineDotHorizontal(1, y, getW() - 2, y);
                g.setColor(0xa0ff00ff);
                sb.Length = 0;
                sb.AppendFormat("{0:F1}", (float)(ps.getCe() / 10));

                if (mDrawRefLabel)
                {
                    g.drawString(f, sb.ToString(), 1, y, 0);
                }

                //  FLOOR line
                g.setColor(0x3000FFFF);
                y = (int)(y0 + totalH - (ps.getFloor() - min) * ry);
                g.drawLineDotHorizontal(1, y, getW() - 2, y);
                g.setColor(0xa000FFFF);
                sb.Length = 0;
                sb.AppendFormat("{0:F1}", (float)(ps.getFloor() / 10));
                if (mDrawRefLabel)
                {
                    g.drawString(f, sb.ToString(), 1, y - f.Height, 0);
                }
            }
            //===================================================
            color = price < open? C.COLOR_RED:C.COLOR_GREEN;
            if (price == open)
            {
                color = C.COLOR_WHITE;
            }
            if (price == 0)
            {
                return;
            }
            //  draw shadow
            g.setColor(C.COLOR_WHITE);
            x = getW() / 2;

            if (share.isIndex() && hi > 0 && lo > 0)
            {
                int minY = (int)(y0 + totalH - (lo - min) * ry);
                int maxY = (int)(y0 + totalH - (hi - min) * ry);

                g.drawLine(x, maxY, x, minY);
            }
            int centerX = x + bodyW / 2;
            //  candle's body
            int oY = (int)(y0 + totalH - (open - min) * ry);
            int cY = (int)(y0 + totalH - (price - min) * ry);

            y = oY < cY?oY:cY;
            int bodyH = Utils.ABS_INT(cY - oY);

            if (bodyH < 2)
            {
                bodyH = 2;
            }
            g.setColor(color);
            g.fillRect(x - bodyW / 2, y, bodyW, bodyH);

            /*
             * if (lo > 0 && lo != open && lo != price)
             * {
             *  y = (int)(y0 + totalH - (lo - min)*ry);
             *  g.setColor(C.COLOR_WHITE);
             *  sb.Length = 0;
             *  sb.AppendFormat("{0:F1}", (float)lo/10);
             *  g.drawString(f, sb.ToString(), centerX - 44, y + 1, 0);
             * }
             * if (hi > 0 && hi != open && hi != price)
             * {
             *  y = (int)(y0 + totalH - (hi - min)*ry);
             *  g.setColor(C.COLOR_WHITE);
             *  sb.Length = 0;
             *  sb.AppendFormat("{0:F1}", (float)hi/10);
             *  g.drawString(f, sb.ToString(), centerX - 44, y - f.Height, 0);
             * }
             * //  2 lines
             * g.setColor(C.COLOR_WHITE);
             * sb.Length = 0;
             * sb.AppendFormat("{0:F1}", (float)open/10);
             *
             * //  open
             * if (oY < cY)
             *  y = oY - f.Height;
             * else
             *  y = oY + 1;
             * if (y < 0) y = 0;
             * if (y + f.Height > getH())
             *  y = getH() - f.Height;
             * g.drawString(f, sb.ToString(), x + bodyW / 2, y, 0);
             * //  price
             * sb.Length = 0;
             * sb.AppendFormat("{0:F1}", (float)price/10);
             * if (cY < oY)
             *  y = cY - f.Height;
             * else
             *  y = cY + 1;
             * if (y < 0) y = 0;
             * if (y + f.Height > getH())
             *  y = getH() - f.Height;
             * g.drawString(f, sb.ToString(), x + bodyW / 2, y, 0);
             */
        }
Beispiel #7
0
        //  code | ref | KL1 | G1 |= GiaKhop | KLKhop | TongKL =| KL1 | G1 |=== TB | Cao | Thap
        override protected void updateQuote()
        {
            if (getID() < 0)
            {
                return;
            }
            Context ctx = Context.getInstance();

            if (getID() == 0)
            {
                //  code
                setCellValue(0, "Mã/Giá", C.COLOR_GRAY);

                setCellValue(2, "+/-", C.COLOR_GRAY);
                addCellValue1(2, "%", C.COLOR_GRAY);

                setCellValue(3, "Khối lượng", C.COLOR_GRAY);
                setCellValue(4, ShareSortUtils.sortTypeToString(sortType), C.COLOR_ORANGE);
            }

            if (getID() == 0)
            {
                return;
            }

            String code = (String)this.getUserData();

            if (code == null)
            {
                return;
            }
            stPriceboardState item = ctx.mPriceboard.getPriceboard(code);

            if (item == null)
            {
                return;
            }

            String s;

            //  code
            uint color;

            setCellValue(0, item.getCode(), C.COLOR_WHITE);

            float reference = item.getRef();
            float price     = item.getCurrentPrice();

            if (price == 0)
            {
                price = reference;
            }
            color = ctx.valToColorF(item.getCurrentPrice(), item.getCe(), item.getRef(), item.getFloor());
            addCellValue1(0, String.Format("{0:F2}", item.getCurrentPrice()), color);

            int j = 0;
            //  change +/-
            float v = price - reference;

            s = String.Format("{0:F2}", (float)v);
            if (item.getCurrentPrice() == 0)
            {
                s = "-";
            }
            setCellValue(2, s, color);

            //  change percent
            if (reference > 0)
            {
                s = String.Format("{0:F1}", (float)((v * 100) / reference));
                addCellValue1(2, s, color);
            }

            //  volume
            //s = volumeToString(item.getTotalVolume());
            //setCellValue(3, s, C.COLOR_WHITE);

            //Share share = (Share)mFilteredShares.elementAt(row);
            mVolumeColumn = 3;

            //  short column
            Share share = Context.getInstance().mShareManager.getShare(getCode());

            if (share != null)
            {
                setCellValue(4, share.mCompareText, C.COLOR_ORANGE);
                stCell c = getCellAt(4);
                if (c != null)
                {
                    c.text2      = null;
                    c.textColor2 = C.COLOR_ORANGE;
                }
            }
        }
Beispiel #8
0
        public void refreshChart(int martketID)
        {
            rx = (float)(getW() - 10) / mMapW;
            ry = (float)(getH() - 15) / mMapH;
            //  block data
            int total = 1000;
            int i     = 0;

            for (i = 0; i < mUsedBlocks.size(); i++)
            {
                stBubbleBlock b = (stBubbleBlock)mUsedBlocks.elementAt(i);
                b.x = 0;
                b.y = 0;
                mFreeBlocks.addElement(b);
            }
            //  reset
            mUsedBlocks.removeAllElements();
            for (i = 0; i < mMapH; i++)
            {
                for (int j = 0; j < mMapW; j++)
                {
                    mMap[map(i, j)] = 0;
                }
            }

            //--------------------------------------
            //xVector v = mContext.mShareManager.getCompanyInfos();
            double totalEquity   = 0.0f;
            double totalIndexInc = 0;
            double totalIndexDec = 0;


            stPriceboardStateIndex pi = mContext.mPriceboard.getPriceboardIndexOfMarket(martketID);

            int shareCount = mContext.mShareManager.getTotalShareIDCount();

            //  calc totalEquity
            int[] market = { 0 };
            for (i = 0; i < shareCount; i++)
            {
                int           shareID = mContext.mShareManager.getShareIDAt(i, market);
                stCompanyInfo inf     = mContext.mShareManager.getCompanyInfo(shareID);
                if (inf != null && inf.floor == martketID)
                {
                    stPriceboardState priceboard = mContext.mPriceboard.getPriceboard(inf.shareID);
                    if (priceboard != null)
                    {
                        double ff = priceboard.getCurrentPrice();  //  avoiding of overstack
                        if (mChartType == BUBBLE_TRADE_MONEY)
                        {
                            totalEquity += ff * priceboard.getTotalVolume();
                        }
                        else if (mChartType == BUBBLE_VOLUME_WEIGHT ||
                                 mChartType == BUBBLE_INDEX_WEIGHT_RATIO_INC ||
                                 mChartType == BUBBLE_INDEX_WEIGHT_RATIO_DEC)
                        {
                            totalEquity += ((double)inf.volume * ff);
                        }
                    }
                }
            }
            //  extra
            for (i = 0; i < shareCount; i++)
            {
                int           shareID = mContext.mShareManager.getShareIDAt(i, market);
                stCompanyInfo inf     = mContext.mShareManager.getCompanyInfo(shareID);
                if (inf != null && inf.floor == martketID)
                {
                    stPriceboardState priceboard = mContext.mPriceboard.getPriceboard(inf.shareID);
                    if (priceboard != null)
                    {
                        double ff = priceboard.getCurrentPrice();  //  avoiding of overstack
                        if (mChartType == BUBBLE_TRADE_MONEY)
                        {
                        }
                        else if (mChartType == BUBBLE_VOLUME_WEIGHT ||
                                 mChartType == BUBBLE_INDEX_WEIGHT_RATIO_INC ||
                                 mChartType == BUBBLE_INDEX_WEIGHT_RATIO_DEC)
                        {
                            if (mChartType == BUBBLE_INDEX_WEIGHT_RATIO_INC && priceboard.change > 0)
                            {
                                double indexPointOfShare = pi.current_point * ((inf.volume * ff) / totalEquity);
                                double indexChanged      = priceboard.change * indexPointOfShare / priceboard.current_price_1;
                                totalIndexInc += 1.2f * indexChanged;
                            }
                            else if (mChartType == BUBBLE_INDEX_WEIGHT_RATIO_DEC && priceboard.change < 0)
                            {
                                double indexPointOfShare = pi.current_point * ((inf.volume * ff) / totalEquity);
                                double indexChanged      = priceboard.change * indexPointOfShare / priceboard.current_price_1;
                                totalIndexDec += -1.2f * indexChanged;
                            }
                        }
                    }
                }
            }
            if (totalEquity == 0.0)
            {
                return;
            }

            double squareOfCell = 1.0 / (mMapW * mMapH);
            double tmp          = 0;

            //  now calc blocks
            for (i = 0; i < shareCount; i++)
            {
                int           shareID = mContext.mShareManager.getShareIDAt(i, market);
                stCompanyInfo inf     = mContext.mShareManager.getCompanyInfo(shareID);
                if (inf != null && inf.floor == martketID)
                {
                    stPriceboardState priceboard = mContext.mPriceboard.getPriceboard(inf.shareID);//martketID, share.mShareID);
                    if (priceboard != null)
                    {
                        String code = mContext.mShareManager.getShareCode(inf.shareID);
                        if (code != null && (code.CompareTo("MSN") == 0 || code.CompareTo("MBB") == 0))
                        {
                            Utils.trace("aaa");
                        }
                        double equity    = 0.0f;
                        double ff        = priceboard.getCurrentPrice(); //  avoiding of overstack
                        float  threshold = 0.003f;
                        if (mChartType == BUBBLE_TRADE_MONEY)
                        {
                            equity = ff * priceboard.getTotalVolume();
                        }
                        else if (mChartType == BUBBLE_VOLUME_WEIGHT)
                        {
                            equity = ((double)inf.volume * ff);
                        }
                        else if (mChartType == BUBBLE_INDEX_WEIGHT_RATIO_INC)
                        {
                            double indexPointOfShare = pi.current_point * ((inf.volume * ff) / totalEquity);
                            double indexChanged      = priceboard.change * indexPointOfShare / priceboard.current_price_1;
                            equity    = indexChanged;
                            threshold = 0.00001f;
                        }
                        else if (mChartType == BUBBLE_INDEX_WEIGHT_RATIO_DEC)
                        {
                            double indexPointOfShare = pi.current_point * ((inf.volume * ff) / totalEquity);
                            double indexChanged      = priceboard.change * indexPointOfShare / priceboard.current_price_1;
                            equity    = -indexChanged;
                            threshold = 0.00001f;
                        }
                        float percent = (float)(equity / totalEquity);   //  <= 1
                        if (mChartType == BUBBLE_INDEX_WEIGHT_RATIO_INC ||
                            mChartType == BUBBLE_INDEX_WEIGHT_RATIO_DEC)
                        {
                            percent = (float)(equity / (double)pi.current_point);
                            //percent = (float)(equity/totalEquityOfUsedBlock);
                        }
                        if (percent >= threshold && mFreeBlocks.size() > 0)
                        {
                            //  big enough to care
                            float percentR = percent;
                            if (mChartType == BUBBLE_INDEX_WEIGHT_RATIO_INC)
                            {
                                percentR = (float)(equity / totalIndexInc);
                            }
                            else if (mChartType == BUBBLE_INDEX_WEIGHT_RATIO_DEC)
                            {
                                percentR = (float)(equity / totalIndexDec);
                            }

                            float square = percentR * (mMapH * mMapW);

                            float cells = square;
                            if (cells < 1)
                            {
                                cells = 1;
                            }

                            stBubbleBlock block = (stBubbleBlock)mFreeBlocks.pop();
                            block.code = mContext.mShareManager.getShareCode(inf.shareID);;
                            //  w & h
                            block.w = (short)Math.Sqrt(cells);
                            block.h = block.w;
                            if (block.h * block.w < cells)
                            {
                                block.w++;
                            }

                            if (block.h >= 50)
                            {
                                int k = 0;
                            }

                            //  color
                            uint  color     = C.COLOR_YELLOW;
                            float price     = priceboard.getCurrentPrice();
                            float reference = priceboard.getRef();
                            if (price == reference)
                            {
                                color = C.COLOR_YELLOW;
                            }
                            else if (price == priceboard.getCe())
                            {
                                color = C.COLOR_MAGENTA;
                            }
                            else if (price == priceboard.getFloor())
                            {
                                color = C.COLOR_CYAN;
                            }
                            else if (price < reference)
                            {
                                int r = (int)((reference - price) * 100 / reference);    //  percent
                                if (r < 8)
                                {
                                    r = (0xff - 150) + r * 30;
                                }
                                else
                                {
                                    r = 0xff;
                                }
                                if (r > 0xff)
                                {
                                    r = 0xff;
                                }
                                //---------------
                                r = 0xff;

                                color = (uint)((0xff << 24) | (r << 16));
                            }
                            else if (price > reference)
                            {
                                int g = (int)((price - reference) * 100 / reference);    //  percent
                                if (g < 8)
                                {
                                    g = (0xff - 150) + g * 30;
                                }
                                else
                                {
                                    g = 0xff;
                                }
                                if (g > 0xff)
                                {
                                    g = 0xff;
                                }
                                //----------------
                                g     = 0xff;
                                color = (uint)((0xff << 24) | (g << 8));
                            }
                            block.color = color;
                            //  point
                            block.point = (short)(percent * 1000);//(priceboard.current_price_1 - priceboard.ref)*1000/priceboard.ref;
                            //  x & y
                            //setBlockPosition(block);

                            //  extra inf
                            StringBuilder sb = Utils.sb;
                            sb.Length = 0;
                            if (mChartType == BUBBLE_TRADE_MONEY)
                            {
                                sb.AppendFormat("{0:F1}tỉ", (equity / 1000000));   //  money unit = 100 vnd
                            }
                            else if (mChartType == BUBBLE_VOLUME_WEIGHT)
                            {
                                sb.AppendFormat("{0:F1}%", (percent * 100));
                            }
                            else if (mChartType == BUBBLE_INDEX_WEIGHT_RATIO_INC)
                            {
                                double r = (inf.volume * price) / totalEquity;
                                //  totalE = pi.point
                                //  vonhoa = ?


                                //  index-point of code: (r*pi.point);
                                //  price <> (r*pi.point)
                                //  changed <> ?
                                double indexChanged = (priceboard.change * r * pi.current_point) / priceboard.current_price_1;
                                tmp += indexChanged;
                                sb.AppendFormat("{0:F4}", (indexChanged));
                            }
                            else if (mChartType == BUBBLE_INDEX_WEIGHT_RATIO_DEC)
                            {
                                double r            = (inf.volume * price) / totalEquity;
                                double indexChanged = (priceboard.change * r * pi.current_point) / priceboard.current_price_1;

                                sb.AppendFormat("{0:F4}", (indexChanged));
                            }
                            block.inf = sb.ToString();
                            if (priceboard.getCode() == "ACB")
                            {
                                int k = 0;
                            }
                            //  changed
                            sb.Length = 0;
                            if (reference != 0)
                            {
                                float changed = price - reference;
                                if (changed > 0)
                                {
                                    sb.AppendFormat("+{0:F2}%", (float)((changed * 100) / reference));
                                }
                                else
                                {
                                    sb.AppendFormat("{0:F2}%", (float)((changed * 100) / reference));
                                }
                            }
                            block.changed = sb.ToString();

                            mUsedBlocks.addElement(block);
                        }
                    }
                }
            }// end of for

            sortBlocks();
        }
Beispiel #9
0
        override public void render(xGraphics g)
        {
            Utils.trace("=====render today candle");

            if (mIsSelected)
            {
                g.setColor(C.COLOR_BLUE);
                g.fillRect(0, 0, getW(), getH());

                g.setColor(C.COLOR_BLACK);
                g.fillRect(3, 3, getW() - 6, getH() - 6);
            }
            else
            {
                g.setColor(C.COLOR_BLACK);
                g.fillRect(0, 0, getW(), getH());
            }

            g.setColor(C.COLOR_GRAY_LIGHT);
            g.drawRect(0, 0, getW() - 1, getH() - 1);

            Share share = mShare;

            if (share == null)
            {
                return;
            }

            int x, y;

            x = 0;
            y = 0;
            int h = getH();

            if (mHasTitle)
            {
                Font ft = mContext.getFontTextB();
                //  title background
                if (mIsSelected)
                {
                    g.setColor(C.COLOR_BLUE);
                }
                else
                {
                    g.setColor(0xff204040);
                }
                //g.setColor(0xff004070);
                g.fillRect(1, 1, getW() - 2, 1 * ft.Height);

                //  code
                g.setColor(C.COLOR_WHITE);
                g.drawString(ft, mShare.mCode, 1, 1);
                //  point
                stPriceboardState ps     = mContext.mPriceboard.getPriceboard(share.getID());
                float             price  = ps.getCurrentPrice();
                float             change = price - ps.getRef();
                StringBuilder     sb     = Utils.getSB();
                if (change >= 0)
                {
                    sb.AppendFormat("{0:F2} (+{1:F2})", (float)price, (float)change);
                }
                else
                {
                    sb.AppendFormat("{0:F2} ({1:F2})", (float)price, (float)change);
                }

                x += g.getStringWidth(ft, mShare.mCode) + 4;

                uint color = mContext.valToColorF(price, ps.getCe(), ps.getRef(), ps.getFloor());
                g.setColor(color);
                g.drawString(ft, sb.ToString(), x, 1);
                //=====vol
                g.setColor(C.COLOR_ORANGE);
                x  = 1;
                ft = mContext.getFontSmall();
                y  = getH() - ft.Height;

                sb.Length = 0;
                if (ps.getTotalVolume() > 100000)
                {
                    sb.AppendFormat("{0}K", (ps.getTotalVolume() / 1000));
                }
                else if (ps.getTotalVolume() > 1000)
                {
                    sb.AppendFormat("{0:F1}K", (float)(ps.getTotalVolume() / 1000));
                }
                else
                {
                    sb.AppendFormat("{0}", ps.getTotalVolume());
                }
                g.drawString(ft, sb.ToString(), x, y);
                //=========================
                x  = 0;
                h -= (int)ft.Height;
                y  = ft.Height;
            }
            //===========================================
            drawCandle(g, x, y, getW(), h);
        }
Beispiel #10
0
        void drawCandle(xGraphics g, int x, int y0, int w, int h)
        {
            Share share = mShare;

            int  y = 0;
            Font f = mContext.getFontSmall();

            uint color;

            stPriceboardState ps = mContext.mPriceboard.getPriceboard(share.getID());

            if (ps == null)
            {
                return;
            }

            TradeHistory trade = mContext.getTradeHistory(share.getID());
            float        price = ps.getCurrentPrice();
            float        open  = mContext.mPriceboard.getOpen(ps.getID());

            if (trade != null && trade.getTransactionCount() > 0)
            {
                open = trade.getPrice(0);
            }
            else
            {
                open = mContext.mPriceboard.getOpen(mShare.mID);
            }

            if (open != 0 && mContext.mPriceboard.getOpen(mShare.mID) == 0 && !share.isIndex())
            {
                mContext.mPriceboard.setOpen(mShare.mID, (int)open);
            }

            float hi = ps.getMax();
            float lo = ps.getMin();

            //  check hi/lo valid
            if ((hi == 0 || lo == 0))
            {
                float[] hl = new float[2];
                if (trade.getHiLo(hl))
                {
                    if (hi == 0)
                    {
                        hi = hl[0];
                    }
                    if (lo == 0)
                    {
                        lo = hl[1];
                    }
                }
            }

            if (hi == 0)
            {
                hi = open > price ? open : price;
            }
            if (lo == 0)
            {
                lo = open < price ? open : price;
            }
            if (lo == 0)
            {
                lo = hi;
            }
            //---------------------------------------------
            float priceLen = hi - lo;
            float reference = ps.getRef();
            float min, max;

            if (share.isIndex())
            {
                stPriceboardStateIndex pi = mContext.mPriceboard.getPriceboardIndexOfMarket(mShare.getMarketID());
                price = pi.current_point;

                min = lo - price / 40;
                max = hi + price / 40;
            }
            else
            {
                min = ps.getFloor() - reference / 30;
                max = ps.getCe() + reference / 30;
            }

            if (price == 0)
            {
                return;
            }

            //if (min > ps.getMin() && ps.getMin() > 0) min = ps.getMin();
            //if (max < ps.getMax()) max = ps.getMax();

            float totalPrice = (max - min);  //(10%);

            if (totalPrice < priceLen)
            {
                totalPrice = priceLen;
            }

            if (totalPrice == 0)
            {
                return;
            }

            float ry = (float)(h) / totalPrice;

            int           totalH = (int)(ry * totalPrice);
            int           bodyW  = w / 3;
            StringBuilder sb     = Utils.getSB();

            //================frame=============================
            //  line ref
            g.setColor(0x30ffff00);
            y = (int)(y0 + totalH - (reference - min) * ry);
            g.drawLineDotHorizontal(1, y, getW() - 2, y);
            g.setColor(0xa0ffff00);
            if (mDrawRefLabel)
            {
                sb.AppendFormat("{0:F2}", reference);
                g.drawString(f, sb.ToString(), 1, y - f.Height / 2, 0);
            }
            //  CE line
            if (!share.isIndex())
            {
                g.setColor(0x30ff00ff);
                y = (int)(y0 + totalH - (ps.getCe() - min) * ry);
                g.drawLineDotHorizontal(1, y, getW() - 2, y);
                g.setColor(0xa0ff00ff);
                sb.Length = 0;
                sb.AppendFormat("{0:F2}", ps.getCe());

                if (mDrawRefLabel)
                {
                    g.drawString(f, sb.ToString(), 1, y, 0);
                }

                //  FLOOR line
                g.setColor(0x3000FFFF);
                y = (int)(y0 + totalH - (ps.getFloor() - min) * ry);
                g.drawLineDotHorizontal(1, y, getW() - 2, y);
                g.setColor(0xa000FFFF);
                sb.Length = 0;
                sb.AppendFormat("{0:F2}", ps.getFloor());
                if (mDrawRefLabel)
                {
                    g.drawString(f, sb.ToString(), 1, y - f.Height, 0);
                }
            }
            //===================================================
            color = price < open? C.COLOR_RED:C.COLOR_GREEN;
            if (price == open)
            {
                color = C.COLOR_WHITE;
            }
            if (price == 0)
            {
                return;
            }
            //  draw shadow
            g.setColor(C.COLOR_WHITE);
            x = getW() / 2;

            if (hi > 0 && lo > 0)
            {
                int minY = (int)(y0 + totalH - (lo - min) * ry);
                int maxY = (int)(y0 + totalH - (hi - min) * ry);

                g.drawLine(x, maxY, x, minY);
            }
            int centerX = x;
            //  candle's body
            int oY = (int)(y0 + totalH - (open - min) * ry);
            int cY = (int)(y0 + totalH - (price - min) * ry);

            y = oY < cY?oY:cY;
            int bodyH = Utils.ABS_INT(cY - oY);

            if (bodyH < 2)
            {
                bodyH = 2;
            }
            g.setColor(color);
            g.fillRect(x - bodyW / 2, y, bodyW, bodyH);

            if (lo > 0 && lo != open && lo != price)
            {
                y = (int)(y0 + totalH - (lo - min) * ry);
                g.setColor(C.COLOR_YELLOW);
                sb.Length = 0;
                sb.AppendFormat("{0:F2}", lo);
                g.drawString(f, sb.ToString(), centerX - 10, y + 1, 0);
            }
            if (hi > 0 && hi != open && hi != price)
            {
                y = (int)(y0 + totalH - (hi - min) * ry);
                g.setColor(C.COLOR_YELLOW);
                sb.Length = 0;
                sb.AppendFormat("{0:F2}", hi);
                g.drawString(f, sb.ToString(), centerX - 10, y - f.Height, 0);
            }
            //  2 lines
            g.setColor(C.COLOR_WHITE);
            sb.Length = 0;
            sb.AppendFormat("{0:F2}", open);

            //  open
            if (oY < cY)
            {
                y = oY - f.Height;
            }
            else
            {
                y = oY + 1;
            }
            if (y < 0)
            {
                y = 0;
            }
            if (y + f.Height > getH())
            {
                y = getH() - f.Height;
            }
            g.drawString(f, sb.ToString(), x + bodyW / 2, y, 0);
            //  price
            sb.Length = 0;
            sb.AppendFormat("{0:F2}", price);
            if (cY < oY)
            {
                y = cY - f.Height;
            }
            else
            {
                y = cY + 1;
            }
            if (y < 0)
            {
                y = 0;
            }
            if (y + f.Height > getH())
            {
                y = getH() - f.Height;
            }
            g.drawString(f, sb.ToString(), x + bodyW / 2, y, 0);
        }
Beispiel #11
0
        override public void render(xGraphics g)
        {
            g.setColor(C.COLOR_BLACK);
            g.fillRect(0, 0, getW(), getH());

            g.setColor(C.COLOR_GRAY_LIGHT);
            g.drawRect(0, 0, getW(), getH());

            Share share = mShare;

            if (share == null)
            {
                return;
            }

            if (share.mCClose == null && share.getID() > 0)
            {
                share.loadShareFromCommonData(true);
                mContext.setCurrentShare(share.getID());
            }
            else
            {
                //return;
            }
            if (share.mCClose == null || share.getID() == 0)
            {
                return;
            }

            Font f = mContext.getFontText();
            int  x, y;

            x = 0;
            y = 0;

            stPriceboardState ps = mContext.mPriceboard.getPriceboard(share.getID());

            if (ps == null)
            {
                return;
            }

            StringBuilder sb     = Utils.getSB();

            f = mContext.getBigFont();
            //  current price
            float price = ps.getCurrentPrice();
            uint  color = mContext.valToColorF(price, ps.getCe(), ps.getRef(), ps.getFloor());

            if (price == 0)
            {
                price = ps.getRef();
            }

            //  current price
            sb.AppendFormat("{0:F2}", price);

            //l.setFont(f);
            x = 10;
            g.setColor(color);
            g.drawString(f, sb.ToString(), x, y);

            y += f.Height;
            //  change
            float change        = price - ps.getRef();
            float changePercent = 0;

            if (ps.getRef() > 0)
            {
                changePercent = (change * 100) / ps.getRef();
            }
            sb.Length = 0;
            sb.AppendFormat("{0:F1} ({1:F2}%)", (float)(change), changePercent);

            f = mContext.getFontText();

            g.setColor(color);
            g.drawString(f, sb.ToString(), x, y);
            //  --------------------vol
            x  = 4;
            y += f.Height + 10;
            int vol   = ps.getTotalVolume();
            int vol10 = share.getAveVolumeInDays(10);

            int   barMax = getW() - 20;
            float bar0   = 0;
            float bar10  = 0;

            if (vol < vol10)
            {
                bar0  = ((float)vol / vol10) * barMax;
                bar10 = barMax;
            }
            else if (vol != 0)
            {
                bar0  = barMax;
                bar10 = ((float)vol10 / vol) * barMax;
            }
            if (bar0 < 1)
            {
                bar0 = 1;
            }
            if (bar10 < 1)
            {
                bar10 = 1;
            }

            string tmp = Utils.formatNumber(vol);

            sb.Length = 0;
            sb.AppendFormat("Vol: {0}", tmp);

            g.setColor(C.COLOR_WHITE);
            g.drawString(f, sb.ToString(), x, y);

            y += (int)f.Height;

            g.setColor(C.COLOR_ORANGE);
            g.fillRect(x, y, (int)bar0, 10);
            y += 20;
            //  --------------------vol10
            tmp       = Utils.formatNumber(vol10);
            sb.Length = 0;
            sb.AppendFormat("TB 10phiên: {0}", tmp);

            g.setColor(C.COLOR_WHITE);
            g.drawString(f, sb.ToString(), x, y);

            y += f.Height;
            g.setColor(C.COLOR_ORANGE);
            g.fillRect(x, y, (int)bar10, 10);
        }
Beispiel #12
0
        //  code | _ref | KL1 | G1 |= GiaKhop | KLKhop | TongKL =| KL1 | G1 |=== TB | Cao | Thap
        override protected void updateQuote()
        {
            if (getID() < 0)
            {
                return;
            }

            Context ctx = Context.getInstance();
            stCell  c;

            if (getID() == 0)
            {
                //  code
                setCellValue(0, "Mã/TC", C.COLOR_GRAY);

                setCellValue(2, "Giá", C.COLOR_GRAY);
                setCellValue(3, "+/-", C.COLOR_GRAY);

                setCellValue(4, "H/L", C.COLOR_GRAY);


                setCellValue(5, "TổngKL", C.COLOR_GRAY);
            }

            if (getID() == 0)
            {
                return;
            }

            String code = (String)getUserData();

            if (code == null)
            {
                return;
            }
            stPriceboardState item = GlobalData.getPriceboardStateOfIndexWithSymbol(code);
            stPriceboardState ps   = item;

            if (item == null)
            {
                return;
            }

            String s;

            //  code
            uint color;

            setCellValue(0, code, C.COLOR_WHITE);
            addCellValue1(0, String.Format("{0:F2}", item.getRef()), C.COLOR_YELLOW);
            float _ref = item.getRef();

            int   j = 0;
            float v;

            //  Khop
            float currentPrice = item.getCurrentPrice();
            int   currentVol   = item.getCurrentVolume();

            color = ctx.valToColorF(currentPrice, item.getCe(), item.getRef(), item.getFloor());
            setCellValue(2, String.Format("{0:F2}", currentPrice), color);

            s = volumeToString(currentVol);

            addCellValue1(2, s);

            //  change +/-
            v = currentPrice - item.getRef();
            s = String.Format("{0:F2}", (float)v);
            if (currentPrice == 0)
            {
                s = "-";
            }
            setCellValue(3, s, color);

            //  cao - thap
            setCellValue(4, String.Format("{0:F2}", item.getMax()), ctx.valToColorF(item.getMax(), item.getCe(), item.getRef(), item.getFloor()));
            addCellValue1(4, String.Format("{0:F2}", item.getMin()), ctx.valToColorF(item.getMin(), item.getCe(), item.getRef(), item.getFloor()));


            //  total volume
            s = volumeToString(item.getTotalVolume());
            setCellValue(5, s, C.COLOR_WHITE);
        }
        private void refreshChart(int martketID)
        {
            //  block data
            int total = 1000;
            int i     = 0;

            if (getW() == 0 || getH() == 0)
            {
                return;
            }

            for (i = 0; i < mUsedBlocks.size(); i++)
            {
                stStatisticsBlock b = (stStatisticsBlock)mUsedBlocks.elementAt(i);
                mFreeBlocks.addElement(b);
            }
            //  reset
            mUsedBlocks.removeAllElements();
            //--------------------------------------
            int shareCount = mContext.mShareManager.getTotalShareIDCount();

            int[] market = { 0 };

            double totalEquity   = 0.0f;
            double totalIndexInc = 0;
            double totalIndexDec = 0;


            stPriceboardStateIndex pi = mContext.mPriceboard.getPriceboardIndexOfMarket(martketID);

            //  calc totalEquity
            for (i = 0; i < shareCount; i++)
            {
                int           shareID = mContext.mShareManager.getShareIDAt(i, market);
                stCompanyInfo inf     = mContext.mShareManager.getCompanyInfo(shareID);
                if (inf != null && inf.floor == martketID)
                {
                    stPriceboardState priceboard = mContext.mPriceboard.getPriceboard(inf.shareID);
                    if (priceboard != null)
                    {
                        double ff = priceboard.getCurrentPrice();  //  avoiding of overstack
                        if (mChartType == BUBBLE_TRADE_MONEY)
                        {
                            totalEquity += ff * priceboard.getTotalVolume();
                        }
                        else if (mChartType == BUBBLE_VOLUME_WEIGHT ||
                                 mChartType == BUBBLE_INDEX_WEIGHT_RATIO_INC ||
                                 mChartType == BUBBLE_INDEX_WEIGHT_RATIO_DEC)
                        {
                            totalEquity += ((double)inf.volume * ff);
                        }
                    }
                }
            }
            //  extra
            for (i = 0; i < shareCount; i++)
            {
                int           shareID = mContext.mShareManager.getShareIDAt(i, market);
                stCompanyInfo inf     = mContext.mShareManager.getCompanyInfo(shareID);
                if (inf != null && inf.floor == martketID)
                {
                    stPriceboardState priceboard = mContext.mPriceboard.getPriceboard(inf.shareID);
                    if (priceboard != null)
                    {
                        double ff = priceboard.getCurrentPrice();  //  avoiding of overstack
                        if (mChartType == BUBBLE_TRADE_MONEY)
                        {
                        }
                        else if (mChartType == BUBBLE_VOLUME_WEIGHT ||
                                 mChartType == BUBBLE_INDEX_WEIGHT_RATIO_INC ||
                                 mChartType == BUBBLE_INDEX_WEIGHT_RATIO_DEC)
                        {
                            if (mChartType == BUBBLE_INDEX_WEIGHT_RATIO_INC && priceboard.change > 0)
                            {
                                double indexPointOfShare = pi.current_point * ((inf.volume * ff) / totalEquity);
                                double indexChanged      = priceboard.change * indexPointOfShare / priceboard.current_price_1;
                                totalIndexInc += 1.2f * indexChanged;
                            }
                            else if (mChartType == BUBBLE_INDEX_WEIGHT_RATIO_DEC && priceboard.change < 0)
                            {
                                double indexPointOfShare = pi.current_point * ((inf.volume * ff) / totalEquity);
                                double indexChanged      = priceboard.change * indexPointOfShare / priceboard.current_price_1;
                                totalIndexDec += -1.2f * indexChanged;
                            }
                        }
                    }
                }
            }
            if (totalEquity == 0.0)
            {
                return;
            }

            double        tmp = 0;
            StringBuilder sb  = new StringBuilder();

            //  now calc blocks
            for (i = 0; i < shareCount; i++)
            {
                int           shareID = mContext.mShareManager.getShareIDAt(i, market);
                stCompanyInfo inf     = mContext.mShareManager.getCompanyInfo(shareID);
                if (inf != null && inf.floor == martketID)
                {
                    stPriceboardState priceboard = mContext.mPriceboard.getPriceboard(inf.shareID);//martketID, share.mShareID);
                    if (priceboard != null)
                    {
                        String code = mContext.mShareManager.getShareCode(inf.shareID);
                        //if (code != null && (code.CompareTo("MSN") == 0 || code.CompareTo("AAM") == 0))
                        //{
                        //Utils.trace("aaa");
                        //}
                        double modifierValue = 0.0f;
                        double ff            = priceboard.getCurrentPrice(); //  avoiding of overstack

                        //String log = String.Format("{0}, {1}, {2}, {3}", code, priceboard.current_price_1, inf.volume, totalEquity);
                        //Utils.trace(log);

                        float threshold = 0.003f;
                        if (mChartType == BUBBLE_TRADE_MONEY)
                        {
                            modifierValue = ff * priceboard.getTotalVolume();
                        }
                        else if (mChartType == BUBBLE_VOLUME_WEIGHT)
                        {
                            modifierValue = ((double)inf.volume * ff);
                        }
                        else if (mChartType == BUBBLE_INDEX_WEIGHT_RATIO_INC)
                        {
                            double indexPointOfShare = pi.current_point * ((inf.volume * ff) / totalEquity);
                            double indexChanged      = priceboard.change * indexPointOfShare / priceboard.current_price_1;
                            modifierValue = indexChanged;
                            threshold     = 0.000001f;
                        }
                        else if (mChartType == BUBBLE_INDEX_WEIGHT_RATIO_DEC)
                        {
                            double indexPointOfShare = pi.current_point * ((inf.volume * ff) / totalEquity);
                            double indexChanged      = priceboard.change * indexPointOfShare / priceboard.current_price_1;
                            modifierValue = -indexChanged;
                            threshold     = 0.000001f;
                        }
                        float percent = (float)(modifierValue / totalEquity);   //  <= 1
                        if (mChartType == BUBBLE_INDEX_WEIGHT_RATIO_INC ||
                            mChartType == BUBBLE_INDEX_WEIGHT_RATIO_DEC)
                        {
                            percent = (float)(modifierValue / (double)pi.current_point);
                        }

                        //String log = String.Format("{0}, {1}, {2}, {3}, {4}, {5}", code, priceboard.current_price_1, inf.volume
                        //, totalEquity, modifierValue, pi.current_point);
                        //Utils.trace(log);
                        if (percent >= threshold && mFreeBlocks.size() > 0)
                        {
                            //  big enough to care
                            float value = percent;
                            if (mChartType == BUBBLE_INDEX_WEIGHT_RATIO_INC)
                            {
                                percent *= 100;// (float)(equity / totalIndexInc);
                            }
                            else if (mChartType == BUBBLE_INDEX_WEIGHT_RATIO_DEC)
                            {
                                percent *= 100;// (float)(equity / totalIndexDec);
                            }

                            stStatisticsBlock block = (stStatisticsBlock)mFreeBlocks.pop();
                            block.code = mContext.mShareManager.getShareCode(inf.shareID);;
                            //  w & h
                            //block.w = (short)Math.Sqrt(cells);
                            //block.h = block.w;
                            //if (block.h * block.w < cells) block.w++;

                            //if (block.h >= 50)
                            //{
                            //int k = 0;
                            //}

                            //  color
                            uint  color     = C.COLOR_YELLOW;
                            float price     = priceboard.getCurrentPrice();
                            float reference = priceboard.getRef();
                            if (price == reference)
                            {
                                color = C.COLOR_YELLOW;
                            }
                            else if (price == priceboard.getCe())
                            {
                                color = C.COLOR_MAGENTA;
                            }
                            else if (price == priceboard.getFloor())
                            {
                                color = C.COLOR_CYAN;
                            }
                            else if (price < reference)
                            {
                                int r = (int)((reference - price) * 100 / reference);    //  percent
                                if (r < 8)
                                {
                                    r = (0xff - 150) + r * 30;
                                }
                                else
                                {
                                    r = 0xff;
                                }
                                if (r > 0xff)
                                {
                                    r = 0xff;
                                }
                                //---------------
                                r = 0xff;

                                color = (uint)((0xff << 24) | (r << 16));
                            }
                            else if (price > reference)
                            {
                                int g = (int)((price - reference) * 100 / reference);    //  percent
                                if (g < 8)
                                {
                                    g = (0xff - 150) + g * 30;
                                }
                                else
                                {
                                    g = 0xff;
                                }
                                if (g > 0xff)
                                {
                                    g = 0xff;
                                }
                                //----------------
                                g     = 0xff;
                                color = (uint)((0xff << 24) | (g << 8));
                            }
                            block.color = color;
                            //  point
                            block.point = (short)(percent * 1000);//(priceboard.current_price_1 - priceboard.ref)*1000/priceboard.ref;
                            //  x & y
                            //setBlockPosition(block);

                            //  extra inf

                            sb.Length = 0;
                            if (mChartType == BUBBLE_TRADE_MONEY)
                            {
                                sb.AppendFormat("{0:F1}tỉ", (modifierValue / 1000000));   //  money unit = 100 vnd
                            }
                            else if (mChartType == BUBBLE_VOLUME_WEIGHT)
                            {
                                sb.AppendFormat("{0:F1}%", (percent * 100));
                            }
                            else if (mChartType == BUBBLE_INDEX_WEIGHT_RATIO_INC)
                            {
                                double r = (inf.volume * price) / totalEquity;
                                //  totalE = pi.point
                                //  vonhoa = ?


                                //  index-point of code: (r*pi.point);
                                //  price <> (r*pi.point)
                                //  changed <> ?
                                double indexChanged = (priceboard.change * r * pi.current_point) / priceboard.current_price_1;
                                tmp += indexChanged;
                                sb.AppendFormat("{0:F4}", (indexChanged));
                            }
                            else if (mChartType == BUBBLE_INDEX_WEIGHT_RATIO_DEC)
                            {
                                double r            = (inf.volume * price) / totalEquity;
                                double indexChanged = (priceboard.change * r * pi.current_point) / priceboard.current_price_1;

                                sb.AppendFormat("{0:F4}", (indexChanged));
                            }
                            block.inf = sb.ToString();
                            if (priceboard.getCode() == "GAS")
                            {
                                int k = 0;
                            }
                            //  changed
                            sb.Length = 0;
                            if (reference != 0)
                            {
                                float changed = price - reference;
                                if (changed > 0)
                                {
                                    sb.AppendFormat("({0:F2}; +{1:F2}%)", price, (float)((changed * 100) / reference));
                                }
                                else
                                {
                                    sb.AppendFormat("({0:F2}; {1:F2}%)", price, (float)((changed * 100) / reference));
                                }
                            }
                            block.changed = sb.ToString();

                            //String log = String.Format("{0}, {1}, {2}, {3}, {4}, {5}, {6}", code, priceboard.current_price_1, inf.volume
                            //, totalEquity, modifierValue, pi.current_point, mUsedBlocks.size());
                            //Utils.trace(log);
                            mUsedBlocks.addElement(block);
                        }
                    }
                }
            }// end of for

            sortBlocks();
        }
Beispiel #14
0
        override public void render(xGraphics g)
        {
            g.setColor(C.COLOR_BLACK);
            g.clear();

            //  title

            xVector v = getMoneyVolumeArray();

            if (v == null || v.size() == 0)
            {
                return;
            }
            int biggest = 0;
            int i       = 0;

            for (i = 0; i < v.size(); i++)
            {
                MoneyVol mv = (MoneyVol)v.elementAt(i);
                if (mv.volume > biggest)
                {
                    biggest = mv.volume;
                }
            }

            float             rx;
            StringBuilder     sb = Utils.sb;
            uint              color;
            int               itemH = (getH() - 18) / v.size() - 4;
            int               y     = 4;
            int               x     = 60;
            stPriceboardState ps    = mContext.mPriceboard.getPriceboard(mShareID);

            if (ps == null)
            {
                return;
            }

            Font   f  = mContext.getFontSmall();
            int    x1 = g.getStringWidth(f, "444.44") + 2;
            int    w0 = getW() - x1;
            string s;

            g.setColor(C.COLOR_GRAY_DARK);
            g.fillRect(0, 0, x1, 14);
            g.setColor(C.COLOR_WHITE);
            g.drawString(f, "Giá", 2, 0);

            g.setColor(C.COLOR_GRAY_DARK);
            g.fillRect(x1 + 2, 0, getW() - x1 - 5, 14);
            g.setColor(C.COLOR_WHITE);
            g.drawString(f, "Khối lượng", x1 + 4, 0);

            y = 18;
            for (i = 0; i < v.size(); i++)
            {
                MoneyVol mv = (MoneyVol)v.elementAt(i);
                sb.Length = 0;
                sb.AppendFormat("{0:F2}", (float)mv.price);
                //  gia
                g.setColor(C.COLOR_GRAY_DARK);
                g.fillRect(0, y, x1, itemH);
                g.setColor(0xffffffff);
                g.drawString(f, sb.ToString(), 2, y);

                if (x1 == 0)
                {
                    x1 = g.getStringWidth(f, sb.ToString());
                }
                //  column
                color = mContext.valToColorF(mv.price, ps.getCe(), ps.getRef(), ps.getFloor());
                g.setColor(color);
                float w = ((float)mv.volume / biggest) * (w0 - 10);
                g.fillRect(2 + x1, y, (int)w, itemH);
                //  volume
                s         = Utils.formatNumber(mv.volume);
                sb.Length = 0;
                sb.AppendFormat("kl={0:}", s);
                s = sb.ToString();
                int w2 = g.getStringWidth(f, s) + 2;
                g.setColor(C.COLOR_GRAY_DARK);
                g.fillRect(4 + x1, y, w2, 14);
                g.setColor(C.COLOR_ORANGE);
                g.drawString(f, s, 5 + x1, y);
                y += itemH + 3;
            }
        }