Example #1
0
        public void fillColorRed(xGraphics g, short[] line, int pointCount, short baseline)
        {
            mChartLineColorArea = allocMem(mChartLineColorArea, pointCount * 2 + 20);
            //========red area
            int j = 0;

            g.setColor(0x80ff0000);
            short x  = 0;
            int   x0 = line[0];

            for (int i = 1; i < pointCount; i++)
            {
                x = line[2 * i];
                int y = line[2 * i + 1];
                if (y >= baseline)
                {
                    if (j == 0)
                    {
                        mChartLineColorArea[2 * j]     = (short)(x0 + ((x - x0) / 2));
                        mChartLineColorArea[2 * j + 1] = (short)baseline;
                        j++;
                    }
                    {
                        mChartLineColorArea[2 * j]     = x;
                        mChartLineColorArea[2 * j + 1] = line[2 * i + 1];
                        j++;
                    }
                }
                else if (y < baseline)
                {
                    if (j >= 2)
                    {
                        mChartLineColorArea[2 * j]     = (short)(x0 + ((x - x0) / 2));
                        mChartLineColorArea[2 * j + 1] = (short)baseline;
                        j++;

                        g.fillShapes(mChartLineColorArea, j);
                    }
                    j = 0;
                }
                x0 = x;
            }
            if (j > 1 && pointCount > 2)
            {
                x = line[2 * (pointCount - 1)];

                mChartLineColorArea[2 * j]     = x;
                mChartLineColorArea[2 * j + 1] = (short)baseline;
                j++;

                g.fillShapes(mChartLineColorArea, j);
            }
        }
Example #2
0
        void drawTrendArrow(xGraphics g, stTrendLine t)
        {
            double h = (t.x[1] - t.x[0]) * (t.x[1] - t.x[0]) + (t.y[1] - t.y[0]) * (t.y[1] - t.y[0]);

            h = Math.Sqrt(h);

            double sina = (float)(t.y[1] - t.y[0]) / h;
            double cosa = (float)(t.x[1] - t.x[0]) / h;

            int x01 = -14;
            int y01 = -7;
            int x02 = -14;
            int y02 = +7;

            int x1 = (int)(x01 * cosa - y01 * sina) + t.x[1];
            int y1 = (int)(x01 * sina + y01 * cosa) + t.y[1];

            int x2 = (int)(x02 * cosa - y02 * sina) + t.x[1];
            int y2 = (int)(x02 * sina + y02 * cosa) + t.y[1];

            short[] xy = { (short)x1, (short)y1, (short)x2, (short)y2, (short)t.x[1], (short)t.y[1] };

            g.setColor(t.color);
            g.fillShapes(xy, 3);

            //g.drawTriangle(x1, y1, t.x[1], t.y[1], x2, y2);
        }
Example #3
0
        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);
        }
