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
        }