Example #1
0
        xBaseControl createCommonTab()
        {
            xContainer c = new xContainer();

            c.setSize(getW() - 6, getH() - 6);
            int y = 0;
            int h = c.getH() / 2 - 10;

            mControlsShouldInvalideAfterNetDone.removeAllElements();

            for (int i = 0; i < mContext.mPriceboard.getIndicesCount(); i++)
            {
                stPriceboardStateIndex pi = mContext.mPriceboard.getPriceboardIndexAt(i);
                if (pi == null || pi.code == null)
                {
                    break;
                }
                IndexControl ic = new IndexControl(mListener, pi.marketID, c.getW(), h);
                ic.setPosition(0, y);
                ic.setSize(c.getW(), h);
                y += ic.getBottom() + 10;

                mControlsShouldInvalideAfterNetDone.addElement(ic);

                c.addControl(ic);
            }

            return(c);
        }
Example #2
0
        public MarketsTab(xIEventListener listener, int w, int h)
            : base(listener)
        {
            mTabControl = new xTabControl();
            this.setSize(w, h);

            mContext = Context.getInstance();

            mTabControl.setSize(w, h);
            addControl(mTabControl);

            //  common
            xTabPage     page = new xTabPage("Hose && Hnx");
            xBaseControl c    = createCommonTab();

            page.addControl(c);

            mTabControl.addPage(page);

            for (int i = 0; i < mContext.mPriceboard.getIndicesCount(); i++)
            {
                stPriceboardStateIndex pi = mContext.mPriceboard.getPriceboardIndexAt(i);
                if (pi == null || pi.code == null)
                {
                    break;
                }

                //  Hose
                page = new xTabPage(pi.code);
                c    = createMarketFullControl(pi);
                page.addControl(c);

                mTabControl.addPage(page);
            }
        }
Example #3
0
        xBaseControl createMarketFullControl(stPriceboardStateIndex pi)
        {
            xContainer c = new xContainer();

            c.setSize(getW() - 6, getH() - 6);

            return(c);
        }
        void showRealtimeChart()
        {
            if (STATE_SHOWING_REALTIME == mState)
            {
                for (int i = 0; i < mRealtimes.size(); i++)
                {
                    xBaseControl c = (xBaseControl)mRealtimes.elementAt(i);
                    removeControl(c);
                }
                mRealtimes.removeAllElements();
                Invalidate();

                mState = STATE_NORMAL;
                MainApplication.getInstance().setSize(getW(), MINI_H);
            }
            else
            {
                int rW   = getW() / 2;
                int rH   = 200;
                int newH = getH() + rH;
                int x    = 0;
                int y    = MINI_H;

                MainApplication.getInstance().setSize(getW(), newH);

                mState = STATE_SHOWING_REALTIME;
                mTimer.expireTimer();

                RealtimeChart r;
                for (int i = 0; i < 2; i++)
                {
                    stPriceboardStateIndex pi = mContext.mPriceboard.getPriceboardIndexAt(i);
                    if (pi != null && pi.id > 0)
                    {
                        r = new RealtimeChart(mContext.getTradeHistory(pi.id), this);
                        r.setPosition(x + 1, y + 1);
                        r.setSize(rW - 2, rH - 2);
                        addControl(r);

                        mRealtimes.addElement(r);

                        x += rW;
                    }
                }
            }
        }
Example #5
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);
                    }
                }
            }
        }
