Example #1
0
        public void calcMACD()
        {
            int cnt = this.mCandleCnt;

            if (cnt < 5)
            {
                return;
            }

            float[] val = mPrices;

            float[] ema12 = Share.EMA(val, 0, cnt, 12, null);
            float[] ema26 = Share.EMA(val, 0, cnt, 26, null);

            float[] macd = pMACD;
            for (int i = 0; i < cnt; i++)
            {
                macd[i] = ema12[i] - ema26[i];
            }

            //======signal======EMA9 of MACD
            float[] sig = pMACDSignal9;
            sig[0] = macd[0];
            float exp = (float)2 / (Context.getInstance().mOptMACDSignal + 1);

            for (int i = 1; i < cnt; i++)
            {
                sig[i] = (float)macd[i] * exp + (float)sig[i - 1] * (1 - exp);
            }

            //=======histogram===============
            float[] his = pMACDHistogram;
            for (int i = 0; i < cnt; i++)
            {
                his[i] = macd[i] - sig[i];
            }
            //====================================
            ema12 = null;
            ema26 = null;
        }
Example #2
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.calcOBV();

                mChartLineXY = allocMem(mChartLineXY, mChartLineLength * 2);

                float min = 0xffffff;
                float max = -0xffffff;

                for (int i = share.mBeginIdx; i <= share.mEndIdx; i++)
                {
                    if (share.pOBV[i] > max)
                    {
                        max = share.pOBV[i];
                    }
                    if (share.pOBV[i] < min)
                    {
                        min = share.pOBV[i];
                    }
                }

                pricesToYs(share.pOBV, share.mBeginIdx, mChartLineXY, mChartLineLength, min, max);

                if (mContext.mOptOBV_EMA > 0)
                {
                    mChartEMA = allocMem(mChartEMA, mChartLineLength * 2);

                    if (mContext.mOptOBV_EMA_ON[0])
                    {
                        Share.EMA(share.pOBV, share.getCandleCount(), (int)mContext.mOptOBV_EMA, share.pTMP);
                    }
                    else
                    {
                        Share.SMA(share.pOBV, 0, share.getCandleCount(), (int)mContext.mOptOBV_EMA, share.pTMP);
                    }
                    pricesToYs(share.pTMP, share.mBeginIdx, mChartEMA, mChartLineLength, min, max);
                }
            }

            if (mChartLineLength == 0)
            {
                return;
            }

            //========================
            if (mShouldDrawGrid)
            {
                drawGrid(g);
            }
            //===============================================
            //  OBV
            g.setColor(0xff00f000);
            g.drawLines(mChartLineXY, mChartLineLength, 1.5f);

            if (mContext.mOptOBV_EMA > 0)
            {
                g.setColor(C.COLOR_MAGENTA);
                g.drawLines(mChartEMA, mChartLineLength, 1.0f);
            }

            renderCursor(g);

            renderDrawer(g);
        }