Wednesday, 30 May 2012

22. Trader - First drawing

Application can draw candles. Six days can be analysed. Gray one is for today and it is be drawn with current trading data. More details will come to graph but this is basic start.


Code needed:

         // let's find trading limits
            double priceMax=0;
            double priceMin=1000000;
            int j = 5;      // number of days to draw
            for (int i = 1; i <= j; i++)
            {
                if (historyArray[i, 3] > priceMax) priceMax = historyArray[i, 3]; // find max price for j last days
                if (historyArray[i, 4] < priceMin) priceMin = historyArray[i, 4]; // find min price for j last days
            }
            double priceRange = priceMax - priceMin;
            double pricePerPix = areaHeightMax / priceRange;
            drawCandle(5, pricePerPix, priceMax);
            drawCandle(4, pricePerPix, priceMax);
            drawCandle(3, pricePerPix, priceMax);
            drawCandle(2, pricePerPix, priceMax);
            drawCandle(1, pricePerPix, priceMax);


then:

   private void drawCandle(int noDay, double vPricePerPix, double vPriceMax)
        {
            double[] aR=new double[8];
            for (int i = 0; i < 8; i++) { aR[i]=historyArray[noDay,i];}
            aboutDay ad = new aboutDay(aR);                      // day 5*********************************
            double candleHeiPix = ad.dayBodyLengthNum * vPricePerPix;  // candle  length in pix
            double candleTaiPix = ad.dayTailLengthNum * vPricePerPix;  // candle  tail in pix
             if (noDay == 5)
            {
                body5.Height = Convert.ToInt16(candleHeiPix);
                body5.Top = Convert.ToInt16(areaTopPointMin + (vPriceMax - ad.dayBodyBigger) * vPricePerPix);
                tail5.Height = Convert.ToInt16(candleTaiPix);
                tail5.Top = Convert.ToInt16(areaTopPointMin + (vPriceMax - ad.dayBiggest) * vPricePerPix);
                tail5.Height = Convert.ToInt16(ad.dayTailLengthNum * vPricePerPix);
                if (ad.dayColor == Globals.whitE) body5.BackColor = Color.White;
                if (ad.dayColor == Globals.blacK) body5.BackColor = Color.Black;
                cLabel5.Text =  Convert.ToString( aR[0]).Substring(6,2);
                cLabel5.Top = body5.Top + body5.Height / 2;
            }
            if (noDay == 4)
            {
                body4.Height = Convert.ToInt16(candleHeiPix);
                body4.Top = Convert.ToInt16(areaTopPointMin + (vPriceMax - ad.dayBodyBigger) * vPricePerPix);
                tail4.Height = Convert.ToInt16(candleTaiPix);
                tail4.Top = Convert.ToInt16(areaTopPointMin + (vPriceMax - ad.dayBiggest) * vPricePerPix);
                tail4.Height = Convert.ToInt16(ad.dayTailLengthNum * vPricePerPix);
                if (ad.dayColor == Globals.whitE) body4.BackColor = Color.White;
                if (ad.dayColor == Globals.blacK) body4.BackColor = Color.Black;
            } if (noDay == 3)
            {
                body3.Height = Convert.ToInt16(candleHeiPix);
                body3.Top = Convert.ToInt16(areaTopPointMin + (vPriceMax - ad.dayBodyBigger) * vPricePerPix);
                tail3.Height = Convert.ToInt16(candleTaiPix);
                tail3.Top = Convert.ToInt16(areaTopPointMin + (vPriceMax - ad.dayBiggest) * vPricePerPix);
                tail3.Height = Convert.ToInt16(ad.dayTailLengthNum * vPricePerPix);
                if (ad.dayColor == Globals.whitE) body3.BackColor = Color.White;
                if (ad.dayColor == Globals.blacK) body3.BackColor = Color.Black;
            }
            if (noDay == 2)
            {
                body2.Height = Convert.ToInt16(candleHeiPix);
                body2.Top = Convert.ToInt16(areaTopPointMin + (vPriceMax - ad.dayBodyBigger) * vPricePerPix);
                tail2.Height = Convert.ToInt16(candleTaiPix);
                tail2.Top = Convert.ToInt16(areaTopPointMin + (vPriceMax - ad.dayBiggest) * vPricePerPix);
                tail2.Height = Convert.ToInt16(ad.dayTailLengthNum * vPricePerPix);
                if (ad.dayColor == Globals.whitE) body2.BackColor = Color.White;
                if (ad.dayColor == Globals.blacK) body2.BackColor = Color.Black;
            }
            if (noDay == 1)
            {
                body1.Height = Convert.ToInt16(candleHeiPix);
                body1.Top = Convert.ToInt16(areaTopPointMin + (vPriceMax - ad.dayBodyBigger) * vPricePerPix);
                tail1.Height = Convert.ToInt16(candleTaiPix);
                tail1.Top = Convert.ToInt16(areaTopPointMin + (vPriceMax - ad.dayBiggest) * vPricePerPix);
                tail1.Height = Convert.ToInt16(ad.dayTailLengthNum * vPricePerPix);
                if (ad.dayColor == Globals.whitE) body1.BackColor = Color.White;
                if (ad.dayColor == Globals.blacK) body1.BackColor = Color.Black;
            }
            if (noDay == 0)
            {
                body0.Height = Convert.ToInt16(candleHeiPix);  
                body0.Top = Convert.ToInt16(areaTopPointMin + (vPriceMax - ad.dayBodyBigger) * vPricePerPix);
                tail0.Height = Convert.ToInt16(candleTaiPix);
                tail0.Top = Convert.ToInt16(areaTopPointMin + (vPriceMax - ad.dayBiggest) * vPricePerPix);
                tail0.Height = Convert.ToInt16(ad.dayTailLengthNum * vPricePerPix);
                if (ad.dayColor == Globals.whitE) body0.BackColor = Color.White;
                if (ad.dayColor == Globals.blacK) body0.BackColor = Color.Black;
            }
        }

No comments:

Post a Comment