Example #6
0
        public override void render(xGraphics g)
        {
            if (isFocus())
            {
                g.setColor(0xff306AC5);
            }
            else
            {
                g.setColor(C.COLOR_BLACK);
            }
            g.clear();
            g.setColor(0xffffffff);
            g.drawLine(0, getH() - 1, getW(), getH() - 1);
            stPriceboardStateIndex pi = mContext.mPriceboard.getPriceboardIndexOfMarket(mMarketID);

            if (pi == null /* || pi.current_point == 0*/)
            {
                return;
            }

            //===========================================
            //  VNIndex 375.3 (-1.86, -0.49%)   KL: 37,716,548 GT: 560.9 ty     up:84 no:53 down:169
            //===========================================
            int  x = 0;
            int  y = 0;
            uint color;

            g.setColor(C.COLOR_WHITE);
            g.drawString(mFont, pi.code, x, y);

            x = 75;

            if (pi.changed_point > 0)
            {
                color = C.COLOR_GREEN;
            }
            else if (pi.changed_point < 0)
            {
                color = C.COLOR_RED;
            }
            else
            {
                color = C.COLOR_YELLOW;
            }
            g.setColor(color);

            String s;

            s = String.Format("{0:F2}", pi.current_point);
            //  point
            g.drawString(mFont, s, x, y);
            x = 130;
            //  change
            String        s1             = String.Format("{0:F2}", pi.changed_point);
            float         changedPercent = (pi.changed_point * 100) / pi.current_point;
            String        s2             = String.Format("{0:F2}%", changedPercent);
            StringBuilder sb             = Utils.sb;

            sb.Length = 0;
            sb.AppendFormat("({0}, {1})", s1, s2);
            s = sb.ToString();
            g.drawString(mFont, s, x, y);
            x = 220;
            //  KL
            g.setColor(C.COLOR_WHITE);
            double t = pi.total_volume;

            t /= 1000000;
            //s =
            s = Utils.formatNumber((float)t, 2);
            //Utils.formatNumber(0, 1);
            sb.Length = 0;
            sb.AppendFormat("KLGD: {0} tr", s);
            g.drawString(mFont, sb.ToString(), x, y);

            x = 330;
            //  GT
            s         = Utils.formatDecimalNumber(pi.totalGTGD, 1000, 1);
            sb.Length = 0;
            sb.AppendFormat("GTGD: {0} tỷ", s);
            g.drawString(mFont, sb.ToString(), x, y);

            x = 440;

            //  up/none/down
            int frmW = mArrows.Width / 3;
            int frmH = mArrows.Height;

            g.drawImage(mArrows, x, y, frmW, frmH, 0, 0);
            x += frmW + 2;
            g.setColor(C.COLOR_GREEN);
            g.drawString(mFont, "" + pi.inc_cnt, x, y);
            x += 40;
            //  none
            g.drawImage(mArrows, x, y, frmW, frmH, 2 * frmW, 0);
            x += frmW + 2;
            g.setColor(C.COLOR_YELLOW);
            g.drawString(mFont, "" + pi.ref_num, x, y);
            x += 40;
            //  down
            g.drawImage(mArrows, x, y, frmW, frmH, frmW, 0);
            x += frmW + 2;
            g.setColor(C.COLOR_RED);
            g.drawString(mFont, "" + pi.dec_cnt, x, y);
            //  date

            x += 50;

            //  cung-cau
            g.setColor(C.COLOR_WHITE);

            double[] tt = { 0, 0 };
            calcBuySellRemains(pi.marketID, tt);
            //  mua
            t = tt[0] / 1000000;
            s = Utils.formatNumber((float)t, 1);
            //  ban
            t         = tt[1] / 1000000;
            s1        = Utils.formatNumber((float)t, 1);
            sb.Length = 0;
            sb.AppendFormat("Dư M/B={0} / {1}", s, s1);
            g.drawString(mFont, sb.ToString(), x, y);

            x += 150;

            g.setColor(C.COLOR_WHITE);
            g.drawString(mFont, pi.mDate, x, y);
        }
