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); }
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); }
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); }
/// <summary> /// The Copy Constructor /// </summary> /// <param name="rhs">The StockPointList from which to copy</param> public StockPointList(StockPointList rhs) { for (var i = 0; i < rhs.Count; i++) { var pt = new StockPt(rhs[i]); Add(pt); } }
/// <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 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); } }
public void GetBarWidth_OrdinalAxisWeeklyValues_3Pixels() { GraphPane myPane = new GraphPane(); myPane.Rect = new RectangleF(0, 0, 640f, 480f); myPane.XAxis.Type = AxisType.DateAsOrdinal; StockPointList spl = CreateStockPointList(60 * 24 * 7); OHLCBarItem myCurve = myPane.AddOHLCBar("trades", spl, Color.Black); AxisChangeAndDraw(myPane); Assert.That(myCurve.Bar.GetBarWidth(myPane, myPane.XAxis, 1.0f), Is.EqualTo(3f)); }
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 Copy Constructor /// </summary> /// <param name="rhs">The StockPointList from which to copy</param> public StockPointList(StockPointList <T> rhs) : this(rhs._dateIndex != null) { _offset = 0; foreach (IStockPt pp in rhs) { Add(pp.Clone()); if (rhs._dateIndex == null) { continue; } _dateIndex.Add(new Tuple <double, int>(pp.Date, Count - 1)); } }
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(); }
public void CreateGraph( ZedGraphControl zgc, StockPointList stlist, StockPointList ema11Plist,StockPointList ema22Plist) { GraphPane myPane = zgc.GraphPane; #region 初始化 myPane.Title.Text = "小日經 30分鐘"; myPane.XAxis.Title.Text = ""; myPane.YAxis.Title.Text = ""; myPane.XAxis.Type = AxisType.Date; myPane.XAxis.Scale.Format = "MM/dd HH:mm"; myPane.XAxis.Scale.FontSpec.Size = 12; myPane.XAxis.Scale.MajorUnit = DateUnit.Minute; myPane.XAxis.Scale.MajorStep = 30; myPane.XAxis.Scale.MinorUnit = DateUnit.Minute; myPane.XAxis.Scale.MinorStep = 10; myPane.YAxis.Scale.MagAuto = false; myPane.CurveList.numBarsToFocus = m_numBarFocused; #endregion #region K 棒繪製 : Once jpnCandle = myPane.AddJapaneseCandleStick("", stlist); jpnCandle.Stick.IsAutoSize = true; // 下跌K jpnCandle.Stick.FallingFill = new Fill(Color.Green); jpnCandle.Stick.FallingColor = Color.Green; jpnCandle.Stick.FallingBorder = new Border(false, Color.Green, 0); // 上漲K jpnCandle.Stick.RisingFill = new Fill(Color.Red); jpnCandle.Stick.Color = Color.Red; jpnCandle.Stick.RisingBorder = new Border(false, Color.Green, 0); #endregion #region 背景 : Once myPane.Chart.Fill = new Fill(Color.Black); // Color.LightGoldenrodYellow, 45F myPane.Fill = new Fill(Color.White); //, Color.FromArgb( 0, 0, 255 ), 45F myPane.XAxis.Type = AxisType.DateAsOrdinal; myPane.Chart.Fill = new Fill(Color.Black); #endregion #region Range 更新 : Once //左右Range XDate Min = new XDate(2015, 2, 25, 0, 0, 0, 0); XDate Max = new XDate(2015, 2, 26, 0, 0, 0, 0); myPane.XAxis.Scale.Min = Min; myPane.XAxis.Scale.Max = Max; //上下Range int min_rr = 16000; int max_rr = 19000; myPane.YAxis.Scale.Min = min_rr; myPane.YAxis.Scale.Max = max_rr; #endregion zgc.AxisChange(); zgc.Invalidate(); }
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 ); }
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; }
//---------------------------------------------------------------------- // Initialize //---------------------------------------------------------------------- public ServMain(string[] args) { //開啟之後特殊模式判別,雙擊開啟不會有任何特殊模式 string strMode = ""; int iMode = 0; try { strMode = args[0]; iMode = int.Parse(strMode); } catch { } switch (iMode) { case 0: quoteProgramMode = QuoteProgramModeOS.QPM_Neutural; Console.WriteLine("當前模式為 Server 一般雙擊開啟"); break; case 1: quoteProgramMode = QuoteProgramModeOS.QPM_AllProduct; Console.WriteLine("當前模式為 Server 取得當前商品列表"); break; case 2: quoteProgramMode = QuoteProgramModeOS.QPM_MarketKLGetter; Console.WriteLine("當前模式為 Server 昨日下午盤K棒資訊擷取"); break; case 3: quoteProgramMode = QuoteProgramModeOS.QPM_MarketAM; Console.WriteLine("當前模式為 Server 小日經上午盤中作單模式"); break; case 4: quoteProgramMode = QuoteProgramModeOS.QPM_AMMarketTickGet; Console.WriteLine("當前模式為 Server 小日經上午盤後Tick資訊擷取,上午倉位紀錄"); break; case 5: quoteProgramMode = QuoteProgramModeOS.QPM_MarketPM; Console.WriteLine("當前模式為 Server 小日經下午盤作單模式"); break; case 6: quoteProgramMode = QuoteProgramModeOS.QPM_AfterMarket; Console.WriteLine("當前模式為 Server 小日經下午盤後Tick資訊擷取,寫入每日歷史紀錄"); break; } InitializeComponent(); fConnect = new FOnConnect(OnConnect); GC.KeepAlive(fConnect); fQuoteUpdate = new FOnGetStockIdx(OnQuoteUpdate); GC.KeepAlive(fQuoteUpdate); fNotifyTicks = new FOnNotifyTicks(OnNotifyTicks); GC.KeepAlive(fNotifyTicks); fOnNotifyBest5 = new FOnGetStockIdx(OnNotifyBest5); GC.KeepAlive(fOnNotifyBest5); fOverseaProducts = new FOnOverseaProducts(OnOverseaProducts); GC.KeepAlive(fOverseaProducts); fNotifyServerTime = new FOnNotifyServerTime(OnNotifyServerTime); GC.KeepAlive(fNotifyServerTime); fNotifyKLineData = new FOnNotifyKLineData(OnNotifyKLineData); GC.KeepAlive(fNotifyKLineData); fOnNotifyTicksGet = new FOnNotifyTicksGet(OnNotifyTicksGet); GC.KeepAlive(fOnNotifyTicksGet); // Order Lib fOrderAsync = new OrderReply.FOnOrderAsyncReport(OnOrderAsyncReport); GC.KeepAlive(fOrderAsync); fOnExecutionReport = new OrderReply.FOnGetExecutionReoprt(OnExecutionReport); GC.KeepAlive(fOnExecutionReport); GC.SuppressFinalize(fOnExecutionReport); // Reply Lib fData = new OrderReply.FOnData(OnReceiveReplyData); GC.KeepAlive(fData); fRConnect = new OrderReply.FOnConnect(OnRConnect); GC.KeepAlive(fConnect); fDisconnect = new OrderReply.FOnConnect(OnRDisconnect); GC.KeepAlive(fDisconnect); fComplete = new OrderReply.FOnComplete(OnComplete); GC.KeepAlive(fComplete); m_Logger = new Logger(); m_Tick = new TICK(); // 繪圖初始 StockPointList _stklist = new StockPointList(); StockPointList _ema11Plist = new StockPointList(); StockPointList _ema22Plist = new StockPointList(); this.AsyncEventHandler += new AsyncEventArgs(_AsyncEventHandler); m_updGraphDelegate = new updGraphDelegate(updGraph); CreateGraph(zg1, _stklist, _ema11Plist, _ema22Plist); // 啟動策略,更新繪圖 dayTradeSt = new JNAutoDayTrade_Strategy(Application.StartupPath,this); //更新繪圖資訊 DrawGraphOnce(dayTradeSt.m_KLdata_30Min, dayTradeSt.EMA11.records, dayTradeSt.EMA22.records); // 取得商品資訊已經搬移到client ,一定是server mode //if( // (quoteProgramMode==QuoteProgramModeOS.QPM_MarketAM) || // (quoteProgramMode == QuoteProgramModeOS.QPM_AMMarketTickGet) || // (quoteProgramMode == QuoteProgramModeOS.QPM_MarketPM) || // (quoteProgramMode == QuoteProgramModeOS.QPM_AfterMarket) // ) bServerMode = true; //今天日期 DateTime todate = DateTime.Now; // Server 不分上下午,只需開收盤時間 g_marketStartTime_AM = new DateTime(todate.Year, todate.Month, todate.Day, 9, 0, 0); DateTime nxDate = todate.AddDays(1); g_marketEndTime_PM = new DateTime(nxDate.Year, nxDate.Month, nxDate.Day, 3, 0, 0); this.timer2.Interval = 100; this.timer2.Start(); }
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 }
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; }
/// <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(); } }
// 讀取完歷史資料一次畫出歷史 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); }
private void Form_StockChart_Load(object sender, EventArgs e) { // Get a reference to the GraphPane instance in the ZedGraphControl GraphPane myPane = zg1.GraphPane; // Set the titles and axis labels myPane.Title.Text = this.Text = title; myPane.XAxis.Title.Text = "Date"; myPane.YAxis.Title.Text = "Close price"; foreach (Model_ShockChart eachModel in stockLineList) { // Make up some data points based on the Sine function StockPointList spl = new StockPointList(); foreach (Tick eachTick in eachModel.stock.priceList) { double x = new XDate(eachTick.Time); double open = ((NumericTick)eachTick).open; double close = ((NumericTick)eachTick).close; double high = ((NumericTick)eachTick).high; double low = ((NumericTick)eachTick).low; double vol = 0.0; try { vol = double.Parse(((NumericTick)eachTick).volume); } catch (Exception ex) { LogHelper.GetLogger(typeof(MainForm)).FullLog(ex.ToString(), "IGNORE"); } spl.Add(new StockPt(x, high, low, open, close, vol)); } // Generate a blue curve with circle symbols, and "Beta" in the legend myPane.AddCurve(eachModel.stock.stockCode + ".HK", spl, eachModel.color, SymbolType.None); } // JapaneseCandleStickItem myCurve = myPane.AddJapaneseCandleStick(baseStock.stockCode + ".HK", spl); // myCurve.Stick.IsAutoSize = true; // myCurve.Stick.Color = Color.Blue; // myCurve = myPane.AddCurve("Beta", list2, Color.Blue, SymbolType.Circle); // Fill the symbols with white // myCurve.Symbol.Fill = new Fill(Color.White); // Associate this curve with the Y2 axis // myCurve.IsY2Axis = true; // Show the x axis grid myPane.XAxis.MajorGrid.IsVisible = true; // Make the Y axis scale red // myPane.YAxis.Scale.FontSpec.FontColor = Color.Red; // myPane.YAxis.Title.FontSpec.FontColor = Color.Red; // turn off the opposite tics so the Y tics don't show up on the Y2 axis myPane.YAxis.MajorTic.IsOpposite = false; myPane.YAxis.MinorTic.IsOpposite = false; // Don't display the Y zero line myPane.YAxis.MajorGrid.IsZeroLine = false; // Align the Y axis labels so they are flush to the axis myPane.YAxis.Scale.Align = AlignP.Inside; // Manually set the axis range // myPane.YAxis.Scale.Min = -30; // myPane.YAxis.Scale.Max = 30; // myPane.XAxis.Scale.Max = baseStock.priceList.Count; // Set the XAxis to date type myPane.XAxis.Type = AxisType.Date; // Enable the Y2 axis display // myPane.Y2Axis.IsVisible = true; // Make the Y2 axis scale blue // myPane.Y2Axis.Scale.FontSpec.FontColor = Color.Blue; // myPane.Y2Axis.Title.FontSpec.FontColor = Color.Blue; // turn off the opposite tics so the Y2 tics don't show up on the Y axis // myPane.Y2Axis.MajorTic.IsOpposite = false; // myPane.Y2Axis.MinorTic.IsOpposite = false; // Display the Y2 axis grid lines // myPane.Y2Axis.MajorGrid.IsVisible = true; // Align the Y2 axis labels so they are flush to the axis // myPane.Y2Axis.Scale.Align = AlignP.Inside; // Fill the axis background with a gradient myPane.Chart.Fill = new Fill(Color.White, Color.LightGray, 45.0f); // Add a text box with instructions // TextObj text = new TextObj( // "Zoom: left mouse & drag\nPan: middle mouse & drag\nContext Menu: right mouse", // 0.05f, 0.95f, CoordType.ChartFraction, AlignH.Left, AlignV.Bottom); // text.FontSpec.StringAlignment = StringAlignment.Near; // myPane.GraphObjList.Add(text); // Enable scrollbars if needed zg1.IsShowHScrollBar = true; zg1.IsShowVScrollBar = true; zg1.IsAutoScrollRange = true; zg1.IsScrollY2 = true; // OPTIONAL: Show tooltips when the mouse hovers over a point zg1.IsShowPointValues = true; zg1.PointValueEvent += new ZedGraphControl.PointValueHandler(MyPointValueHandler); // OPTIONAL: Add a custom context menu item // zg1.ContextMenuBuilder += new ZedGraphControl.ContextMenuBuilderEventHandler(MyContextMenuBuilder); // OPTIONAL: Handle the Zoom Event zg1.ZoomEvent += new ZedGraphControl.ZoomEventHandler(MyZoomEvent); // Size the control to fit the window // SetSize(); // Tell ZedGraph to calculate the axis ranges // Note that you MUST call this after enabling IsAutoScrollRange, since AxisChange() sets // up the proper scrolling parameters zg1.AxisChange(); // Make sure the Graph gets redrawn 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; }