private void update() { GraphPane variablePane = this.grpGraph.GraphPane; variablePane.CurveList.Clear(); variablePane.Title.Text = this.stock.StockName; variablePane.XAxis.Title.Text = "Time"; variablePane.YAxis.Title.Text = this.stock.StockName; variablePane.XAxis.Type = AxisType.Text; variablePane.XAxis.Scale.TextLabels = data.Time.ToArray(); StockPointList stockList = new StockPointList(); for (int i = 0; i < this.data.NumberObservations; i++) { XDate date = new XDate(this.data.XTime[i]); StockPt point = new StockPt(date.XLDate, this.stock.High[i], this.stock.Low[i], this.stock.Open[i], this.stock.Close[i], this.stock.Volume[i]); stockList.Add(point); } JapaneseCandleStickItem candle = variablePane.AddJapaneseCandleStick(this.stock.StockName, stockList); candle.Stick.RisingFill = new Fill(Color.Blue, Color.LightBlue); candle.Stick.FallingFill = new Fill(Color.Red, Color.IndianRed); candle.Stick.IsAutoSize = true; variablePane.Chart.Fill = new Fill(Color.FromArgb(255, 255, 245), Color.FromArgb(255, 255, 190), 90F); variablePane.Fill = new Fill(Color.White, Color.LightBlue, 135.0f); grpGraph.AxisChange(); zedGraphToolstrip1.SetData(grpGraph, variablePane); }
/// <summary> /// The StockPt copy constructor. /// </summary> /// <param name="rhs">The basis for the copy.</param> public StockPt(StockPt rhs) : base(rhs) { Open = rhs.Open; Close = rhs.Close; Vol = rhs.Vol; }
/// <summary> /// The StockPt copy constructor. /// </summary> /// <param name="rhs">The basis for the copy.</param> public StockPt(StockPt rhs) : base((IPointPair)rhs) { this.Open = rhs.Open; this.Close = rhs.Close; this.Vol = rhs.Vol; }
private static StockPointList CreateStockPointList(long valueStepSizeMinutes) { StockPointList spl = new StockPointList(); Random rand = new Random(); XDate xDate = new XDate(2013, 1, 1); double open = 50.0; for (int i = 0; i < 50; i++) { double x = xDate.XLDate; double close = open + rand.NextDouble() * 10.0 - 5.0; double hi = Math.Max(open, close) + rand.NextDouble() * 5.0; double low = Math.Min(open, close) - rand.NextDouble() * 5.0; StockPt pt = new StockPt(x, hi, low, open, close, 100000); spl.Add(pt); open = close; xDate.AddMinutes(valueStepSizeMinutes); if (XDate.XLDateToDayOfWeek(xDate.XLDate) == 6) { xDate.AddDays(2.0); } } return(spl); }
private static StockPointList <StockPt> CreateStockPointList(long valueStepSizeMinutes) { var spl = new StockPointList <StockPt>(); Random rand = new Random(); XDate xDate = new XDate(2013, 1, 1); var open = 50.0f; for (int i = 0; i < 50; i++) { double x = xDate.XLDate; var close = (float)(open + rand.NextDouble() * 10.0 - 5.0); var hi = (float)(Math.Max(open, close) + rand.NextDouble() * 5.0); var low = (float)(Math.Min(open, close) - rand.NextDouble() * 5.0); StockPt pt = new StockPt(x, open, hi, low, close, 50000, 50000); spl.Add(pt); open = close; xDate.AddMinutes(valueStepSizeMinutes); if (XDate.XLDateToDayOfWeek(xDate.XLDate) == 6) { xDate.AddDays(2.0); } } return(spl); }
/// <summary> /// The Copy Constructor /// </summary> /// <param name="rhs">The StockPointList from which to copy</param> public StockPointList( StockPointList rhs ) { for ( int i = 0; i < rhs.Count; i++ ) { StockPt pt = new StockPt( rhs[i] ); this.Add( pt ); } }
/// <summary> /// The StockPt copy constructor. /// </summary> /// <param name="rhs">The basis for the copy.</param> public StockPt(StockPt rhs) : base((IPointPair)rhs) { Open = rhs.Open; High = rhs.High; VolBuy = rhs.VolBuy; VolSell = rhs.VolSell; ColorValue = rhs.ColorValue; Tag = rhs.Tag is ICloneable ? ((ICloneable)rhs.Tag).Clone() : rhs.Tag; }
public CandleStickDemo() : base("Demonstration of the Candlestick Chart Type", "CandleStick Demo", DemoType.Bar) { GraphPane myPane = base.GraphPane; myPane.Title.Text = "Candlestick Chart Demo"; myPane.XAxis.Title.Text = "Trading Date"; myPane.YAxis.Title.Text = "Share Price, $US"; StockPointList spl = new StockPointList(); Random rand = new Random(); // First day is jan 1st XDate xDate = new XDate( 2006, 1, 1 ); double open = 50.0; for ( int i = 0; i < 50; i++ ) { double x = xDate.XLDate; double close = open + rand.NextDouble() * 10.0 - 5.0; double hi = Math.Max( open, close ) + rand.NextDouble() * 5.0; double low = Math.Min( open, close ) - rand.NextDouble() * 5.0; StockPt pt = new StockPt( x, hi, low, open, close, 100000 ); spl.Add( pt ); open = close; // Advance one day xDate.AddDays( 1.0 ); // but skip the weekends if ( XDate.XLDateToDayOfWeek( xDate.XLDate ) == 6 ) xDate.AddDays( 2.0 ); } CandleStickItem myCurve = myPane.AddCandleStick( "trades", spl, Color.Black ); myCurve.Stick.IsAutoSize = true; myCurve.Stick.Color = Color.Blue; // Use DateAsOrdinal to skip weekend gaps myPane.XAxis.Type = AxisType.DateAsOrdinal; myPane.XAxis.Scale.Min = new XDate( 2006, 1, 1 ); // pretty it up a little myPane.Chart.Fill = new Fill( Color.White, Color.LightGoldenrodYellow, 45.0f ); myPane.Fill = new Fill( Color.White, Color.FromArgb( 220, 220, 255 ), 45.0f ); base.ZedGraphControl.AxisChange(); }
/// <summary> /// The StockPt copy constructor. /// </summary> /// <param name="rhs">The basis for the copy.</param> public StockPt(IPointPair rhs) : base(rhs) { if (rhs is StockPt) { StockPt pt = rhs as StockPt; this.Open = pt.Open; this.Close = pt.Close; this.Vol = pt.Vol; } else { this.Open = PointPair.Missing; this.Close = PointPair.Missing; this.Vol = PointPair.Missing; } }
/// <summary> /// The StockPt copy constructor. /// </summary> /// <param name="rhs">The basis for the copy.</param> public StockPt(StockPt rhs) : base(rhs) { this.Low = rhs.Low; this.Open = rhs.Open; this.Close = rhs.Close; this.Vol = rhs.Vol; this.ColorValue = rhs.ColorValue; if (rhs.Tag is ICloneable) { this.Tag = ((ICloneable)rhs.Tag).Clone(); } else { this.Tag = rhs.Tag; } }
/// <summary> /// The StockPt copy constructor. /// </summary> /// <param name="rhs">The basis for the copy.</param> public StockPt(StockPt rhs) : base(rhs) { Low = rhs.Low; Open = rhs.Open; Close = rhs.Close; Vol = rhs.Vol; initVirtualMemberCallInConstructor(rhs.ColorValue); if (rhs.Tag is ICloneable) { Tag = ((ICloneable)rhs.Tag).Clone(); } else { Tag = rhs.Tag; } }
public void CreateGraph_junk5( ZedGraphControl zgc ) { GraphPane myPane = zgc.GraphPane; // Set the title and axis labels myPane.Title.Text = "Japanese Candlestick Chart Demo"; myPane.XAxis.Title.Text = "Trading Date"; myPane.YAxis.Title.Text = "Share Price, $US"; StockPointList spl = new StockPointList(); Random rand = new Random(); // First day is jan 1st XDate xDate = new XDate( 2006, 1, 1 ); double open = 50.0; for ( int i = 0; i < 1000; i++ ) { double x = xDate.XLDate; double close = open + rand.NextDouble() * 10.0 - 5.0; double hi = Math.Max( open, close ) + rand.NextDouble() * 5.0; double low = Math.Min( open, close ) - rand.NextDouble() * 5.0; StockPt pt = new StockPt( x, hi, low, open, close, 100000 ); spl.Add( pt ); open = close; if ( xDate.DateTime.Hour < 23 ) xDate.AddHours( 1.0 ); else { // Advance one day xDate.AddHours( 1.0 ); // but skip the weekends if ( XDate.XLDateToDayOfWeek( xDate.XLDate ) == 6 ) xDate.AddDays( 2.0 ); } } JapaneseCandleStickItem myCurve = myPane.AddJapaneseCandleStick( "trades", spl ); myCurve.Stick.IsAutoSize = true; myCurve.Stick.Color = Color.Blue; // Use DateAsOrdinal to skip weekend gaps myPane.XAxis.Type = AxisType.DateAsOrdinal; myPane.XAxis.Scale.Min = new XDate( 2006, 1, 1 ); myPane.XAxis.Scale.Format = "dd-MMM-yy hh:mm"; // pretty it up a little myPane.Chart.Fill = new Fill( Color.White, Color.LightGoldenrodYellow, 45.0f ); myPane.Fill = new Fill( Color.White, Color.FromArgb( 220, 220, 255 ), 45.0f ); PointPairList ppl = new PointPairList(); for ( int i = 19; i < spl.Count; i++ ) { double avg = 0.0; for ( int j = 0; j < 20; j++ ) avg += spl.GetAt( i - j ).Close; ppl.Add( i + 1, avg / 20.0 ); } LineItem item = myPane.AddCurve( "MA-20", ppl, Color.Red ); item.IsOverrideOrdinal = true; item.Line.Width = 3; item.Symbol.Type = SymbolType.None; item.Line.IsSmooth = true; // Tell ZedGraph to calculate the axis ranges zgc.AxisChange(); zgc.Invalidate(); }
// OHLC Bar Test private void CreateGraph_OHLCBarTest( ZedGraphControl z1 ) { GraphPane myPane = z1.GraphPane; myPane.Title.Text = "OHLC Chart Demo"; myPane.XAxis.Title.Text = "Trading Date"; myPane.YAxis.Title.Text = "Share Price, $US"; StockPointList spl = new StockPointList(); Random rand = new Random(); // First day is jan 1st XDate xDate = new XDate( 2006, 1, 1 ); double open = 50.0; for ( int i = 0; i < 50; i++ ) { double x = xDate.XLDate; double close = open + rand.NextDouble() * 10.0 - 5.0; double hi = Math.Max( open, close ) + rand.NextDouble() * 5.0; double low = Math.Min( open, close ) - rand.NextDouble() * 5.0; StockPt pt = new StockPt( x, hi, low, open, close, 100000 ); spl.Add( pt ); open = close; // Advance one day //xDate.AddMinutes( 1.0 ); xDate.AddDays( 1.0 ); // but skip the weekends //if ( XDate.XLDateToDayOfWeek( xDate.XLDate ) == 6 ) // xDate.AddMinutes( 2.0 ); } OHLCBarItem myCurve = myPane.AddOHLCBar( "trades", spl, Color.Blue); //myCurve.Bar.IsAutoSize = true; myCurve.Bar.Color = Color.Blue; // Use DateAsOrdinal to skip weekend gaps //myPane.XAxis.Type = AxisType.DateAsOrdinal; myPane.XAxis.Type = AxisType.Date; //myPane.XAxis.Scale.Min = new XDate( 2006, 1, 1 ); // pretty it up a little myPane.Chart.Fill = new Fill( Color.White, Color.LightGoldenrodYellow, 45.0f ); myPane.Fill = new Fill( Color.White, Color.FromArgb( 220, 220, 255 ), 45.0f ); // Tell ZedGraph to calculate the axis ranges z1.AxisChange(); z1.Invalidate(); //z1.PointValueEvent += new ZedGraphControl.PointValueHandler( z1_PointValueEvent ); }
// Traditional Open-High-Low-Close Bar chart private void CreateGraph_OHLCBar( ZedGraphControl z1 ) { GraphPane myPane = z1.GraphPane; myPane.Title.Text = "OHLC Chart Demo"; myPane.XAxis.Title.Text = "Trading Date"; myPane.YAxis.Title.Text = "Share Price, $US"; StockPointList spl = new StockPointList(); Random rand = new Random(); // First day is feb 1st XDate xDate = new XDate( 2006, 2, 1 ); double open = 50.0; for ( int i = 0; i < 20; i++ ) { double x = xDate.XLDate; double close = open + rand.NextDouble() * 10.0 - 5.0; double hi = Math.Max( open, close ) + rand.NextDouble() * 5.0; double low = Math.Min( open, close ) - rand.NextDouble() * 5.0; StockPt pt = new StockPt( x, hi, low, open, close, 100000 ); spl.Add( pt ); open = close; // Advance one day xDate.AddDays( 1.0 ); // but skip the weekends if ( XDate.XLDateToDayOfWeek( xDate.XLDate ) == 6 ) xDate.AddDays( 2.0 ); } //OHLCBarItem myCurve = myPane.AddOHLCBar( "trades", spl, Color.Black ); OHLCBarItem myCurve = myPane.AddOHLCBar( "trades", spl, Color.Blue ); //myCurve.Bar.Size = 20; myCurve.Bar.IsAutoSize = true; //myCurve.Bar.PenWidth = 2; //myCurve.Bar.IsOpenCloseVisible = false; Fill fill = new Fill( Color.Red, Color.Yellow, Color.Blue ); fill.RangeMin = 40; fill.RangeMax = 70; fill.Type = FillType.GradientByY; myCurve.Bar.GradientFill = fill; // Use DateAsOrdinal to skip weekend gaps myPane.XAxis.Type = AxisType.DateAsOrdinal; //myPane.XAxis.Type = AxisType.Date; //myPane.XAxis.Scale.MajorStep = 1.0; // pretty it up a little myPane.Chart.Fill = new Fill( Color.White, Color.LightGoldenrodYellow, 45.0f ); myPane.Fill = new Fill( Color.White, Color.FromArgb( 220, 220, 255 ), 45.0f ); //BoxObj box = new BoxObj( 4, 60, 5, 50000 ); //myPane.GraphObjList.Add( box ); // Tell ZedGraph to calculate the axis ranges z1.AxisChange(); z1.Invalidate(); }
// Call this method from the Form_Load method, passing your ZedGraphControl public void CreateGraph_JapaneseCandleStickDemo( ZedGraphControl zgc ) { GraphPane myPane = zgc.GraphPane; // Set the title and axis labels myPane.Title.Text = "Japanese Candlestick Chart Demo"; myPane.XAxis.Title.Text = "Trading Date"; myPane.YAxis.Title.Text = "Share Price, $US"; StockPointList spl = new StockPointList(); Random rand = new Random(); // First day is jan 1st XDate xDate = new XDate( 2006, 1, 1 ); double open = 50.0; for ( int i = 0; i < 50; i++ ) { double x = xDate.XLDate; double close = open + rand.NextDouble() * 10.0 - 5.0; double hi = Math.Max( open, close ) + rand.NextDouble() * 5.0; double low = Math.Min( open, close ) - rand.NextDouble() * 5.0; StockPt pt = new StockPt( x, hi, low, open, close, 100000 ); spl.Add( pt ); open = close; // Advance one day //xDate.AddDays( 1 + 0.4 * rand.NextDouble() - 0.2 ); xDate.AddDays( 1 ); // but skip the weekends if ( XDate.XLDateToDayOfWeek( xDate.XLDate ) == 6 ) xDate.AddDays( 2.0 ); } JapaneseCandleStickItem myCurve = myPane.AddJapaneseCandleStick( "trades", spl ); myCurve.Stick.IsAutoSize = true; myCurve.Stick.Color = Color.Blue; // Use DateAsOrdinal to skip weekend gaps myPane.XAxis.Type = AxisType.DateAsOrdinal; //myPane.XAxis.Type = AxisType.Date; //myPane.XAxis.Scale.Min = new XDate( 2006, 1, 1 ); // pretty it up a little myPane.Chart.Fill = new Fill( Color.White, Color.LightGoldenrodYellow, 45.0f ); myPane.Fill = new Fill( Color.White, Color.FromArgb( 220, 220, 255 ), 45.0f ); // Tell ZedGraph to calculate the axis ranges zgc.AxisChange(); zgc.Invalidate(); }
// Make a masterpane with 3 charts // Top = OHLC Bar Chart // Mid = Volume Chart // Bot = Price Change public void CreateGraph_OHLCBarMaster( ZedGraphControl zgc ) { // ================================================ // First, set up some lists with random data... // ================================================ StockPointList spl = new StockPointList(); PointPairList volList = new PointPairList(); PointPairList changeList = new PointPairList(); Random rand = new Random(); // First day is jan 1st XDate xDate = new XDate( 2006, 1, 1 ); double open = 50.0; double prevClose = 50.0; const int numDays = 365; // Loop to make 365 days of data for ( int i = 0; i < numDays; i++ ) { double x = xDate.XLDate; //double close = open + rand.NextDouble() * 10.0 - 5.0; double close = open * ( 0.95 + rand.NextDouble() * 0.1 ); //double hi = Math.Max( open, close ) + rand.NextDouble() * 5.0; //double low = Math.Min( open, close ) - rand.NextDouble() * 5.0; double hi = Math.Max( open, close ) * ( 1.0 + rand.NextDouble() * 0.05 ); double low = Math.Min( open, close ) * ( 0.95 + rand.NextDouble() * 0.05 ); double vol = 25.0 + rand.NextDouble() * 100.0; double change = close - prevClose; // Create a StockPt instead of a PointPair so we can carry 6 properties StockPt pt = new StockPt( x, hi, low, open, close, vol ); //if price is increasing color=black, else color=red pt.ColorValue = close > prevClose ? 2 : 1; spl.Add( pt ); volList.Add( x, vol ); changeList.Add( x, change ); prevClose = close; open = close; // Advance one day xDate.AddDays( 1.0 ); // but skip the weekends if ( XDate.XLDateToDayOfWeek( xDate.XLDate ) == 6 ) xDate.AddDays( 2.0 ); } // ================================================ // Create 3 GraphPanes to display the data // ================================================ // get a reference to the masterpane MasterPane master = zgc.MasterPane; // The first chart is already in the MasterPane, so add the other two charts master.Add( new GraphPane() ); master.Add( new GraphPane() ); // ================================================ // The first pane is an OHLCBarItem // ================================================ // Get a reference to the pane GraphPane pane = master[0]; // Set the title and axis labels pane.Title.Text = "Open-High-Low-Close History"; pane.XAxis.Title.Text = "Date"; pane.YAxis.Title.Text = "Price"; // Setup the gradient fill... // Use Red for negative days and black for positive days Color[] colors = { Color.Red, Color.Black }; Fill myFill = new Fill( colors ); myFill.Type = FillType.GradientByColorValue; myFill.SecondaryValueGradientColor = Color.Empty; myFill.RangeMin = 1; myFill.RangeMax = 2; //Create the OHLC and assign it a Fill OHLCBarItem ohlcCurve = pane.AddOHLCBar( "Price", spl, Color.Empty ); ohlcCurve.Bar.GradientFill = myFill; ohlcCurve.Bar.IsAutoSize = true; // Create a JapaneseCandleStick //JapaneseCandleStickItem jcsCurve = pane.AddJapaneseCandleStick( "Price", spl ); //jcsCurve.Stick.IsAutoSize = false; // ================================================ // The second pane is a regular BarItem to show daily volume // ================================================ // Get a reference to the pane pane = master[1]; // Set the title and axis labels pane.Title.Text = "Daily Volume"; pane.XAxis.Title.Text = "Date"; pane.YAxis.Title.Text = "Volume, thousands"; BarItem volBar = pane.AddBar( "Volume", volList, Color.Blue ); // ================================================ // The third pane is a LineItem to show daily price change // ================================================ // Get a reference to the pane pane = master[2]; // Set the title and axis labels pane.Title.Text = "Price Change"; pane.XAxis.Title.Text = "Date"; pane.YAxis.Title.Text = "Price Change, $"; LineItem changeCurve = pane.AddCurve( "Price Change", changeList, Color.Green, SymbolType.None ); // ================================================ // These settings are common to all three panes // ================================================ foreach ( GraphPane paneT in master.PaneList ) { // Use DateAsOrdinal to skip weekend gaps paneT.XAxis.Type = AxisType.DateAsOrdinal; // Use only visible data to define Y scale range paneT.IsBoundedRanges = true; // Define a minimum buffer space to the axes can be aligned paneT.YAxis.MinSpace = 80; paneT.Y2Axis.MinSpace = 50; // pretty it up a little paneT.Chart.Fill = new Fill( Color.White, Color.LightGoldenrodYellow, 45.0f ); paneT.Title.FontSpec.Size = 20.0f; paneT.XAxis.Title.FontSpec.Size = 18.0f; paneT.XAxis.Scale.FontSpec.Size = 16.0f; paneT.YAxis.Title.FontSpec.Size = 18.0f; paneT.YAxis.Scale.FontSpec.Size = 16.0f; paneT.Legend.IsVisible = false; paneT.Fill = new Fill( Color.White, Color.FromArgb( 220, 220, 255 ), 45.0f ); // Set the initial scroll position and range // Note that the min and max for DateAsOrdinal scale will be ordinal values, not dates paneT.XAxis.Scale.Min = 1.0; // default range is 30 days paneT.XAxis.Scale.Max = 30.0; } // ================================================ // Set up the MasterPane Layout // ================================================ // Make sure that fonts and dimensions are the same for all three charts master.IsCommonScaleFactor = true; // Show the masterpane title master.Title.IsVisible = true; master.Title.Text = "Wacky Widget Company Stock Performance"; master.Fill = new Fill( Color.White, Color.SlateBlue, 45.0f ); // Leave a margin around the masterpane, but only a small gap between panes master.Margin.All = 10; master.InnerPaneGap = 5; using ( Graphics g = this.CreateGraphics() ) { master.SetLayout( g, PaneLayout.SingleColumn ); // Synchronize the Axes zgc.IsAutoScrollRange = true; zgc.IsShowHScrollBar = true; zgc.IsSynchronizeXAxes = true; // Scale range will extend about 1 day before and after the actual data range zgc.ScrollGrace = 1.0 / numDays; } // Tell ZedGraph to calculate the axis ranges zgc.AxisChange(); // master[0].XAxis.Scale.Min = new XDate( 2006, 1, 1 ).XLDate; // master[0].XAxis.Scale.Max = master[0].XAxis.Scale.Min + 30.0; // master[1].XAxis.Scale.Min = new XDate( 2006, 1, 1 ).XLDate; // master[1].XAxis.Scale.Max = master[1].XAxis.Scale.Min + 30.0; // master[2].XAxis.Scale.Min = new XDate( 2006, 1, 1 ).XLDate; // master[2].XAxis.Scale.Max = master[2].XAxis.Scale.Min + 30.0; //zgc.ScrollDoneEvent += new ZedGraphControl.ScrollDoneHandler( zgc_ScrollDoneEvent ); zgc.ScrollProgressEvent += new ZedGraphControl.ScrollProgressHandler( zgc_ScrollProgressEvent ); }
public void CreateGraph_OHLCBarGradient( ZedGraphControl zgc ) { GraphPane myPane = zgc.GraphPane; // Set the title and axis labels myPane.Title.Text = "OHLC Chart Demo"; myPane.XAxis.Title.Text = "Date"; myPane.YAxis.Title.Text = "Price"; //Load a StockPointList with random data......................... StockPointList spl = new StockPointList(); Random rand = new Random(); // First day is jan 1st XDate xDate = new XDate( 2006, 1, 1 ); double open = 50.0; double prevClose = 0; // Loop to make 50 days of data for ( int i = 0; i < 50; i++ ) { double x = xDate.XLDate; double close = open + rand.NextDouble() * 10.0 - 5.0; double hi = Math.Max( open, close ) + rand.NextDouble() * 5.0; double low = Math.Min( open, close ) - rand.NextDouble() * 5.0; // Create a StockPt instead of a PointPair so we can carry 6 properties StockPt pt = new StockPt( x, hi, low, open, close, 100000 ); //if price is increasing color=black, else color=red pt.ColorValue = close > prevClose ? 2 : 1; spl.Add( pt ); prevClose = close; open = close; // Advance one day xDate.AddDays( 1.0 ); // but skip the weekends if ( XDate.XLDateToDayOfWeek( xDate.XLDate ) == 6 ) xDate.AddDays( 2.0 ); } // Setup the gradient fill... // Use Red for negative days and black for positive days Color[] colors = { Color.Red, Color.Black }; Fill myFill = new Fill( colors ); myFill.Type = FillType.GradientByColorValue; myFill.SecondaryValueGradientColor = Color.Empty; myFill.RangeMin = 1; myFill.RangeMax = 2; //Create the OHLC and assign it a Fill OHLCBarItem myCurve = myPane.AddOHLCBar( "Price", spl, Color.Empty ); myCurve.Bar.GradientFill = myFill; myCurve.Bar.IsAutoSize = true; // Use DateAsOrdinal to skip weekend gaps myPane.XAxis.Type = AxisType.DateAsOrdinal; //myPane.XAxis.Scale.Min = new XDate( 2006, 1, 1 ); // pretty it up a little myPane.Chart.Fill = new Fill( Color.White, Color.LightGoldenrodYellow, 45.0f ); myPane.Fill = new Fill( Color.White, Color.FromArgb( 220, 220, 255 ), 45.0f ); myPane.Title.FontSpec.Size = 20.0f; myPane.XAxis.Title.FontSpec.Size = 18.0f; myPane.XAxis.Scale.FontSpec.Size = 16.0f; myPane.YAxis.Title.FontSpec.Size = 18.0f; myPane.YAxis.Scale.FontSpec.Size = 16.0f; myPane.Legend.IsVisible = false; // BoxObj box = new BoxObj( 4.5, 0.0, 1.0, 1.0, Color.Transparent, // Color.FromArgb( 100, Color.LightBlue ) ); // box.Location.CoordinateFrame = CoordType.XScaleYChartFraction; // myPane.GraphObjList.Add( box ); // Tell ZedGraph to calculate the axis ranges zgc.AxisChange(); zgc.Invalidate(); }
/// <summary> /// Indexer to access the specified <see cref="StockPt"/> object by /// its ordinal position in the list. /// </summary> /// <param name="index">The ordinal position (zero-based) of the /// <see cref="StockPt"/> object to be accessed.</param> /// <value>A <see cref="StockPt"/> object reference.</value> public PointPair this[int index] { get { return (PointPair) List[index]; } set { List[index] = new StockPt( value ); } }
/// <summary> /// The StockPt copy constructor. /// </summary> /// <param name="rhs">The basis for the copy.</param> public StockPt( StockPt rhs ) : base(rhs) { this.Low = rhs.Low; this.Open = rhs.Open; this.Close = rhs.Close; this.Vol = rhs.Vol; this.ColorValue = rhs.ColorValue; if ( rhs.Tag is ICloneable ) this.Tag = ( (ICloneable)rhs.Tag ).Clone(); else this.Tag = rhs.Tag; }
// 讀取完歷史資料一次畫出歷史 public void DrawGraphOnce( List<KLine> _klLst, List<double> ema11Lst, List<double> ema22Lst) { GraphPane myPane = zg1.GraphPane; StockPointList _ema11Plist = new StockPointList(); StockPointList _ema22Plist = new StockPointList(); List<StockPt> KLPnts = (List<StockPt>)jpnCandle.Points; KLPnts.Clear(); foreach (KLine _kl in _klLst) { XDate xDate = new XDate(_kl.datetime.Year, _kl.datetime.Month, _kl.datetime.Day, _kl.datetime.Hour, _kl.datetime.Minute, 0); StockPt pt_kl = new StockPt(xDate.XLDate, _kl.highest, _kl.lowest, _kl.open, _kl.close, _kl.amount); KLPnts.Add(pt_kl); } // Ema 11 更新 _ema11Plist.Clear(); for (int k = 0; k < _klLst.Count; k++) { KLine _kl = _klLst[k]; double _ema11val = ema11Lst[k]; XDate xDate = new XDate(_kl.datetime.Year, _kl.datetime.Month, _kl.datetime.Day, _kl.datetime.Hour, _kl.datetime.Minute, 0); StockPt pt_ema11 = new StockPt(xDate.XLDate, _ema11val, _ema11val, _ema11val, _ema11val, _ema11val); _ema11Plist.Add(pt_ema11); } // Ema 22 更新 _ema22Plist.Clear(); for (int k = 0; k < _klLst.Count; k++) { KLine _kl = _klLst[k]; double _ema22val = ema22Lst[k]; XDate xDate = new XDate(_kl.datetime.Year, _kl.datetime.Month, _kl.datetime.Day, _kl.datetime.Hour, _kl.datetime.Minute, 0); StockPt pt_ema11 = new StockPt(xDate.XLDate, _ema22val, _ema22val, _ema22val, _ema22val, _ema22val); _ema22Plist.Add(pt_ema11); } ema11LineGr = myPane.AddCurve("ema11", _ema11Plist, Color.Aqua, SymbolType.None); ema22LineGr = myPane.AddCurve("ema22", _ema22Plist, Color.Magenta, SymbolType.None); edtNumFocus_TextChanged(null, null); }
/// <summary> /// Create candles from series x,y data: /// </summary> public List<StockPt> CreateCandle(Series series, double lastUpdate) { decimal start = 0; int day = 24 * 60 * 60; decimal dateTime = 0; decimal equity = 0; List<decimal[]> equityCandles = new List<decimal[]>(); decimal[] candleToday = new decimal[0]; var spl = new List<StockPt>(); if (series.Values.Count > 2000) { day = 30 * 24 * 60 * 60; } else if (series.Values.Count > 365) { day = 7* 24 * 60 * 60; } for (int i = 0; i < series.Values.Count; i++) { if (series.Values[i].x < lastUpdate) continue; dateTime = series.Values[i].x; equity = series.Values[i].y; if (start == 0 || (start + day) < dateTime) start = dateTime; if (start == dateTime) { if (candleToday.Length > 0) equityCandles.Add(candleToday); candleToday = new decimal[5] { -1, 0, -1, 999999999, 0 }; candleToday[0] = start; } if (candleToday[1] == 0) candleToday[1] = equity; if (candleToday[2] < equity) candleToday[2] = equity; if (candleToday[3] > equity) candleToday[3] = equity; candleToday[4] = equity; } foreach (var candle in equityCandles) { DateTime time = UnixMsToDateTime((double)candle[0]); StockPt point = new StockPt(time.ToOADate(), Convert.ToDouble(candle[2]), Convert.ToDouble(candle[3]), Convert.ToDouble(candle[1]), Convert.ToDouble(candle[4]), 1000); spl.Add(point); } return spl; }
public void updGraph(KLine newKL, double newEma11, double newEma22 , int min_rr , int max_rr ) { GraphPane myPane = this.zg1.GraphPane; //Console.WriteLine("KL: [op:" + newKL.open.ToString() + "] [cl:" + newKL.close.ToString() + "]"); // K 棒更新 //KLine newKL = KLLst[KLLst.Count - 2]; List<StockPt> KLPnts = (List<StockPt>)jpnCandle.Points; XDate xDate = new XDate(newKL.datetime.Year, newKL.datetime.Month, newKL.datetime.Day, newKL.datetime.Hour, newKL.datetime.Minute, 0); StockPt pt_kl = new StockPt(xDate.XLDate, newKL.highest, newKL.lowest, newKL.open, newKL.close, newKL.amount); KLPnts.Add(pt_kl); // Ema 11 更新 List<StockPt> Ema11Pnts = (List<StockPt>)ema11LineGr.Points; StockPt pt_ema11 = new StockPt(xDate.XLDate, newEma11, newEma11, newEma11, newEma11, newEma11); Ema11Pnts.Add(pt_ema11); // Ema 11 更新 List<StockPt> Ema22Pnts = (List<StockPt>)ema22LineGr.Points; StockPt pt_ema22 = new StockPt(xDate.XLDate, newEma22, newEma22, newEma22, newEma22, newEma22); Ema22Pnts.Add(pt_ema22); #region Range 更新 : Update myPane.YAxis.Scale.Min = min_rr; myPane.YAxis.Scale.Max = max_rr; //Console.WriteLine(min_rr.ToString()); #endregion zg1.AxisChange(); zg1.Invalidate(); }
public JapaneseCandleStickItem AddCandleStick(string name, double[] seriesHigh, double[] seriesLow, double[] seriesOpen, double[] seriesClose, double[] seriesVolume, Color barUpColor, Color barDownColor, Color risingFillColor, Color risingBorderColor, Color fallingFillColor, Color fallingBorderColor) { if (this.mySeriesX == null) return null; StockPointList spl = new StockPointList(); for (int idx = 0; idx < this.mySeriesX.Length; idx++) { StockPt pt = new StockPt(this.mySeriesX[idx], seriesHigh[idx], seriesLow[idx], seriesOpen[idx], seriesClose[idx], seriesVolume[idx]); spl.Add(pt); } JapaneseCandleStickItem myCurve = myGraphPane.AddJapaneseCandleStick(name, spl); myCurve.Stick.IsAutoSize = true; myCurve.Stick.Color = barUpColor; //Bar up myCurve.Stick.FallingColor = barDownColor; //Bar down //myCurve.Color = Color.Pink; // Unknown myCurve.Stick.FallingFill.Color = fallingFillColor; myCurve.Stick.FallingBorder.Color = fallingBorderColor; myCurve.Stick.RisingFill.Color = risingFillColor; myCurve.Stick.RisingBorder.Color = risingBorderColor; return myCurve; }
/// <summary> /// Draws the Open High Low Close graph. /// </summary> /// <param name="data">The stock points to plot.</param> /// <param name="control">The control to plot on.</param> public void DrawOHLCGraph(ref StockPoints data, ref ZedGraph.ZedGraphControl control) { StockPointList pointList = new StockPointList(); XDate date = new XDate(); foreach (StockPoint s in data) { date = new XDate(s.PointDateTime.Year, s.PointDateTime.Month, s.PointDateTime.Day, s.PointDateTime.Hour, s.PointDateTime.Minute, 0); StockPt p = new StockPt(date.XLDate, s.High, s.Low, s.Open, s.Close, s.Volume); pointList.Add(p); } Color[] colors = { Color.Red, Color.Black }; Fill myFill = new Fill(colors); myFill.Type = FillType.GradientByColorValue; myFill.SecondaryValueGradientColor = Color.Empty; myFill.RangeMin = 1; myFill.RangeMax = 2; MasterPane masterPane = control.MasterPane; masterPane.Margin.All = 10; masterPane.InnerPaneGap = 5; GraphPane ohlcPane = new GraphPane(new Rectangle(10, 10, 10, 10), "OHLC", "Time", "Price"); ohlcPane.IsBoundedRanges = true; OHLCBarItem bar = ohlcPane.AddOHLCBar("Price", pointList, Color.Empty); bar.Bar.GradientFill = myFill; bar.Bar.IsAutoSize = true; bar.Bar.Size = 5; ohlcPane.Title.Text = "OHLC Graph"; ohlcPane.XAxis.Type = AxisType.DateAsOrdinal; ohlcPane.XAxis.Title.Text = "Date"; ohlcPane.YAxis.Title.Text = "Price"; ohlcPane.Margin.All = 0; ohlcPane.Margin.Top = 10; ohlcPane.YAxis.MinSpace = 10; ohlcPane.Y2Axis.MinSpace = 10; ohlcPane.AxisChange(); masterPane.Add(ohlcPane); control.IsShowHScrollBar = true; control.ScrollMinX = 0; control.ScrollMaxX = data.Count; control.GraphPane.XAxis.Scale.Max = data.Count; if (data.Count >= 99) { control.GraphPane.XAxis.Scale.Min = data.Count - 99; } else { control.GraphPane.XAxis.Scale.Min = 0; } using (Graphics g = control.CreateGraphics()) { masterPane.SetLayout(g, PaneLayout.SingleColumn); masterPane.AxisChange(g); // Synchronize the Axes //// g.Dispose(); } }
private static StockPointList CreateStockPointList(long valueStepSizeMinutes) { StockPointList spl = new StockPointList(); Random rand = new Random(); XDate xDate = new XDate(2013, 1, 1); double open = 50.0; for (int i = 0; i < 50; i++) { double x = xDate.XLDate; double close = open + rand.NextDouble() * 10.0 - 5.0; double hi = Math.Max(open, close) + rand.NextDouble() * 5.0; double low = Math.Min(open, close) - rand.NextDouble() * 5.0; StockPt pt = new StockPt(x, hi, low, open, close, 100000); spl.Add(pt); open = close; xDate.AddMinutes(valueStepSizeMinutes); if (XDate.XLDateToDayOfWeek(xDate.XLDate) == 6) { xDate.AddDays(2.0); } } return spl; }
private void UpdatePrice(int noOfUpdate, CurveItem curve) { this.ShowMessage("Update " + noOfUpdate.ToString()); IPointListEdit list = curve.Points as IPointListEdit; int lastPos = list.Count - 1; if (curve.GetType() == typeof(JapaneseCandleStickItem)) { if (lastPos >= 0)(list as StockPointList).RemoveAt(lastPos); for (int idx = Math.Max(0, lastPos); idx < myData.DateTime.Count; idx++) { StockPt item = new StockPt(myData.DateTime[idx], myData.High.Values[idx], myData.Low.Values[idx], myData.Open.Values[idx], myData.Close.Values[idx], myData.Volume.Values[idx]); (list as StockPointList).Add(item); } } else { if (lastPos >= 0) (list as PointPairList).RemoveAt(lastPos); for (int idx = Math.Max(0,lastPos); idx < myData.DateTime.Count; idx++) { PointPair item = new PointPair(myData.DateTime[idx], myData.Close.Values[idx]); (list as PointPairList).Add(item); } } }
public static ZedGraphControl KresliJednoduchyGraf(string forecastGraf, List<ObchodnyDen> getDataPreGraf, ZedGraphControl zg1) { try { zg1.GraphPane.CurveList.Clear(); zg1.GraphPane.GraphObjList.Clear(); GraphPane myPane = zg1.GraphPane; // Set the titles and axis labels myPane.Title.Text = forecastGraf; myPane.XAxis.Title.Text = "Date"; myPane.YAxis.Title.Text = "$"; myPane.XAxis.Type = AxisType.Date; var spl = new StockPointList(); int rok = getDataPreGraf.First().Date.Year; DateTime predchadzDatum = getDataPreGraf.First().Date; foreach (var den in getDataPreGraf) { var x = (double)new XDate(DateTime.Parse(den.Date.ToShortDateString())); double open = den.Open; double close = den.Settle; double hi = den.High; double low = den.Low; var pt = new StockPt(x, hi, low, open, close, 100000); spl.Add(pt); if (den.Date.Year != predchadzDatum.Year) { LineItem line = new LineItem(String.Empty, new[] { x, x }, new[] { myPane.YAxis.Scale.Min, myPane.YAxis.Scale.Max }, Color.Black, SymbolType.None); line.Line.Style = System.Drawing.Drawing2D.DashStyle.Dash; line.Line.Width = 1f; //myPane.CurveList.Add(line); Console.WriteLine("Datum " + den.Date); } predchadzDatum = den.Date; } JapaneseCandleStickItem myCurve = myPane.AddJapaneseCandleStick("trades", spl); myCurve.Stick.IsAutoSize = true; myCurve.Stick.Color = Color.Blue; // Use DateAsOrdinal to skip weekend gaps myPane.XAxis.Type = AxisType.DateAsOrdinal; // pretty it up a little //myPane.Chart.Fill = new Fill(Color.White, Color.LightGoldenrodYellow, 45.0f); //myPane.Fill = new Fill(Color.White, Color.FromArgb(220, 220, 255), 45.0f); // Tell ZedGraph to calculate the axis ranges zg1.AxisChange(); zg1.Invalidate(); return zg1; }catch (Exception) { } return null; }
private void CreateGraph(ZedGraphControl zgc, int iDayChart) { // get a reference to the GraphPane GraphPane myPane = zgc.GraphPane; myPane.CurveList.Clear(); DiaNegocio diaChart = new DiaNegocio(); myPane.Title.Text = "Japanese Candlestick Chart Demo"; myPane.XAxis.Title.Text = "Trading Date"; myPane.YAxis.Title.Text = "Share Price, $US"; StockPointList spl = new StockPointList(); Random rand = new Random(); // First day is jan 1st XDate xDate = new XDate(2006, 1, 1); for (int i = 0; dia[iDayChart].Ticker[i] != null; i++) { CriarPontodeEntradaDia(iDayChart); diaChart = dia[iDayChart]; myPane.Title.Text = "WINFUT " + diaChart.dtData.ToString(); double x = diaChart.Ticker[i].dtData.ToOADate();//xDate.XLDate; double open = diaChart.Ticker[i].iAbertura; double close = diaChart.Ticker[i].iFechamento;//open + rand.NextDouble() * 10.0 - 5.0; double hi = diaChart.Ticker[i].iMaximo;// Math.Max(open, close) + rand.NextDouble() * 5.0; double low = diaChart.Ticker[i].iMinimo;// Math.Min(open, close) - rand.NextDouble() * 5.0; StockPt pt = new StockPt(x, hi, low, open, close, 100000); spl.Add(pt); //open = close; // Advance one day //xDate.AddDays(1.0); // but skip the weekends //if (XDate.XLDateToDayOfWeek(xDate.XLDate) == 6) // xDate.AddDays(2.0); } JapaneseCandleStickItem myCurve = myPane.AddJapaneseCandleStick("trades", spl); myCurve.Stick.IsAutoSize = true; myCurve.Stick.Color = Color.Blue; double[] dbentradavenda = new double[500]; for( int i = 0; i < 500; i++) dbentradavenda[i] = (double)diaChart.iEntradaVenda; LineItem entradaVenda = myPane.AddCurve("Venda", null, dbentradavenda, Color.Red,SymbolType.None); double[] dbentradacompra = new double[500]; for (int i = 0; i < 500; i++) dbentradacompra[i] = (double)diaChart.iEntradaCompra; LineItem entradaCompra = myPane.AddCurve("Compra", null, dbentradacompra, Color.Green, SymbolType.None); // Use DateAsOrdinal to skip weekend gaps myPane.XAxis.Type = AxisType.DateAsOrdinal; // pretty it up a little myPane.Chart.Fill = new Fill(Color.White, Color.LightGoldenrodYellow, 45.0f); myPane.Fill = new Fill(Color.White, Color.FromArgb(220, 220, 255), 45.0f); // Tell ZedGraph to refigure the // axes since the data have changed zgc.AxisChange(); zgc.Invalidate(); //ATENÇÃO, OBSERVAR QUE QUANDO RETORNA À PRIMEIRA ENTRADA COMUMENTE EMBARCA NO SENTIDO CONTRÁRIO!!! VERIFICAR SE COMPORTAMENTO SE //REPETE SEGUIDAS VEZES PRO ÍNDICE, PODE SER UMA FORMA DE GANHO COM UM ALVO MENOR DE ~300, 400 PTOS }
/// <summary> /// Add a single point to the <see cref="PointPairList"/> from values of type double. /// </summary> /// <param name="date">An <see cref="XDate" /> value</param> /// <param name="high">The high value for the day</param> /// <param name="low">The low value for the day</param> /// <param name="open">The opening value for the day</param> /// <param name="close">The closing value for the day</param> /// <param name="vol">The trading volume for the day</param> /// <returns>The zero-based ordinal index where the point was added in the list.</returns> public void Add( double date, double high, double low, double open, double close, double vol ) { StockPt point = new StockPt( date, high, low, open, close, vol ); Add( point ); }