Example #7
0
        public IndexControl(xIEventListener listener, int marketID, int w, int h)
            : base(listener)
        {
            mMarketID = marketID;
            mContext  = Context.getInstance();
            setSize(w, h);

            //setBackgroundColor(0xffff0000);

            mTab = new xTabControl();
            addControl(mTab);

            mTab.setSize(w, h);

            TabControl tc = (TabControl)mTab.getControl();

            tc.Selected += new TabControlEventHandler(tabControlSelected);

            int y = 0;

            for (int i = 0; i < TAB_TITLE.Length; i++)
            {
                xTabPage page = new xTabPage(TAB_TITLE[i]);
                mTab.addPage(page);

                if (i == 0)
                {
                    stPriceboardStateIndex pi    = mContext.mPriceboard.getPriceboardIndexOfMarket(marketID);
                    TradeHistory           trade = mContext.getTradeHistory(pi.id);

                    //  realtime
                    RealtimeChart rc = new RealtimeChart(trade, this);
                    h = getH() - y;
                    rc.setPosition(0, y);
                    rc.setSize(w, h);
                    page.addControl(rc);

                    mRealtimeChart = rc;
                    mCurrentChart  = mRealtimeChart;
                }
            }

            int currentTab = mContext.getMarketControlTab(mMarketID);

            if (currentTab < 0 || currentTab >= TAB_INDEX.Length)
            {
                currentTab = 0;
            }
            if (currentTab != -1)
            {
                ((TabControl)mTab.getControl()).SelectedIndex = currentTab;

                onPageSelected(currentTab);
            }

            /*
             * //  Do thi phien
             *
             * int[] ids = {ID_ONLINE_CHART, ID_MONEY_CHART, ID_VOLUMN_CHART, ID_HIS_CHART};
             * int x = 0;
             * int y = 0;
             * int bw = (w / 4) - 2;
             * for (int i = 0; i < text.Length; i++)
             * {
             *  bt = xButton.createStandardButton(ids[i], this, text[i], bw);
             *  bt.setPosition(x, 0);
             *
             *  addControl(bt);
             *  x = bt.getRight() + 2;
             *  y = bt.getBottom() + 4;
             * }
             */
        }
Example #8
0
        void onPageSelected(int pageIdx)
        {
            mContext.setMarketControlTab(mMarketID, pageIdx);

            int      idx  = TAB_INDEX[pageIdx];
            xTabPage page = mTab.getPageAtIndex(pageIdx);

            if (idx == ID_ONLINE_CHART)
            {
                mRealtimeChart.invalidate();
            }
            else if (idx == ID_CANDLE)
            {
                xContainer c = new xContainer();
                c.setSize(mCurrentChart);

                TodayCandle            candle = new TodayCandle();
                stPriceboardStateIndex pi     = mContext.mPriceboard.getPriceboardIndexOfMarket(mMarketID);
                Share share = mContext.mShareManager.getShare(pi.code);
                candle.setShare(share);

                int w  = mCurrentChart.getW();
                int h  = mCurrentChart.getH();
                int cw = w * 3 / 7;
                if (cw > 160)
                {
                    cw = 160;
                }
                candle.setSize(cw, h);

                c.addControl(candle);

                //  summary
                xBaseControl summary = createMarketSummary(w - cw, h);
                summary.setPosition(cw, 0);
                c.addControl(summary);

                mCurrentChart = c;
                //==============================
                page.resetContent();
                page.addControl(c);
            }
            else if (idx == ID_MONEY_CHART)
            {
                page.resetContent();

                ChartStatistics moneyChart = new ChartStatistics(mMarketID, mListener);
                moneyChart.setSize(mRealtimeChart.getW(), mRealtimeChart.getH() - 18);
                moneyChart.setPosition(mRealtimeChart.getX(), mRealtimeChart.getY());
                moneyChart.setChartType(ChartStatistics.BUBBLE_TRADE_MONEY);

                moneyChart.doCalcChanged();

                page.addControl(moneyChart);

                mCurrentChart = moneyChart;
            }
            else if (idx == ID_VOLUMN_CHART)
            {
                page.resetContent();

                ChartStatistics moneyChart = new ChartStatistics(mMarketID, mListener);
                moneyChart.setSize(mRealtimeChart.getW(), mRealtimeChart.getH() - 18);
                moneyChart.setPosition(mRealtimeChart.getX(), mRealtimeChart.getY());
                moneyChart.setChartType(ChartStatistics.BUBBLE_VOLUME_WEIGHT);

                moneyChart.doCalcChanged();

                page.addControl(moneyChart);

                mCurrentChart = moneyChart;
            }
            else if (idx == ID_INDEX_EFFECT_INC)
            {
                page.resetContent();

                ChartStatistics moneyChart = new ChartStatistics(mMarketID, mListener);
                moneyChart.setSize(mRealtimeChart.getW(), mRealtimeChart.getH() - 18);
                moneyChart.setPosition(mRealtimeChart.getX(), mRealtimeChart.getY());
                moneyChart.setChartType(ChartStatistics.BUBBLE_INDEX_WEIGHT_RATIO_INC);

                moneyChart.doCalcChanged();

                page.addControl(moneyChart);

                mCurrentChart = moneyChart;
            }
            else if (idx == ID_INDEX_EFFECT_DEC)
            {
                page.resetContent();

                ChartStatistics moneyChart = new ChartStatistics(mMarketID, mListener);
                moneyChart.setSize(mRealtimeChart.getW(), mRealtimeChart.getH() - 18);
                moneyChart.setPosition(mRealtimeChart.getX(), mRealtimeChart.getY());
                moneyChart.setChartType(ChartStatistics.BUBBLE_INDEX_WEIGHT_RATIO_DEC);

                moneyChart.doCalcChanged();

                page.addControl(moneyChart);

                mCurrentChart = moneyChart;
            }
        }
