public void AddBidAskSegment(ChSeries chSeries, int level) { int depth = level == 0 ? 0 : 40 + (level * 24); Color colorBid = System.Drawing.Color.Lime; object RGBBid = (int)ChRGB.Get(colorBid) - (depth << 8); Color colorAsk = System.Drawing.Color.Red; object RGBAsk = (int)ChRGB.Get(colorAsk) - depth; ChSegment segmentAsk = chSeries.FormatMap.Segments.Add(); segmentAsk.Begin.Border.Color = ChRGB.Get(Color.Black); segmentAsk.Begin.Interior.SetSolid(RGBBid); segmentAsk.Begin.Value = 0.0; segmentAsk.Begin.ValueType = ChartBoundaryValueTypeEnum.chBoundaryValueAbsolute; segmentAsk.End.Border.Color = ChRGB.Get(Color.Black); segmentAsk.End.Interior.SetSolid(RGBBid); segmentAsk.End.Value = 0.0; segmentAsk.End.ValueType = ChartBoundaryValueTypeEnum.chBoundaryValueAbsolute; ChSegment segmentLast = chSeries.FormatMap.Segments.Add(); segmentLast.Begin.Border.Color = ChRGB.Get(Color.Black); segmentLast.Begin.Interior.SetSolid(ChRGB.Get(Color.Blue)); segmentLast.Begin.Value = 2.0; segmentLast.Begin.ValueType = ChartBoundaryValueTypeEnum.chBoundaryValueAbsolute; segmentLast.End.Border.DashStyle = ChartLineDashStyleEnum.chLineLongDash; segmentLast.End.Border.Color = ChRGB.Get(Color.Black); segmentLast.End.Interior.SetSolid(ChRGB.Get(Color.Blue)); segmentLast.End.Value = 2.0; segmentLast.End.ValueType = ChartBoundaryValueTypeEnum.chBoundaryValueAbsolute; ChSegment segmentBid = chSeries.FormatMap.Segments.Add(); segmentBid.Begin.Border.Color = ChRGB.Get(Color.Black); segmentBid.Begin.Interior.SetSolid(RGBAsk); segmentBid.Begin.Value = 3.0; segmentBid.Begin.ValueType = ChartBoundaryValueTypeEnum.chBoundaryValueAbsolute; segmentBid.End.Border.DashStyle = ChartLineDashStyleEnum.chLineLongDash; segmentBid.End.Border.Color = ChRGB.Get(Color.Black); segmentBid.End.Interior.SetSolid(RGBAsk); segmentBid.End.Value = 3.0; segmentBid.End.ValueType = ChartBoundaryValueTypeEnum.chBoundaryValueAbsolute; }
public void DisplayForeground(string securityName, decimal startingPrice) { lock (this) { try { lastPrice = 0.0; lastQuantity = 0.0; steps = 17; lowRange = Convert.ToDouble(startingPrice - startingPrice * 0.01M); highRange = Convert.ToDouble(startingPrice + startingPrice * 0.01M); stepSize = (highRange - lowRange) / steps; // Initialize the market InitializeMarket(Convert.ToDouble(startingPrice) + stepSize * 2.0); // Calculate a random price movement and go back in time building the history for this security. The // price movement will be anywhere between nothing and 10 cents. int direction = random.Next(0, 1); double priceChange = Math.Round(random.NextDouble() * direction == 0 ? -0.05 : 0.05, 2); double[] priceHistory = new Double[4]; priceHistory[0] = Convert.ToDouble(startingPrice) + (-priceChange * 2); priceHistory[1] = priceHistory[0] + priceChange; priceHistory[2] = priceHistory[1] + priceChange; priceHistory[3] = priceHistory[2] + priceChange; series = new Series[4]; series[0] = GenerateSeries(); this.MoveMarket(priceHistory[1]); series[1] = GenerateSeries(); this.MoveMarket(priceHistory[2]); series[2] = GenerateSeries(); this.MoveMarket(priceHistory[3]); series[3] = GenerateSeries(); object[] categories = new object[steps]; for (int step = 0; step < steps; step++) { categories[step] = Convert.ToDouble(Math.Round(lowRange + step * stepSize, 2)); } double maxQuantity = 0.0; for (int seriesIndex = 0; seriesIndex < 4; seriesIndex++) { for (int step = 0; step < steps; step++) { if (Convert.ToDouble(series[seriesIndex].values[step]) > maxQuantity) { maxQuantity = Convert.ToDouble(series[seriesIndex].values[step]); } } } // Clear the contents of the chart workspace. This removes // any old charts that may already exist and leaves the chart workspace // completely empty. One chart object is then added. AxChartSpace chartSpace = this.axChartSpace; chartSpace.Clear(); ChChart chartMain = chartSpace.Charts.Add(0); chartMain.Type = ChartChartTypeEnum.chChartTypeColumn3D; chartMain.PlotArea.BackWall.Interior.SetTextured(ChartPresetTextureEnum.chTextureWhiteMarble, ChartTextureFormatEnum.chTile, 0.0, ChartTexturePlacementEnum.chAllFaces); chartMain.PlotArea.SideWall.Interior.SetTextured(ChartPresetTextureEnum.chTextureWhiteMarble, ChartTextureFormatEnum.chTile, 0.0, ChartTexturePlacementEnum.chAllFaces); chartMain.PlotArea.Floor.Interior.SetTextured(ChartPresetTextureEnum.chTextureWhiteMarble, ChartTextureFormatEnum.chTile, 0.0, ChartTexturePlacementEnum.chAllFaces); chartMain.Overlap = 100; chartMain.ChartDepth = 50; chartMain.GapWidth = 50; chartMain.Perspective = 0; chartMain.ProjectionMode = ChartProjectionModeEnum.chProjectionModePerspective; chartMain.Inclination = 30.0; chartMain.DirectionalLightInclination = 10.0; chartMain.DirectionalLightRotation = 60.0; chartMain.DirectionalLightIntensity = 0.5; chartMain.Rotation = 330.0; chartMain.HasTitle = true; chartMain.Title.Caption = securityName; chartMain.Title.Font.Bold = true; chartMain.Title.Font.Name = "Ariel"; chartMain.Title.Font.Size = 12; chartMain.Axes[0].Scaling.Minimum = 1.0; chartMain.Axes[0].Scaling.Maximum = 17.0; chartMain.Axes[1].Scaling.Minimum = 0.0; chartMain.Axes[1].Scaling.Maximum = maxQuantity; chartMain.Axes[1].NumberFormat = "#0.00"; DateTime currentTime = DateTime.Now; // Bid Series ChSeries chSeries0 = chartMain.SeriesCollection.Add(0); chSeries0.Caption = (currentTime - new TimeSpan(0, 15, 0)).ToString("hh:mm"); chSeries0.Interior.SetSolid(ChRGB.Get(Color.Transparent)); chSeries0.Border.Color = ChRGB.Get(Color.Transparent); chSeries0.SetData(ChartDimensionsEnum.chDimCategories, (int)ChartSpecialDataSourcesEnum.chDataLiteral, categories); chSeries0.SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, series[0].values); chSeries0.SetData(ChartDimensionsEnum.chDimFormatValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, series[0].format); AddBidAskSegment(chSeries0, 3); ChSeries chSeries1 = chartMain.SeriesCollection.Add(0); chSeries1.Caption = (currentTime - new TimeSpan(0, 10, 0)).ToString("hh:mm"); chSeries1.Interior.SetSolid(ChRGB.Get(Color.Transparent)); chSeries1.Border.Color = ChRGB.Get(Color.Transparent); chSeries1.SetData(ChartDimensionsEnum.chDimCategories, (int)ChartSpecialDataSourcesEnum.chDataLiteral, categories); chSeries1.SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, series[1].values); chSeries1.SetData(ChartDimensionsEnum.chDimFormatValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, series[1].format); AddBidAskSegment(chSeries1, 2); ChSeries chSeries2 = chartMain.SeriesCollection.Add(0); chSeries2.Caption = (currentTime - new TimeSpan(0, 5, 0)).ToString("hh:mm"); chSeries2.Interior.SetSolid(ChRGB.Get(Color.Transparent)); chSeries2.Border.Color = ChRGB.Get(Color.Transparent); chSeries2.SetData(ChartDimensionsEnum.chDimCategories, (int)ChartSpecialDataSourcesEnum.chDataLiteral, categories); chSeries2.SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, series[2].values); chSeries2.SetData(ChartDimensionsEnum.chDimFormatValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, series[2].format); AddBidAskSegment(chSeries2, 1); ChSeries chSeries3 = chartMain.SeriesCollection.Add(0); chSeries3.Caption = "Now"; chSeries3.Interior.SetSolid(ChRGB.Get(Color.Transparent)); chSeries3.Border.Color = ChRGB.Get(Color.Transparent); chSeries3.SetData(ChartDimensionsEnum.chDimCategories, (int)ChartSpecialDataSourcesEnum.chDataLiteral, categories); chSeries3.SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, series[3].values); chSeries3.SetData(ChartDimensionsEnum.chDimFormatValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, series[3].format); AddBidAskSegment(chSeries3, 0); this.lastPrice = Convert.ToDouble(startingPrice); } catch (Exception exception) { Console.WriteLine(exception.Message); } } }