Example #4
0
        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())
            {
                share.calcIchimoku();

                int newSize = mChartLineLength * 2;
                mLineTenkansen = allocMem(mLineTenkansen, newSize);
                mLineKijunsen  = allocMem(mLineKijunsen, newSize);
                mLineChikou    = allocMem(mLineChikou, newSize);
                mLineSpanA     = allocMem(mLineSpanA, newSize + 1000);
                mLineSpanB     = allocMem(mLineSpanB, newSize + 1000);

                int idx = share.mBeginIdx;
                pricesToYs(share.pTenkansen, idx, mLineTenkansen, mChartLineLength, false);
                pricesToYs(share.pKijunsen, idx, mLineKijunsen, mChartLineLength, false);
                pricesToYs(share.pChikouSpan, idx, mLineChikou, mChartLineLength, false);
                //  correct the chikou length
                int chikouCnt = share.getCandleCount() - (int)mContext.mOptIchimokuTime2;
                mChikouLineLength = mChartLineLength;
                if (idx + mChikouLineLength > chikouCnt)
                {
                    mChikouLineLength = chikouCnt - idx;
                }

                int kumoLen = mChartLineLength + (int)mContext.mOptIchimokuTime2;    //  shift 26 days ahead
                pricesToYs(share.pSpanA, idx, mLineSpanA, kumoLen, false);
                pricesToYs(share.pSpanB, idx, mLineSpanB, kumoLen, false);

                //  kumo cloud
                uint[]     colors  = { 0x40f06070, 0x40f0f0f0 }; //  bronw/white
                int        t       = mLineSpanA[1] > mLineSpanB[1] ? 0 : 1;
                xVectorInt vinters = new xVectorInt(100);
                xVectorInt vcolors = new xVectorInt(100);
                vinters.addElement(0);
                vcolors.addElement((int)colors[t]);

                for (int i = 0; i < kumoLen; i++)
                {
                    int j = 2 * i + 1;
                    if (t == 0)
                    {
                        if (mLineSpanA[j] < mLineSpanB[j])
                        {
                            t = 1 - t;
                            vinters.addElement(i);
                            vcolors.addElement((int)colors[t]);
                        }
                    }
                    else if (t == 1)
                    {
                        if (mLineSpanA[j] > mLineSpanB[j])
                        {
                            t = 1 - t;
                            vinters.addElement(i);
                            vcolors.addElement((int)colors[t]);
                        }
                    }
                }
                //===========================
                vinters.addElement(kumoLen - 1);
                vcolors.addElement(0);  //  dont care this time
                clearKumoCloud();
                //  create kumo cloud
                for (int i = 1; i < vinters.size(); i++)
                {
                    int     b     = vinters.elementAt(i - 1);
                    int     e     = vinters.elementAt(i);
                    short[] cloud = new short[((e - b + 10) * 4)];

                    int j = 0;
                    for (int k = b; k <= e; k++)
                    {
                        cloud[j++] = mLineSpanA[2 * k];
                        cloud[j++] = mLineSpanA[2 * k + 1];
                    }
                    cloud[j++] = mLineSpanB[2 * e];
                    cloud[j++] = mLineSpanB[2 * e + 1];
                    for (int k = e; k >= b; k--)
                    {
                        cloud[j++] = mLineSpanB[2 * k];
                        cloud[j++] = mLineSpanB[2 * k + 1];
                    }

                    mKumoCloud.addElement(cloud);
                    mKumoCloudItemLength.addElement(j / 2);
                    mKumoCloudColor.addElement(vcolors.elementAt(i - 1));
                }
            }

            if (mChartLineLength == 0)
            {
                return;
            }

            //===============================================
            //  tenkansen: pink
            g.setColor(0xc0ff00ff);
            g.drawLines(mLineTenkansen, mChartLineLength);

            //  kijunsen:
            g.setColor(0xc00050ff);
            g.drawLines(mLineKijunsen, mChartLineLength);

            //  chikou
            if (mChikouLineLength > 0)
            {
                g.setColor(0xc0907070);
                g.drawLines(mLineChikou, mChikouLineLength);
            }
            //  spanA
            g.setColor(0xb000a050);
            g.drawLines(mLineSpanA, mChartLineLength + (int)mContext.mOptIchimokuTime2);
            //  spanB
            g.setColor(0xb0ff0000);
            g.drawLines(mLineSpanB, mChartLineLength + (int)mContext.mOptIchimokuTime2);

            //  kumo cloud
            for (int i = 0; i < mKumoCloud.size(); i++)
            {
                short[] p = (short[])mKumoCloud.elementAt(i);
                if (p != null)
                {
                    g.setColor(mKumoCloudColor.elementAt(i));
                    g.fillShapes(p, mKumoCloudItemLength.elementAt(i));
                }
            }

            //  info
            String        sz;
            StringBuilder sb = Utils.sb;

            sb.Length = 0;
            int cur = share.getCursor();
            int y   = 24;

            if (mShouldDrawValue && cur >= 0 && cur < share.getCandleCount())
            {
                g.setColor(0x60404040);
                if (cur - mContext.mOptIchimokuTime2 > 0)
                {
                    int x0 = candleToX(cur - mContext.mOptIchimokuTime2);
                    g.drawVerticalLine(x0, 0, getH());
                }
                int x1 = candleToX(cur + mContext.mOptIchimokuTime2);
                g.drawVerticalLine(x1, 0, getH());

                //==========draw 2 shadow vertical
                g.setColor(0xffffa000);
                sb.AppendFormat("Ichi({0},{1},{2})", (int)mContext.mOptIchimokuTime1, (int)mContext.mOptIchimokuTime2, (int)mContext.mOptIchimokuTime3);
                sz = sb.ToString();
                g.drawString(mFont, sz, 130, y, 0);
                int x = 150 + g.getStringWidth(mFont, sz) + 10;

                String sz1;
                sz1 = formatPrice(share.pTenkansen[cur]);
                //  tenkansen
                g.setColor(0xc0ff00ff);
                sb.Length = 0;
                sb.AppendFormat("Tenkan: {0}", sz1);
                sz = sb.ToString();
                g.drawString(mFont, sz, x, y, 0);
                x += g.getStringWidth(mFont, sz) + 10;
                //  kijun
                g.setColor(0xc00050ff);
                sz1       = formatPrice(share.pKijunsen[cur]);
                sb.Length = 0;
                sb.AppendFormat("Kijun: {0}", sz1);
                sz = sb.ToString();
                g.drawString(mFont, sz, x, y, 0);
                x += g.getStringWidth(mFont, sz) + 10;
                //  chikou
                g.setColor(0xc0a0a0a0);
                float chikou = 0;
                if (cur < share.getCandleCount() - mContext.mOptIchimokuTime2)
                {
                    chikou = share.pChikouSpan[cur];
                }
                sz1       = formatPrice(chikou);
                sb.Length = 0;
                sb.AppendFormat("Chikou: {0}", sz1);
                sz = sb.ToString();
                g.drawString(mFont, sz, x, y, 0);
                x += g.getStringWidth(mFont, sz) + 10;
                //  spanA
                g.setColor(0xff00a050);
                sz1       = formatPrice(share.pSpanA[cur]);
                sb.Length = 0;
                sb.AppendFormat("SpanA: {0}", sz1);
                sz = sb.ToString();
                g.drawString(mFont, sz, x, y, 0);
                x += g.getStringWidth(mFont, sz) + 10;
                //  spanB
                g.setColor(0xb0ff0000);
                sz1       = formatPrice(share.pSpanB[cur]);
                sb.Length = 0;
                sb.AppendFormat("SpanB: {0}", sz1);
                sz = sb.ToString();
                g.drawString(mFont, sz, x, y, 0);
            }
        }