Example #9
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();
        }
Example #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);
        }
Example #11
0
        public override void onActivate()
        {
            base.onActivate();
            mIsRequestingNetwork = false;
            //---------------------------------------
            if (mTimer == null)
            {
                mTimer = new xTimer(3000);
            }
            mContext.mNetProtocol.cancelNetwork();
            mContext.mNetProtocol.setListener(this);

            mState = STATE_NORMAL;

            MainApplication.getInstance().minimizeApplicationAsString(700, MINI_H);
            MainApplication.getInstance().postMessage(this, this, C.EVT_WINDOW_INITIALIZED, 0, null);
            if (mCurrentLocationX != -1)
            {
                MainApplication.getInstance().setLocation(mCurrentLocationX, mCurrentLocationY);
            }

            setSize(MainApplication.getInstance().Size.Width, MainApplication.getInstance().Size.Height);

            //this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            //this.BackColor = Color.Coral;

            MiniFormMoving controller = new MiniFormMoving(this, mContext.getImageList(C.IMG_MINI, -1, -1));

            controller.updateStatus();
            controller.setPosition(0, 0);
            addControl(controller);
            mMiniFormMoving = controller;

            //============finally indices
            MiniIndex index;
            int       x = controller.getRight() + 2;

            for (int i = 0; i < 2; i++)
            {
                stPriceboardStateIndex pi = mContext.mPriceboard.getPriceboardIndexAt(i);
                if (pi != null)
                {
                    index = new MiniIndex(pi.marketID);
                    index.setPosition(x, 0);
                    addControl(index);

                    mControls.addElement(index);

                    x = index.getRight();
                }
            }
            //  some buttons
            x = createSystemButtons(x + 2);
            setSize(x, MINI_H);

            MainApplication.getInstance().setSize(x, MINI_H);
            if (mCurrentLocationX == -1)
            {
                mCurrentLocationX = (MainApplication.getDesktopW() - getW()) / 2;
                mCurrentLocationY = 0;
            }

            MainApplication.getInstance().setLocation(mCurrentLocationX, mCurrentLocationY);
            if (!mContext.isOnline())
            {
                mNetState = NETSTATE_PREPARING_LOGIN;
            }
            else
            {
                mNetState = NETSTATE_REQUEST_PREPARING;
            }
        }
