XY Chart NET 3 Control Reference > Samples > Sample 9: Candle Profile |
This sample demonstrates a basic financial chart showing a candle profile with Buy/Sell signals and Notes for specific data points.
This chart shows two profiles, one of which is a Candle profile. The Candle profile also displays some Buy and Sell signals as well as Notes for some specified data points. The Legend is configured to only show the Close data, during Crosshairs mode, for the Candle profile. Snapshots of the resulting chart are included below.
To test this code, the trial or full version of XY Chart NET must be installed on your computer.
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim ChartArray(9, 6) As Double Dim sellData(1) As Double Dim buyData(1) As Double Dim noteData(2) As String Dim noteDataDatetime(2) As Double Dim dDate As DateTime = New DateTime(2008, 7, 7) Dim myFont As New Font("Arial", 10, FontStyle.Bold) Dim myFont2 As New Font("Arial", 12, FontStyle.Bold) ChartArray(0, 0) = dDate.ToOADate ChartArray(0, 1) = 83.86 ChartArray(0, 2) = 84.94 ChartArray(0, 3) = 83.5 ChartArray(0, 4) = 84.25 ChartArray(0, 5) = dDate.ToOADate ChartArray(0, 6) = 272744 ChartArray(1, 0) = dDate.AddDays(1).ToOADate ChartArray(1, 1) = 82.89 ChartArray(1, 2) = 83.87 ChartArray(1, 3) = 82.04 ChartArray(1, 4) = 83.45 ChartArray(1, 5) = dDate.AddDays(1).ToOADate ChartArray(1, 6) = 396129 ChartArray(2, 0) = dDate.AddDays(2).ToOADate ChartArray(2, 1) = 84.0 ChartArray(2, 2) = 85.38 ChartArray(2, 3) = 82.68 ChartArray(2, 4) = 82.86 ChartArray(2, 5) = dDate.AddDays(2).ToOADate ChartArray(2, 6) = 140030 ChartArray(3, 0) = dDate.AddDays(3).ToOADate ChartArray(3, 1) = 83.85 ChartArray(3, 2) = 85.91 ChartArray(3, 3) = 83.79 ChartArray(3, 4) = 84.95 ChartArray(3, 5) = dDate.AddDays(3).ToOADate ChartArray(3, 6) = 246776 ChartArray(4, 0) = dDate.AddDays(4).ToOADate ChartArray(4, 1) = 87.82 ChartArray(4, 2) = 89.24 ChartArray(4, 3) = 87.74 ChartArray(4, 4) = 88.9 ChartArray(4, 5) = dDate.AddDays(4).ToOADate ChartArray(4, 6) = 867575 ChartArray(5, 0) = dDate.AddDays(7).ToOADate ChartArray(5, 1) = 89.06 ChartArray(5, 2) = 91.72 ChartArray(5, 3) = 88.1 ChartArray(5, 4) = 91.42 ChartArray(5, 5) = dDate.AddDays(7).ToOADate ChartArray(5, 6) = 355617 ChartArray(6, 0) = dDate.AddDays(8).ToOADate ChartArray(6, 1) = 92.36 ChartArray(6, 2) = 93.51 ChartArray(6, 3) = 88.11 ChartArray(6, 4) = 88.91 ChartArray(6, 5) = dDate.AddDays(8).ToOADate ChartArray(6, 6) = 590973 ChartArray(7, 0) = dDate.AddDays(9).ToOADate ChartArray(7, 1) = 88.84 ChartArray(7, 2) = 89.84 ChartArray(7, 3) = 86.11 ChartArray(7, 4) = 87.14 ChartArray(7, 5) = dDate.AddDays(9).ToOADate ChartArray(7, 6) = 249152 ChartArray(8, 0) = dDate.AddDays(10).ToOADate ChartArray(8, 1) = 86.6 ChartArray(8, 2) = 88.76 ChartArray(8, 3) = 84.91 ChartArray(8, 4) = 85.89 ChartArray(8, 5) = dDate.AddDays(10).ToOADate ChartArray(8, 6) = 397455 ChartArray(9, 0) = dDate.AddDays(11).ToOADate ChartArray(9, 1) = 85.69 ChartArray(9, 2) = 86.52 ChartArray(9, 3) = 84.94 ChartArray(9, 4) = 85.45 ChartArray(9, 5) = dDate.AddDays(11).ToOADate ChartArray(9, 6) = 115791 buyData(0) = dDate.AddDays(3).ToOADate sellData(0) = dDate.AddDays(10).ToOADate noteData(0) = "First" noteData(1) = "Second" noteDataDatetime(0) = dDate.AddDays(4).ToOADate noteDataDatetime(1) = dDate.AddDays(7).ToOADate ' Configure XYChart control With XyChartNETCtl1 .NumProfiles = 2 .NumYScales = 2 .NumXScales = 1 .YStacking = True .NumYStacks = 2 .YStack(0).HeightPercentage = 70 .YStack(1).HeightPercentage = 30 .Toolbar.Visible = True .Toolbar.BackColor = Color.White .ZoomWindowColor = Color.LightGreen ' Chart and plot formatting .BackColor = Color.White .Plot.BackColor = Color.White .Plot.Border.LineOption = XYChartNet.XYChartNETCtl.LineOptions.loNone ' Legend With .Legend .Visible = True .BorderVisible = False .YScaleVisible = False End With ' Crosshairs With .Crosshairs .YCoordInLegend = True .CloseCoordInLegend = True .Color = Color.LightGreen .VerticalVisible = True .HorizontalVisible = False .CoordsBackcolor = Color.LightGreen .Width = XYChartNet.XYChartNETCtl.WidthOptions.woTwoPoint End With ' Y Axis With .YAxis(0) With .Grid .LineOption = XYChartNet.XYChartNETCtl.LineOptions.loCustom .LineStyle = XYChartNet.XYChartNETCtl.StyleOptions.soSolid .LineColor = Color.LightGray End With With .Scale .Label = "$" .LabelFont = myFont2 .LabelColor = Color.Black .TicksColor = Color.Black .Visible = True End With End With With .YAxis(1) With .Grid .LineOption = XYChartNet.XYChartNETCtl.LineOptions.loCustom .LineStyle = XYChartNet.XYChartNETCtl.StyleOptions.soSolid .LineColor = Color.LightGray End With With .Scale .Label = "Volume" .LabelFont = myFont2 .LabelColor = Color.Black .TicksColor = Color.Black .Visible = True .ForceZeroDisplay = True End With End With ' X Axis With .XAxis(0) With .Grid .LineOption = XYChartNet.XYChartNETCtl.LineOptions.loCustom .LineStyle = XYChartNet.XYChartNETCtl.StyleOptions.soSolid .LineColor = Color.LightGray End With With .Scale .Label = "2008" .LabelFont = myFont2 .LabelColor = Color.Black .TicksColor = Color.Black .TickLabelSpacing = 1 .FormatStyle = XYChartNet.XYChartNETCtl.FormatStyles.fsDateTime .CenterToDay = True .DateIncludeWeekends = False .DateTimeFormat = "MMM d" .ScaleMode = XYChartNet.XYChartNETCtl.ScaleModes.smManual .ScaleManualMin = dDate.ToOADate .ScaleManualMax = dDate.AddDays(11).ToOADate + 3 .Visible = True End With End With ' Profiles With .Profile(0) .YScale = 0 .NumSamples = 10 .Label = "Price" .ChartFeatureType = XYChartNet.XYChartNETCtl.ChartFeatureOptions.cfCandle .CandleBodyWidth = 15 .CandleShadowWidth = 1 .SellSignalData = sellData .SellSignal = XYChartNet.XYChartNETCtl.SignalOptions.soArrowDown .SellSignalSize = 14 .SellSignalDisplayOffset = 5 .SellSignalBorderColor = Color.Black .SellSignalFillColor = Color.Black .BuySignalData = buyData .BuySignal = XYChartNet.XYChartNETCtl.SignalOptions.soArrowUp .BuySignalSize = 14 .BuySignalDisplayOffset = 6 .BuySignalBorderColor = Color.Blue .BuySignalFillColor = Color.Blue .NoteData = noteData .NoteDataDatetime = noteDataDatetime .NoteColor = Color.Black .NoteRotation = -45 .NoteFont = myFont End With With .Profile(1) .YScale = 1 .NumSamples = 10 .Label = "Volume" .LineOption = XYChartNet.XYChartNETCtl.LineOptions.loCustom .MarkerOption = XYChartNet.XYChartNETCtl.LineOptions.loCustom .ChartFeatureType = XYChartNet.XYChartNETCtl.ChartFeatureOptions.cfBar .BarReference = 0 .BarBorderColor = Color.CadetBlue .BarFillColor = Color.LightBlue .BarWidth = 0.4 End With .ChartData = ChartArray .Refresh() End With End Sub
private void Form1_Load(object sender, EventArgs e) { double [,] ChartArray = new double [10, 7]; double [] sellData = new double [1]; double [] buyData = new double [1]; String[] noteData = new String[2]; double [] noteDataDatetime = new double [2]; DateTime dDate = new DateTime(2008, 7, 7); Font myFont = new Font("Arial", 10, FontStyle.Bold); Font myFont2 = new Font("Arial", 12, FontStyle.Bold); ChartArray[0, 0] = dDate.ToOADate(); ChartArray[0, 1] = 83.86; ChartArray[0, 2] = 84.94; ChartArray[0, 3] = 83.5; ChartArray[0, 4] = 84.25; ChartArray[0, 5] = dDate.ToOADate(); ChartArray[0, 6] = 272744; ChartArray[1, 0] = dDate.AddDays(1).ToOADate(); ChartArray[1, 1] = 82.89; ChartArray[1, 2] = 83.87; ChartArray[1, 3] = 82.04; ChartArray[1, 4] = 83.45; ChartArray[1, 5] = dDate.AddDays(1).ToOADate(); ChartArray[1, 6] = 396129; ChartArray[2, 0] = dDate.AddDays(2).ToOADate(); ChartArray[2, 1] = 84.0; ChartArray[2, 2] = 85.38; ChartArray[2, 3] = 82.68; ChartArray[2, 4] = 82.86; ChartArray[2, 5] = dDate.AddDays(2).ToOADate(); ChartArray[2, 6] = 140030; ChartArray[3, 0] = dDate.AddDays(3).ToOADate(); ChartArray[3, 1] = 83.85; ChartArray[3, 2] = 85.91; ChartArray[3, 3] = 83.79; ChartArray[3, 4] = 84.95; ChartArray[3, 5] = dDate.AddDays(3).ToOADate(); ChartArray[3, 6] = 246776; ChartArray[4, 0] = dDate.AddDays(4).ToOADate(); ChartArray[4, 1] = 87.82; ChartArray[4, 2] = 89.24; ChartArray[4, 3] = 87.74; ChartArray[4, 4] = 88.9; ChartArray[4, 5] = dDate.AddDays(4).ToOADate(); ChartArray[4, 6] = 867575; ChartArray[5, 0] = dDate.AddDays(7).ToOADate(); ChartArray[5, 1] = 89.06; ChartArray[5, 2] = 91.72; ChartArray[5, 3] = 88.1; ChartArray[5, 4] = 91.42; ChartArray[5, 5] = dDate.AddDays(7).ToOADate(); ChartArray[5, 6] = 355617; ChartArray[6, 0] = dDate.AddDays(8).ToOADate(); ChartArray[6, 1] = 92.36; ChartArray[6, 2] = 93.51; ChartArray[6, 3] = 88.11; ChartArray[6, 4] = 88.91; ChartArray[6, 5] = dDate.AddDays(8).ToOADate(); ChartArray[6, 6] = 590973; ChartArray[7, 0] = dDate.AddDays(9).ToOADate(); ChartArray[7, 1] = 88.84; ChartArray[7, 2] = 89.84; ChartArray[7, 3] = 86.11; ChartArray[7, 4] = 87.14; ChartArray[7, 5] = dDate.AddDays(9).ToOADate(); ChartArray[7, 6] = 249152; ChartArray[8, 0] = dDate.AddDays(10).ToOADate(); ChartArray[8, 1] = 86.6; ChartArray[8, 2] = 88.76; ChartArray[8, 3] = 84.91; ChartArray[8, 4] = 85.89; ChartArray[8, 5] = dDate.AddDays(10).ToOADate(); ChartArray[8, 6] = 397455; ChartArray[9, 0] = dDate.AddDays(11).ToOADate(); ChartArray[9, 1] = 85.69; ChartArray[9, 2] = 86.52; ChartArray[9, 3] = 84.94; ChartArray[9, 4] = 85.45; ChartArray[9, 5] = dDate.AddDays(11).ToOADate(); ChartArray[9, 6] = 115791; buyData[0] = dDate.AddDays(3).ToOADate(); sellData[0] = dDate.AddDays(10).ToOADate(); noteData[0] = "First"; noteData[1] = "Second"; noteDataDatetime[0] = dDate.AddDays(4).ToOADate(); noteDataDatetime[1] = dDate.AddDays(7).ToOADate(); // Configure XYChart control xyChartNETCtl1.NumProfiles = 2; xyChartNETCtl1.NumYScales = 2; xyChartNETCtl1.NumXScales = 1; xyChartNETCtl1.YStacking = true; xyChartNETCtl1.NumYStacks = 2; xyChartNETCtl1.get_YStack(0).HeightPercentage = 70; xyChartNETCtl1.get_YStack(1).HeightPercentage = 30; xyChartNETCtl1.Toolbar.Visible = true; xyChartNETCtl1.Toolbar.BackColor = Color.White; xyChartNETCtl1.ZoomWindowColor = Color.LightGreen; // Chart and plot formatting xyChartNETCtl1.BackColor = Color.White; xyChartNETCtl1.Plot.BackColor = Color.White; xyChartNETCtl1.Plot.Border.LineOption = XYChartNet.XYChartNETCtl.LineOptions.loNone; // Legend xyChartNETCtl1.Legend.Visible = true; xyChartNETCtl1.Legend.BorderVisible = false; xyChartNETCtl1.Legend.YScaleVisible = false; // Crosshairs xyChartNETCtl1.Crosshairs.YCoordInLegend = true; xyChartNETCtl1.Crosshairs.CloseCoordInLegend = true; xyChartNETCtl1.Crosshairs.Color = Color.LightGreen; xyChartNETCtl1.Crosshairs.VerticalVisible = true; xyChartNETCtl1.Crosshairs.HorizontalVisible = false; xyChartNETCtl1.Crosshairs.CoordsBackcolor = Color.LightGreen; xyChartNETCtl1.Crosshairs.Width = XYChartNet.XYChartNETCtl.WidthOptions.woTwoPoint; // Y Axis 0 xyChartNETCtl1.get_YAxis(0).Grid.LineOption = XYChartNet.XYChartNETCtl.LineOptions.loCustom; xyChartNETCtl1.get_YAxis(0).Grid.LineStyle = XYChartNet.XYChartNETCtl.StyleOptions.soSolid; xyChartNETCtl1.get_YAxis(0).Grid.LineColor = Color.LightGray; xyChartNETCtl1.get_YAxis(0).Scale.Label = "$"; xyChartNETCtl1.get_YAxis(0).Scale.LabelFont = myFont2; xyChartNETCtl1.get_YAxis(0).Scale.LabelColor = Color.Black; xyChartNETCtl1.get_YAxis(0).Scale.TicksColor = Color.Black; xyChartNETCtl1.get_YAxis(0).Scale.Visible = true; // Y Axis 1 xyChartNETCtl1.get_YAxis(1).Grid.LineOption = XYChartNet.XYChartNETCtl.LineOptions.loCustom; xyChartNETCtl1.get_YAxis(1).Grid.LineStyle = XYChartNet.XYChartNETCtl.StyleOptions.soSolid; xyChartNETCtl1.get_YAxis(1).Grid.LineColor = Color.LightGray; xyChartNETCtl1.get_YAxis(1).Scale.Label = "Volume"; xyChartNETCtl1.get_YAxis(1).Scale.LabelFont = myFont2; xyChartNETCtl1.get_YAxis(1).Scale.LabelColor = Color.Black; xyChartNETCtl1.get_YAxis(1).Scale.TicksColor = Color.Black; xyChartNETCtl1.get_YAxis(1).Scale.Visible = true; xyChartNETCtl1.get_YAxis(1).Scale.ForceZeroDisplay = true; // X Axis xyChartNETCtl1.get_XAxis(0).Grid.LineOption = XYChartNet.XYChartNETCtl.LineOptions.loCustom; xyChartNETCtl1.get_XAxis(0).Grid.LineStyle = XYChartNet.XYChartNETCtl.StyleOptions.soSolid; xyChartNETCtl1.get_XAxis(0).Grid.LineColor = Color.LightGray; xyChartNETCtl1.get_XAxis(0).Scale.Label = "2008"; xyChartNETCtl1.get_XAxis(0).Scale.LabelFont = myFont2; xyChartNETCtl1.get_XAxis(0).Scale.LabelColor = Color.Black; xyChartNETCtl1.get_XAxis(0).Scale.TicksColor = Color.Black; xyChartNETCtl1.get_XAxis(0).Scale.TickLabelSpacing = 1; xyChartNETCtl1.get_XAxis(0).Scale.FormatStyle = XYChartNet.XYChartNETCtl.FormatStyles.fsDateTime; xyChartNETCtl1.get_XAxis(0).Scale.CenterToDay = true; xyChartNETCtl1.get_XAxis(0).Scale.DateIncludeWeekends = false; xyChartNETCtl1.get_XAxis(0).Scale.DateTimeFormat = "MMM d"; xyChartNETCtl1.get_XAxis(0).Scale.ScaleMode = XYChartNet.XYChartNETCtl.ScaleModes.smManual; xyChartNETCtl1.get_XAxis(0).Scale.ScaleManualMin = dDate.ToOADate(); xyChartNETCtl1.get_XAxis(0).Scale.ScaleManualMax = dDate.AddDays(11).ToOADate() + 3; xyChartNETCtl1.get_XAxis(0).Scale.Visible = true; // Profile 0 xyChartNETCtl1.get_Profile(0).YScale = 0; xyChartNETCtl1.get_Profile(0).NumSamples = 10; xyChartNETCtl1.get_Profile(0).Label = "Price"; xyChartNETCtl1.get_Profile(0).ChartFeatureType = XYChartNet.XYChartNETCtl.ChartFeatureOptions.cfCandle; xyChartNETCtl1.get_Profile(0).CandleBodyWidth = 15; xyChartNETCtl1.get_Profile(0).CandleShadowWidth = 1; xyChartNETCtl1.get_Profile(0).SellSignalData = sellData; xyChartNETCtl1.get_Profile(0).SellSignal = XYChartNet.XYChartNETCtl.SignalOptions.soArrowDown; xyChartNETCtl1.get_Profile(0).SellSignalSize = 14; xyChartNETCtl1.get_Profile(0).SellSignalDisplayOffset = 5; xyChartNETCtl1.get_Profile(0).SellSignalBorderColor = Color.Black; xyChartNETCtl1.get_Profile(0).SellSignalFillColor = Color.Black; xyChartNETCtl1.get_Profile(0).BuySignalData = buyData; xyChartNETCtl1.get_Profile(0).BuySignal = XYChartNet.XYChartNETCtl.SignalOptions.soArrowUp; xyChartNETCtl1.get_Profile(0).BuySignalSize = 14; xyChartNETCtl1.get_Profile(0).BuySignalDisplayOffset = 6; xyChartNETCtl1.get_Profile(0).BuySignalBorderColor = Color.Blue; xyChartNETCtl1.get_Profile(0).BuySignalFillColor = Color.Blue; xyChartNETCtl1.get_Profile(0).NoteData = noteData; xyChartNETCtl1.get_Profile(0).NoteDataDatetime = noteDataDatetime; xyChartNETCtl1.get_Profile(0).NoteColor = Color.Black; xyChartNETCtl1.get_Profile(0).NoteRotation = -45; xyChartNETCtl1.get_Profile(0).NoteFont = myFont; // Profile 1 xyChartNETCtl1.get_Profile(1).YScale = 1; xyChartNETCtl1.get_Profile(1).NumSamples = 10; xyChartNETCtl1.get_Profile(1).Label = "Volume"; xyChartNETCtl1.get_Profile(1).LineOption = XYChartNet.XYChartNETCtl.LineOptions.loCustom; xyChartNETCtl1.get_Profile(1).MarkerOption = XYChartNet.XYChartNETCtl.LineOptions.loCustom; xyChartNETCtl1.get_Profile(1).ChartFeatureType = XYChartNet.XYChartNETCtl.ChartFeatureOptions.cfBar; xyChartNETCtl1.get_Profile(1).BarReference = 0; xyChartNETCtl1.get_Profile(1).BarBorderColor = Color.CadetBlue; xyChartNETCtl1.get_Profile(1).BarFillColor = Color.LightBlue; xyChartNETCtl1.get_Profile(1).BarWidth = 0.4; xyChartNETCtl1.ChartData = ChartArray; xyChartNETCtl1.Refresh(); }
Initial Display
With Crosshairs button selected