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); }
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); }