Example #12
0
        public override void onTick()
        {
            base.onTick();

            if (mContext.mNetProtocol != null)
            {
                mContext.mNetProtocol.onTick();
            }

            if (mIsRequestingNetwork)
            {
                return;
            }

            if (!mContext.isOnline())
            {
                mNetState = NETSTATE_PREPARING_LOGIN;
            }
            //else
            //{
            //mNetState = NETSTATE_REQUEST_PREPARING;
            //}

            if (!mTimer.isExpired())
            {
                return;
            }
            mTimer.reset();
            //=======================================
            if (mNetState == NETSTATE_PREPARING_LOGIN)
            {
                login();
                mNetState = NETSTATE_LOGGING;
            }
            if (mNetState == NETSTATE_PREPARING_PRICEBOARD_ZERO)
            {
                mContext.mNetProtocol.resetRequest();

                mContext.mNetProtocol.requestPriceboardInitial(-1, null);
                mContext.mNetProtocol.flushRequest();

                mNetState = NETSTATE_GETTING_PRICEBOARD_ZERO;
                return;
            }

            //===============================================
            if (mNetState == NETSTATE_REQUEST_PREPARING)
            {
                if (mState == STATE_NORMAL) //  mini0 mode
                {
                    mContext.mNetProtocol.resetRequest();
                    for (int i = 0; i < mContext.mPriceboard.getIndicesCount(); i++)
                    {
                        stPriceboardStateIndex pi = mContext.mPriceboard.getPriceboardIndexAt(i);
                        mContext.mNetProtocol.requestOnlineIndex(pi.marketID);
                    }
                    mContext.mNetProtocol.flushRequest();
                    mIsRequestingNetwork = true;
                    mNetState            = NETSTATE_REQUEST;
                }
                else if (mState == STATE_SHOWING_REALTIME)//    mini mode with 2 realtime charts
                {
                    mContext.mNetProtocol.resetRequest();
                    for (int i = 0; i < mContext.mPriceboard.getIndicesCount(); i++)
                    {
                        stPriceboardStateIndex pi = mContext.mPriceboard.getPriceboardIndexAt(i);
                        mContext.mNetProtocol.requestOnlineIndex(pi.marketID);
                        if (pi.id != 0)
                        {
                            TradeHistory trade = mContext.getTradeHistory(pi.id);
                            if (trade != null)
                            {
                                mContext.mNetProtocol.requestTradeHistory(pi.code, pi.marketID, 0, trade.getLastTime());
                            }
                        }
                    }
                    mContext.mNetProtocol.flushRequest();
                    mIsRequestingNetwork = true;
                }
                mNetState = NETSTATE_REQUEST;
            }
        }
