Tuesday, 19 June 2012

24. Trader - Drawing was finished

Now, candle drawing is finished and some pattern recognition.


Two signals are in place. Long white day suggests grow, but long tails bring some  concerns. Confirmation on new trading day is needed.

And some code:
internal class lLongDay
    {
        public lLongDay(double[] arr2,double[] arr1,double[] arr0)
        {
            string mE = " 320-L-Long day ";        // name of the pattern
            aboutDay aD0 = new aboutDay(arr0);
            whatIsTrend wis=new whatIsTrend(arr2,arr1);

            if (aD0.dayLong != Globals.yeS) { idenT = Globals.nO; goto kraj; }
            if (aD0.dayColor == Globals.whitE && wis.trendIs == Globals.growtH)
            {
                mE = Globals.nextDay + aD0.dayDate + mE + " " + Globals.whitE + " " + Globals.growtH + " Continues ";
                Globals.messageS.Add(mE);
            }
            if (aD0.dayColor == Globals.whitE && wis.trendIs == Globals.falL)
            {
                mE = Globals.nextDay + aD0.dayDate + mE + " " + Globals.whitE + " " + Globals.falL + " Reverse ";
                Globals.messageS.Add(mE);
            }
            if (aD0.dayColor == Globals.blacK && wis.trendIs == Globals.falL)
            {
                mE = Globals.nextDay + aD0.dayDate + mE + " " + Globals.blacK + " " + Globals.falL + " Continues ";
                Globals.messageS.Add(mE);
            }
            if (aD0.dayColor == Globals.blacK && wis.trendIs == Globals.growtH)
            {
                mE = Globals.nextDay + aD0.dayDate + mE + " " + Globals.blacK + " " + Globals.growtH + " Reverse ";
                Globals.messageS.Add(mE);
            }
            if (aD0.dayColor == Globals.blacK && wis.trendDesc == Globals.almostTheSameS)
            {
                mE = Globals.nextDay + aD0.dayDate + mE + " " + Globals.blacK + " " + Globals.falL + " Continues ";
                Globals.messageS.Add(mE);
                mE = mE + " " + Globals.blacK + " " + Globals.falL + Globals.weakDay + " D2.close ~ D1.close";
                Globals.messageS.Add(mE);
            }
        kraj: ;

        }
        public string idenT { get; private set; }
    }


