void drawFiboFan(xGraphics g, stTrendLine t) { uint color = t.color; // blue g.setColor(color); float[] percent = { 23.6f, 38.2f, 50.0f, 61.8f };//, 100f}; String[] txt = { "23.6", "38.2", "50", "61.8", "100", "161.8" }; int y = 0; int deltaY = t.y[0] - t.y[1]; int dx = t.x[1] - t.x[0]; int dy = t.y[1] - t.y[0]; for (int i = 0; i < percent.Length; i++) { y = t.y[0] - (int)(deltaY * percent[i] / 100); int x2 = t.x[1] + 2 * dx; int dx2 = x2 - t.x[0]; dy = y - t.y[0]; // => y = dy + t.y[0] // dx/dx2 = dy/dy2 int dy2 = 0; if (dx != 0) { dy2 = dx2 * dy / dx; y = t.y[0] + dy2; } g.drawLineDotHorizontal(t.x[0], t.y[0], x2, y); g.drawString(mFont, txt[i], x2 - 30, y); } }
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); } } }
void test(xGraphics g) { g.setColor(C.COLOR_RED); g.drawLineDotHorizontal(10, 10, 100, 100); g.setColor(C.COLOR_MAGENTA); g.fillRect(30, 40, 15, 15); g.setColor(C.COLOR_GREEN); g.drawString(mContext.getFontText(), "This is a realtime chart", 100, 10, 0); short[] path = { 10, 20, 35, 20, 48, 30, 35, 35 }; g.setColor(C.COLOR_BLUE); g.fillShapes(path, 4); g.drawLines(path, 4); }
protected void renderCursor(xGraphics g) { if (!mShouldDrawCursor) { return; } Share share = getShare(); if (share == null) { return; } int sel = share.getCursor(); int x = candleToX(sel); g.setColor(C.COLOR_GRAY); g.drawLine(x, 0, x, getH()); // mouse title g.setColor(C.COLOR_FADE_YELLOW); g.drawLineDotHorizontal(0, mLastY, getW()); if (mMouseTitle != null && mLastY != 0 & mLastY != 0) { int y = mLastY; x = mLastX; if (y < 12) { y = mLastY + 12; x += 6; // stay away from the mouse } g.setColor(0xa0000000); int sw = Utils.getStringW(mMouseTitle, mContext.getFontSmall()); g.fillRect(x, y - 12, sw, mContext.getFontSmall().Height); g.setColor(C.COLOR_ORANGE); g.drawString(mContext.getFontSmall(), mMouseTitle, x, y - 12); } if (mShouldDrawTitle) { renderTitles(g, 2, 0); } }
public void drawGrid(xGraphics g) { g.setColor(C.GREY_LINE_COLOR); int h = getH(); int w = getW(); int gH = h / 10; int gW = w / 10; int i = 0; int y = gH; int x = gW; for (i = 0; i < 9; i++) { g.drawLineDotHorizontal(0, y, getW() - 40); g.drawVerticalLine(x, 0, h); y += gH; x += gW; } }
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); }
public override void render(xGraphics g) { int mH = getH(); int mW = getW(); if (isHiding()) { return; } Share share = getShare(3); if (share == null) { return; } if (detectShareCursorChanged()) { int rsiPeriod = GlobalData.getData().getValueInt(GlobalData.kStochRSIPeriod1, 14); int stochPeriod = GlobalData.getData().getValueInt(GlobalData.kStochRSIPeriodStock, 14); int smoothK = GlobalData.getData().getValueInt(GlobalData.kStockRSISmoothK, 3); int smoothD = GlobalData.getData().getValueInt(GlobalData.kStochRSISmoothD, 3); share.calcStochRSI(rsiPeriod, stochPeriod, smoothK, smoothD, pStochRSI, pStochRSISMA); mChartLineXY = allocMem(mChartLineXY, mChartLineLength * 2); pricesToYs(pStochRSI, share.mBeginIdx, mChartLineXY, mChartLineLength, -10, 110); float[] tmp = { 0, 20, 50, 80, 100 }; pricesToYs(tmp, 0, mPricelines, 5, -10, 110); // SMA mChartLineXY2 = allocMem(mChartLineXY2, mChartLineLength * 2); pricesToYs(pStochRSISMA, share.mBeginIdx, mChartLineXY2, mChartLineLength, -10, 110); } if (mChartLineLength == 0) { return; } //======================== if (mShouldDrawGrid) { drawGrid(g); } //=============================================== String[] ss = { "0", "20", "50", "80", "100" }; for (int i = 0; i < 5; i++) { if (i == 0 || i == 4 || i == 2) { g.setColor(C.COLOR_GRAY_DARK); g.drawLineDotHorizontal(0, mPricelines[2 * i + 1], getW() - 44, mPricelines[2 * i + 1]); } else { g.setColor(C.COLOR_FADE_YELLOW); g.drawLine(0, mPricelines[2 * i + 1], getW() - 44, mPricelines[2 * i + 1]); } g.setColor(C.COLOR_FADE_YELLOW0); g.drawString(mFont, ss[i], getW() - 8, mPricelines[2 * i + 1], xGraphics.VCENTER | xGraphics.RIGHT); } // stochRSI g.setColor(0xffff8000); g.drawLines(mChartLineXY, mChartLineLength, 1.5f); g.setColor(0xffb000b0); g.drawLines(mChartLineXY2, mChartLineLength, 1.5f); renderDrawer(g); renderCursor(g); }
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); */ }
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); }
public void drawFiboProjection(xGraphics g, stTrendLine t) { uint color = t.color;// Constants.COLOR_FIBO_DOT_LINE2; // blue g.setColor(color); float[] percent = { 0f, 23.6f, 38.2f, 50.0f, 61.8f, 100f, 161.8f }; String[] txt = { "0", "23.6", "38.2", "50.0", "61.8", "100", "161.8" }; int minX = t.x[0] < t.x[1] ? t.x[0] : t.x[1]; minX = minX < t.x[2] ? minX : t.x[2]; int maxX = t.x[0] > t.x[1] ? t.x[0] : t.x[1] + 30; maxX = mX + getW() - 35; int maxY = mY + getH() - 20; int deltaY = t.y[1] - t.y[0]; if (deltaY < 0) { deltaY = -deltaY; } int up = 1; int y0 = t.y[2]; if (t.x[0] < t.x[1] && t.y[0] < t.y[1]) { up = 1; } if (t.x[0] < t.x[1] && t.y[0] > t.y[1]) { up = -1; } if (t.x[0] > t.x[1] && t.y[0] > t.y[1]) { up = 1; } if (t.x[0] > t.x[1] && t.y[0] < t.y[1]) { up = -1; } String s; for (int i = 0; i < 7; i++) { int y = (int)(y0 + up * (percent[i] * deltaY) / 100); if (y > maxY || y < 0) { continue; } g.setColor(color); if (i == 5) { g.drawLine(minX - 30, y, maxX + 30, y); } else { g.drawLineDotHorizontal(minX - 30, y, maxX + 30, y); } //===================== if (i == 0 || i == 3 || i == 5) { s = Utils.formatDecimalNumber((int)mChart.yToPrice(y), 10, 1); g.setColor(C.COLOR_WHITE); g.drawString(mFont, s, maxX, y, xGraphics.VCENTER | xGraphics.TOP); g.drawString(mFont, txt[i], minX - 30, y, xGraphics.VCENTER | xGraphics.TOP); } } }