Example #13
0
        public override void render(xGraphics g)
        {
            g.setColor(C.COLOR_BLACK);
            g.clear();
            g.setColor(0xffffffff);
            g.drawLine(0, 0, 0, getH());
            stPriceboardStateIndex pi = mContext.mPriceboard.getPriceboardIndexOfMarket(mMarketID);

            if (pi == null || pi.current_point == 0)
            {
                return;
            }

            //===========================================
            //  VNIndex 375.3 (-1.86, -0.49%)   KL: 37,716,548 GT: 560.9 ty     up:84 no:53 down:169
            //===========================================
            int lineH = 20;

            int  x0 = 4;
            int  x  = x0;
            int  y  = 0;
            uint color;

            g.setColor(C.COLOR_WHITE);

            Font fTitle = mContext.getFontTextItalic();

            //  date
            x = x0;
            g.setColor(C.COLOR_WHITE);
            g.drawString(fTitle, pi.mDate, x, y);
            y += lineH;
            //==============================
            //  VNINDEX
            g.drawString(mFont, pi.code, x, y);
            //======point

            if (pi.changed_point > 0)
            {
                color = C.COLOR_GREEN;
            }
            else if (pi.changed_point < 0)
            {
                color = C.COLOR_RED;
            }
            else
            {
                color = C.COLOR_YELLOW;
            }
            g.setColor(color);

            String s;

            s = String.Format("{0:F2}", pi.current_point);
            //  point
            x += g.getStringWidth(mFont, pi.code) + 10;
            g.drawString(mFont, s, x, y);

            //  change
            g.setColor(C.COLOR_WHITE);
            y += lineH + 10;
            g.drawString(fTitle, "Thay đổi: ", x0, y);

            x = x0 + g.getStringWidth(fTitle, "Thay đổi: ") + 6;
            g.setColor(color);
            //  change
            String        s1             = String.Format("{0:F2}", pi.changed_point);
            float         changedPercent = (pi.changed_point * 100) / pi.current_point;
            String        s2             = String.Format("{0:F2}", changedPercent);
            StringBuilder sb             = Utils.sb;

            sb.Length = 0;
            sb.AppendFormat("({0}, {1} %)", s1, s2);
            s = sb.ToString();
            g.drawString(mFont, s, x, y);

            x  = x0;
            y += lineH + 10;
            //  KL
            g.setColor(C.COLOR_WHITE);
            double t = pi.total_volume;

            t /= 1000000;
            //s =
            s = Utils.formatNumber((float)t, 2);
            //Utils.formatNumber(0, 1);
            sb.Length = 0;
            sb.AppendFormat("KLGD: {0} tr", s);
            g.drawString(mFont, sb.ToString(), x, y);

            x  = x0;
            y += lineH;
            //  GT
            s         = Utils.formatDecimalNumber(pi.totalGTGD, 1000, 1);
            sb.Length = 0;
            sb.AppendFormat("GTGD: {0} tỷ", s);
            g.drawString(mFont, sb.ToString(), x, y);

            x  = x0;
            y += lineH;
            //  cung-cau
            g.setColor(C.COLOR_WHITE);

            double[] tt = { 0, 0 };
            calcBuySellRemains(pi.marketID, tt);
            //  mua
            t = tt[0] / 1000000;
            s = Utils.formatNumber((float)t, 1);
            //  ban
            t         = tt[1] / 1000000;
            s1        = Utils.formatNumber((float)t, 1);
            sb.Length = 0;
            sb.AppendFormat("Dư mua/bán (tr): {0} / {1}", s, s1);
            g.drawString(mFont, sb.ToString(), x, y);

            x = x0;

            y += lineH + 10;

            g.setColor(C.COLOR_WHITE);
            g.drawString(fTitle, "Số mã tăng/giảm:", x, y);
            y += lineH;
            //  up/none/down
            int frmW = mArrows.Width / 3;
            int frmH = mArrows.Height;

            g.drawImage(mArrows, x, y, frmW, frmH, 0, 0);
            x += frmW + 2;
            g.setColor(C.COLOR_GREEN);
            g.drawString(mFont, "" + pi.inc_cnt, x, y);
            x += 40;
            //  none
            g.drawImage(mArrows, x, y, frmW, frmH, 2 * frmW, 0);
            x += frmW + 2;
            g.setColor(C.COLOR_YELLOW);
            g.drawString(mFont, "" + pi.floor_cnt, x, y);
            x += 40;
            //  down
            g.drawImage(mArrows, x, y, frmW, frmH, frmW, 0);
            x += frmW + 2;
            g.setColor(C.COLOR_RED);
            g.drawString(mFont, "" + pi.dec_cnt, x, y);

            //===========cao:
            x = x0;
            g.setColor(C.COLOR_YELLOW);
            TradeHistory trade = mContext.getTradeHistory(pi.id);

            //  referent
            s  = String.Format("{0:F2}", pi.reference);
            y += lineH + 10;
            s  = "Tham chiếu: " + s;
            //fTitle = mContext.getFon
            g.drawString(mFont, s, x, y);
            //  cao
            s  = String.Format("{0:F2}", trade.mHighest);
            y += lineH;
            s  = "Cao nhất: " + s;
            g.drawString(mFont, s, x, y);

            //  thap
            s  = String.Format("{0:F2}", trade.mLowest);
            y += lineH;
            s  = "Thấp nhất: " + s;
            g.drawString(mFont, s, x, y);
        }