Example #5
0
        void drawBollingers(xGraphics g, int y, int h)
        {
            int[]   times     = mTimes;
            float[] prices    = mPrices;
            int     pricesCnt = mCandleCnt;

            if (pricesCnt <= 0)
            {
                return;
            }

            int pointCnt = 0;

            int i = 0;

            float lo     = mPriceBase - price_distance / 2;
            float hi     = mPriceBase + price_distance / 2;
            int   period = 14;

            if (pricesCnt < 30)
            {
                period = pricesCnt / 3;
            }
            if (period < 2)
            {
                period = 2;
            }
            Share.calcBollinger(prices, pricesCnt, period, 2.0f, pBBLowers, pBBUppers);

            if (mBBLowerXY == null)
            {
                mBBUpperXY = new short[20000];
                mBBLowerXY = new short[20000];
                mBBLine    = new short[40000];
            }

            pricesToXYs(pBBLowers, pricesCnt, mBBUpperXY, times, y, h);
            pricesToXYs(pBBUppers, pricesCnt, mBBLowerXY, times, y, h);

            int j = 0;

            j = 0;

            for (i = 0; i < pricesCnt; i++)
            {
                mBBLine[j++] = mBBUpperXY[2 * i];
                mBBLine[j++] = mBBUpperXY[2 * i + 1];
            }
            mBBLine[j++] = mBBUpperXY[2 * (pricesCnt - 1)];      //  x
            mBBLine[j++] = mBBLowerXY[2 * (pricesCnt - 1) + 1];  //  y
            for (i = pricesCnt - 1; i >= 0; i--)
            {
                mBBLine[j++] = mBBLowerXY[2 * i];
                mBBLine[j++] = mBBLowerXY[2 * i + 1];
            }

            pointCnt = j / 2;
            //=======river
            g.setColor(0x40F8D4CF);
            g.fillShapes(mBBLine, pointCnt);

            //===========border
            pointCnt = mTrade.getTransactionCount();
            g.setColor(0xff752922);
            g.drawLines(mBBUpperXY, pricesCnt);
            g.drawLines(mBBLowerXY, pricesCnt);
        }