Candle drawing routines:

   private void bDrawCandles_Click(object sender, EventArgs e)
        {
            int fH = shLabels.Height + shLabels.Top; // shLabels is upper  limit for graphics
            int maxCdH = fH - upperLimit.Top - 2 * MainMenuStrip.Height; // max drawing area height
            int maxTop = upperLimit.Top + MainMenuStrip.Height;        // top point of drawing area - upper right corner is 0,0
            areaHeightMax = maxCdH - MainMenuStrip.Height;  // height of drawing area
            //areaTopPointMin = maxTop;
            tradingLimits tL = new tradingLimits(Globals.rowSelected, Globals.daysToAnalyse, areaHeightMax, Globals.historyArrayGloDou);
            double pricePerPix = tL.pricePerPix;
            double priceMax = tL.priceMx;
            for (int i = 0; Globals.daysToAnalyse - i >= 0; i++)
            {
                drawCandle dc5 = new drawCandle(Globals.rowSelected, Globals.daysToAnalyse - i, pricePerPix, priceMax, maxTop);
                if (Globals.daysToAnalyse - i == Globals.daysToAnalyse)
                {
                    body5.Top = dc5.body5Top;
                    body5.Height = dc5.body5Height;
                    tail5.Top = dc5.tail5Top;
                    tail5.Height = dc5.tail5Height;
                    cLabel5.Top = shLabels.Top - shLabels.Height;
                    cLabel5.Text = dc5.cLabel5Text;
                    if (dc5.body5BackColor == Globals.whitE) { body5.BackColor = Color.White; };
                    if (dc5.body5BackColor == Globals.blacK) { body5.BackColor = Color.Black; };
                }
                if (Globals.daysToAnalyse - i == Globals.daysToAnalyse - 1)
                {
                    body4.Top = dc5.body4Top;
                    body4.Height = dc5.body4Height;
                    tail4.Top = dc5.tail4Top;
                    tail4.Height = dc5.tail4Height;
                    cLabel4.Top = shLabels.Top - shLabels.Height;
                    cLabel4.Text = dc5.cLabel4Text;
                    if (dc5.body4BackColor == Globals.whitE) { body4.BackColor = Color.White; };
                    if (dc5.body4BackColor == Globals.blacK) { body4.BackColor = Color.Black; };
                }
                if (Globals.daysToAnalyse - i == Globals.daysToAnalyse - 2)
                {
                    body3.Top = dc5.body3Top;
                    body3.Height = dc5.body3Height;
                    tail3.Top = dc5.tail3Top;
                    tail3.Height = dc5.tail3Height;
                    cLabel3.Top = shLabels.Top - shLabels.Height;
                    cLabel3.Text = dc5.cLabel3Text;
                    if (dc5.body3BackColor == Globals.whitE) { body3.BackColor = Color.White; };
                    if (dc5.body3BackColor == Globals.blacK) { body3.BackColor = Color.Black; };
                }
                if (Globals.daysToAnalyse - i == Globals.daysToAnalyse - 3)
                {
                    body2.Top = dc5.body2Top;
                    body2.Height = dc5.body2Height;
                    tail2.Top = dc5.tail2Top;
                    tail2.Height = dc5.tail2Height;
                    cLabel2.Top = shLabels.Top - shLabels.Height;
                    cLabel2.Text = dc5.cLabel2Text;
                    if (dc5.body2BackColor == Globals.whitE) { body2.BackColor = Color.White; };
                    if (dc5.body2BackColor == Globals.blacK) { body2.BackColor = Color.Black; };
                }
                if (Globals.daysToAnalyse - i == Globals.daysToAnalyse - 4)     // yesterday
                {
                    body1.Top = dc5.body1Top;
                    body1.Height = dc5.body1Height;
                    tail1.Top = dc5.tail1Top;
                    tail1.Height = dc5.tail1Height;
                    cLabel1.Top = shLabels.Top - shLabels.Height;
                    cLabel1.Text = dc5.cLabel1Text;
                    if (dc5.body1BackColor == Globals.whitE) { body1.BackColor = Color.White; };
                    if (dc5.body1BackColor == Globals.blacK) { body1.BackColor = Color.Black; };
                    cLabel1B.Top = dc5.cLabel1BTop;
                    cLabel1B.Text = dc5.cLabel1BText;
                    cLabel1S.Top = dc5.cLabel1STop;
                    cLabel1S.Text = dc5.cLabel1SText;
                }
                if (Globals.daysToAnalyse - i == Globals.daysToAnalyse - 5)     // today
                {
                    body0.Top = dc5.body0Top;
                    body0.Height = dc5.body0Height;
                    tail0.Top = dc5.tail0Top;
                    tail0.Height = dc5.tail0Height;
                    cLabel0.Top = shLabels.Top - shLabels.Height;
                    cLabel0.Text = dc5.cLabel0Text;
                    if (dc5.body0BackColor == Globals.whitE) { body0.BackColor = Color.White; };
                    if (dc5.body0BackColor == Globals.blacK) { body0.BackColor = Color.Black; };
                   cLabel0B.Top = dc5.cLabel0BTop;
                    cLabel0B.Text = dc5.cLabel0BText;
                    cLabel0S.Top = dc5.cLabel0STop;
                    cLabel0S.Text = dc5.cLabel0SText;
                }
 
            }
        }

        private void bInitCandleDrawing_Click(object sender, EventArgs e)
        {
            //          candele no 5
            int leftLimit = upperLimit.Left;    // left margin for candles
            tail5.Width = Globals.tailWidhtDef;     //oldest
            tail5.Height = Globals.tailHeightDef;
            body5.Width = Globals.bodyWidthDef;
            body5.Height = Globals.bodyHeightDef;
            tail5.Left = body5.Left + (body5.Width / 2 - tail5.Width / 2);
            cLabel5.Width = Globals.tailWidhtDef;
            cLabel5.Left = body5.Left; // leftLimit + Globals.bodyGap * 0;
            //          candele no 4
            tail4.Width = Globals.tailWidhtDef;     //oldest
            tail4.Height = Globals.tailHeightDef;
            body4.Width = Globals.bodyWidthDef;
            body4.Height = Globals.bodyHeightDef;
            tail4.Left = body4.Left + (body4.Width / 2 - tail4.Width / 2);
            cLabel4.Width = Globals.tailWidhtDef;
            cLabel4.Left = body4.Left;// leftLimit + Globals.bodyGap * 1;
            //          candele no 3
            tail3.Width = Globals.tailWidhtDef;     //oldest
            tail3.Height = Globals.tailHeightDef;
            body3.Width = Globals.bodyWidthDef;
            body3.Height = Globals.bodyHeightDef;
            tail3.Left = body3.Left + (body3.Width / 2 - tail3.Width / 2);
            cLabel3.Width = Globals.tailWidhtDef;
            cLabel3.Left = body3.Left;// leftLimit + Globals.bodyGap * 1;
            //          candele no 2
            tail2.Width = Globals.tailWidhtDef;     //oldest
            tail2.Height = Globals.tailHeightDef;
            body2.Width = Globals.bodyWidthDef;
            body2.Height = Globals.bodyHeightDef;
            tail2.Left = body2.Left + (body2.Width / 2 - tail2.Width / 2);
            cLabel2.Width = Globals.tailWidhtDef;
            cLabel2.Left = body2.Left;// leftLimit + Globals.bodyGap * 1;
            //          candele no 1
            tail1.Width = Globals.tailWidhtDef;     //oldest
            tail1.Height = Globals.tailHeightDef;
            body1.Width = Globals.bodyWidthDef;
            body1.Height = Globals.bodyHeightDef;
            tail1.Left = body1.Left + (body1.Width / 2 - tail1.Width / 2);
            cLabel1.Width = Globals.tailWidhtDef;
            cLabel1.Left = body1.Left; 
            //          candele no 0
            tail0.Width = Globals.tailWidhtDef;     // last
            tail0.Height = Globals.tailHeightDef;
            body0.Width = Globals.bodyWidthDef;
            body0.Height = Globals.bodyHeightDef;
            tail0.Left = body0.Left + (body0.Width / 2 - tail0.Width / 2);
            cLabel0.Width = Globals.tailWidhtDef;
            cLabel0.Left = body0.Left;
        }
    }


After click on Gridview analyse and drawing are performed:

   private void historyGrid_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
           Globals.rowSelected = e.RowIndex;                              // get a row index  // row number for form2
           bFillAndAnalyze.PerformClick();                      // make descriptive analyze
           bDrawCandles.PerformClick();                     // draw candles
        }
 

Wednesday, 30 May 2012

23. Trader - Full project code attached

Lot of code, so far. Here is whole project including item 22.

Sorry, Google does not allow file upload. :-(

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