Example #14
0
        void refreshChart2()
        {
            if (group == null)
            {
                group = new stShareGroup();
                group.setType(stShareGroup.ID_GROUP_DEFAULT);
            }

            group.clear();

            currentSelected = null;

            Share index = mContext.mShareManager.getShare(mShareID);
            stPriceboardStateIndex pi = mContext.mPriceboard.getPriceboardIndexOfMarket(index.getMarketID());

            if (index == null || pi == null)
            {
                return;
            }

            if (mContext.mShareManager.getVnindexCnt() == 0)
            {
                return;
            }

            _isProcessing = true;

            index.loadShareFromFile(false);

            stCandle cIndex = new stCandle();

            index.getCandleByDate(startDate, 0, cIndex);
            //===============================================
            double totalEquity = 0.0;

            totalIndexInc = 0;
            totalIndexDec = 0;

            int cnt = mContext.mShareManager.getVnindexCnt();

            double[] indexOfShares   = new double[cnt];
            double[] changedPercents = new double[cnt];
            float[]  prices          = new float[cnt];

            stCandle _c0 = new stCandle();
            stCandle _c1 = new stCandle();

            //  tinh total equity
            for (int i = 0; i < cnt; i++)
            {
                Share share = mContext.mShareManager.getVnindexShareAt(i);
                if (share.getShareID() == 223)
                {
                    indexOfShares[i] = 1;
                }
                indexOfShares[i] = 0;

                if (share.getMarketID() == index.getMarketID() && !share.isIndex())
                {
                    stCompanyInfo inf = mContext.mShareManager.getCompanyInfo(share.getShareID());
                    if (inf != null)
                    {
                        share.loadShareFromCommonData(false);
                        share.appendTodayCandle2(); //  use last price if today is not trade

                        stCandle c0 = share.getCandleByDate(startDate, 0, _c0);
                        stCandle c1 = share.getCandleByDate(endDate, startDate, _c1);

                        if (c0 == null || c1 == null)
                        {
                            continue;
                        }
                        if (c0.close == 0 || c1.close == 0)
                        {
                            continue;
                        }

                        totalEquity += (inf.volume * c0.close);

                        double changedPercent = (c1.close - c0.close) / c0.close;
                        if (changedPercent < 0)
                        {
                            //changedPercent = changedPercent;
                        }
                        indexOfShares[i] = cIndex.close * (inf.volume * c0.close) * changedPercent;

                        if (changedPercent > 0)
                        {
                            totalIndexInc += changedPercent;
                        }
                        else
                        {
                            totalIndexDec += changedPercent;
                        }

                        //---------
                        changedPercents[i] = (c1.close - c0.close) * 100 / c0.close;
                        prices[i]          = c1.close;
                    }
                }
            }

            //  cleanup
            vChangeDec.removeAllElements();
            vChangeInc.removeAllElements();
            //====================================
            totalIndexInc /= totalEquity;
            totalIndexDec /= totalEquity;

            totalIndexInc = 0;
            totalIndexDec = 0;

            for (int i = 0; i < cnt; i++)
            {
                Share share = mContext.mShareManager.getVnindexShareAt(i);

                //if (strcmp(share.mCode, "VIC") == 0){
                //            /i = i;
                //}

                double indexChanged = indexOfShares[i] / totalEquity;

                ChangeIndexItem item;
                if (indexChanged > 0)
                {
                    item = new ChangeIndexItem();
                    item.modifiedValue = (float)indexChanged;

                    totalIndexInc += item.modifiedValue;

                    item.shareID = share.getShareID();

                    vChangeInc.addElement(item);
                }
                else
                {
                    item = new ChangeIndexItem();
                    item.modifiedValue = (float)(-indexChanged);

                    totalIndexDec += item.modifiedValue;

                    item.shareID = share.getShareID();

                    vChangeDec.addElement(item);
                }
                item.price           = prices[i];
                item.modifiedPercent = (float)changedPercents[i];
            }

            //  end of calc
            sortChanges(vChangeInc);
            sortChanges(vChangeDec);

            while (vChangeInc.size() > 200)
            {
                vChangeInc.removeElementAt(vChangeInc.size() - 1);
            }
            while (vChangeDec.size() > 200)
            {
                vChangeDec.removeElementAt(vChangeDec.size() - 1);
            }

            //---------------
            //  ChangeIndexItem
            xVector[] vv = { vChangeInc, vChangeDec };
            for (int j = 0; j < 2; j++)
            {
                for (int i = 0; i < vv[j].size(); i++)
                {
                    ChangeIndexItem item  = (ChangeIndexItem)vv[j].elementAt(i);
                    Share           share = mContext.mShareManager.getShare(item.shareID);
                    if (share != null && share.getCode() != null)
                    {
                        group.addCode(share.getCode());
                    }
                }
            }

            invalidate();
        }