Example #6
0
        public override void render(xGraphics g)
        {
            if (isHiding())
            {
                return;
            }
            if (getShare(3) == null)
            {
                return;
            }

            Share share = getShare();

            if (share == null)
            {
                return;
            }

            if (detectShareCursorChanged())
            {
                share.calcBollinger();

                mBBUpperXY = allocMem(mBBUpperXY, mChartLineLength * 2 + 10);
                mBBLowerXY = allocMem(mBBLowerXY, mChartLineLength * 2 + 10);
                mCenterXY  = allocMem(mCenterXY, mChartLineLength * 2 + 10);
                mBBLine    = allocMem(mBBLine, mChartLineLength * 4 + 10);

                pricesToYs(share.pBBUpper, share.mBeginIdx, mBBUpperXY, mChartLineLength, share.getLowestPrice(), share.getHighestPrice());
                pricesToYs(share.pBBLower, share.mBeginIdx, mBBLowerXY, mChartLineLength, share.getLowestPrice(), share.getHighestPrice());

                int j = 0;

                j = 0;

                for (int i = 0; i < mChartLineLength; i++)
                {
                    mBBLine[j++] = mBBUpperXY[2 * i];
                    mBBLine[j++] = mBBUpperXY[2 * i + 1];

                    mCenterXY[2 * i]     = mBBLowerXY[2 * i];
                    mCenterXY[2 * i + 1] = (short)((mBBUpperXY[2 * i + 1] + mBBLowerXY[2 * i + 1]) / 2);
                }
                mBBLine[j++] = mBBUpperXY[2 * (mChartLineLength - 1)];      //  x
                mBBLine[j++] = mBBLowerXY[2 * (mChartLineLength - 1) + 1];  //  y
                for (int i = mChartLineLength - 1; i >= 0; i--)
                {
                    mBBLine[j++] = mBBLowerXY[2 * i];
                    mBBLine[j++] = mBBLowerXY[2 * i + 1];
                }

                mPointCnt = j / 2;
            }

            if (mChartLineLength == 0)
            {
                return;
            }

            int mX = 0;
            int mY = 0;
            int mW = getW();
            int mH = getH();

            g.setColor(mBBColorBG);
            g.fillShapes(mBBLine, mPointCnt);

            g.setColor(0xa00080ff);
            g.drawLinesDot(mCenterXY, mChartLineLength);

            g.setColor(0xff752922);
            g.drawLines(mBBUpperXY, mChartLineLength);
            g.drawLines(mBBLowerXY, mChartLineLength);

            //=================================
            int cur = share.getCursor();

            if (mShouldDrawValue && cur >= 0 && cur < share.getCandleCount())
            {
                g.setColor(0xffffa0a0);

                String        s1 = formatPrice(share.pBBUpper[cur]);
                String        s2 = formatPrice(share.pBBLower[cur]);
                StringBuilder sb = Utils.sb;
                sb.Length = 0;
                sb.AppendFormat("BB({0},{1}) U:{2}     L:{3}", (int)mContext.mOptBBPeriod, (int)mContext.mOptBBD, s1, s2);
                s1 = sb.ToString();
                g.drawString(mFont, s1, 150, 12, 0);
            }
        }