Exemplo n.º 1
0
        void drawFiboTime(xGraphics g, stTrendLine t)
        {
            uint color = t.color;       //	blue

            g.setColor(color);

            float[]  percent = { 0, 23.6f, 38.2f, 50.0f, 61.8f, 100f, 161.8f };
            String[] txt     = { "0", "23.6", "38.2", "50", "61.8", "100", "161.8" };

            int toRight = 1;

            if (t.x[0] > t.x[1])
            {
                toRight = -1;
            }
            int x0     = mX + t.x[0];
            int deltaX = Utils.ABS_INT((t.x[1] - t.x[0]));
            int maxX   = mX + getW();

            //	int devidedNum = 1000;
            //	char sz[25];

            for (int i = 0; i < 7; i++)
            {
                int x = (int)(x0 + toRight * (percent[i] * deltaX) / 100);
                if (x > maxX || x < 0)
                {
                    continue;
                }

                g.setColor(color);
                if (i == 5)
                {
                    g.drawLine(x, t.y[0], x, mY + getH() - TOP_Y_FIBO_TIME);
                }
                else
                {
                    g.drawLineDotHorizontal(x, t.y[0], x, mY + getH() - TOP_Y_FIBO_TIME);
                }

                if (i == 0 || i == 3 || i == 5 || i == 6)
                {
                    g.setColor(C.COLOR_WHITE);
                    g.drawString(mFont, txt[i], x, t.y[0], 0);//xGraphics::HCENTER|xGraphics::BOTTOM);
                }
            }
        }
Exemplo n.º 2
0
        protected void renderCandle(xGraphics g, stCell c)
        {
            int x, y;

            x = c.x;
            y = 0;

            uint color;

            object o = getUserData();
            String code;

            if (o is String)
            {
                code = (String)o;
            }
            else
            {
                stGainloss gainloss = (stGainloss)o;
                code = gainloss.code;
            }

            if (code == null)
            {
                return;
            }
            stPriceboardState ps = Context.getInstance().mPriceboard.getPriceboard(code);

            if (ps == null)
            {
                return;
            }

            Context ctx = Context.getInstance();

            float price = ps.getCurrentPrice();
            float open  = ctx.mPriceboard.getOpen(ps.getID());

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

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

            //  check hi/lo valid

            if ((hi == 0 || lo == 0))
            {
                TradeHistory trade = Context.getInstance().getTradeHistory(ps.getID());
                float[]      hl    = new float[2];
                if (trade != null && trade.getHiLo(hl))
                {
                    if (hi == 0)
                    {
                        hi = hl[0];
                    }
                    if (lo == 0)
                    {
                        lo = hl[1];
                    }
                }
            }

            if (hi == lo)
            {
                hi = price;
            }

            if (hi == 0)
            {
                hi = open > price ? open : price;
            }
            if (lo == 0)
            {
                lo = open < price ? open : price;
            }
            if (lo == 0)
            {
                lo = hi;
            }
            //---------------------------------------------

            float priceLen = (float)(hi - lo);

            int y0 = 0;

            float min = ps.getRef() - (ps.getRef() / 13);       //	+-7% (7*13==100)
            float max = ps.getRef() + (ps.getRef() / 13);

            if (ps.getMarketID() == 1)
            {
                min = ps.getRef() - (ps.getRef() / 19); //	+-5%
                max = ps.getRef() + (ps.getRef() / 19);
            }

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

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

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

            if (totalPrice == 0)
            {
                return;
            }

            float ry = (float)(getH() - 2 * y0) / totalPrice;

            int totalH = (int)(ry * totalPrice);
            int bodyW  = c.w / 2;

            //================frame=============================
            //  line _ref
            g.setColor(0x70ffff00);
            y = (int)(y0 + totalH - (ps.getRef() - min) * ry);
            g.drawLineDotHorizontal(c.x + 1, y, c.w - 2);
            //===================================================
            if (price == 0)
            {
                return; //	khong co giao dich
            }
            color = price < open ? C.COLOR_RED : C.COLOR_GREEN;
            if (price == open)
            {
                color = C.COLOR_WHITE;
            }

            //  draw shadow
            g.setColor(C.COLOR_WHITE);
            x = c.x + c.w / 2;

            if (lo > 0 && hi > 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);
        }
Exemplo n.º 3
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);
             */
        }
Exemplo n.º 4
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);
        }