Example #15
0
        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();
        }
Example #16
0
        public override void render(xGraphics g)
        {
            if (isFocus())
                g.setColor(0xff306AC5);
            else
                g.setColor(C.COLOR_BLACK);
            g.clear();
            g.setColor(C.COLOR_GRAY_LIGHT);
            g.drawLine(0, 0, getW(), 0);
            g.setColor(C.COLOR_GRAY_LIGHT);
            g.drawLine(0, getH()-2, getW(), getH()-2);
            stPriceboardStateIndex pi = mContext.mPriceboard.getPriceboardIndexOfMarket(mMarketID);
            if (pi == null || pi.current_point == 0)
                return;

            //===========================================
            //  VNIndex 375.3 (-1.86, -0.49%)   KL: 37,716,548 GT: 560.9 ty     up:84 no:53 down:169
            //===========================================
            int x = 0;
            int y = 0;
            uint color;
            /*
            g.setColor(C.COLOR_WHITE);
            g.drawString(mFont, pi.code, x, y);
             */
            int iconIdx = mMarketID == 1 ? 0 : 1;
            g.drawImage(mIcons.Images[iconIdx], 0, 1);

            x = mIcons.ImageSize.Width + 1;

            if (pi.changed_point > 0) color = C.COLOR_GREEN;
            else if (pi.changed_point < 0) color = C.COLOR_RED;
            else color = C.COLOR_YELLOW;
            g.setColor(color);

            String s;
            s = String.Format("{0:F2}", pi.current_point);
            //  point
            g.drawString(mFont, s, x, y);
            x = 77;
            //  change
            String s1 = String.Format("{0:F2}", pi.changed_point);
            float changedPercent = (pi.changed_point * 100) / pi.current_point;
            String s2 = String.Format("{0:F2}", changedPercent);
            StringBuilder sb = Utils.sb;
            sb.Length = 0;
            if (pi.changed_point >= 0)
                sb.AppendFormat("(+{0}, {1})", s1, s2);
            else sb.AppendFormat("(-{0}, {1})", s1, s2);
            s = sb.ToString();
            g.drawString(mFont, s, x, y);
            x = 160;
            //  KL
            g.setColor(C.COLOR_WHITE);
            s = Utils.formatNumber((int)pi.total_volume);
            sb.Length = 0;
            sb.AppendFormat("KL:{0:F1} tr", (double)(pi.total_volume/1000000));
            g.drawString(mFont, sb.ToString(), x, y);

            x = 245;
            //  GT
            sb.Length = 0;
            sb.AppendFormat("GT:{0:F1} tỷ", (double)pi.totalGTGD/1000);
            g.drawString(mFont, sb.ToString(), x, y);
            /*
            x = 520;

            //  up/none/down
            int frmW = mArrows.Width/3;
            int frmH = mArrows.Height;
            g.drawImage(mArrows, x, y, frmW, frmH, 0, 0);
            x += frmW + 2;
            g.setColor(C.COLOR_GREEN);
            g.drawString(mFont, "" + pi.inc_cnt, x, y);
            x += 40;
            //  none
            g.drawImage(mArrows, x, y, frmW, frmH, 2*frmW, 0);
            x += frmW + 2;
            g.setColor(C.COLOR_YELLOW);
            g.drawString(mFont, "" + pi.floor_cnt, x, y);
            x += 40;
            //  down
            g.drawImage(mArrows, x, y, frmW, frmH, frmW, 0);
            x += frmW + 2;
            g.setColor(C.COLOR_RED);
            g.drawString(mFont, "" + pi.dec_cnt, x, y);
             */
        }