private void SetJapaneseCandles(StockPointList points) { if (points == null) { var candles = zedPrice.GraphPane.CurveList["candle"] as JapaneseCandleStickItem; if (candles != null) { points = (StockPointList)candles.Points; } else { var bars = zedPrice.GraphPane.CurveList["candle"] as OHLCBarItem; if (bars == null) { throw new InvalidOperationException("Other bars doensn't implemented"); } points = (StockPointList)bars.Points; } } RemovePriceChart(); var stick = zedPrice.GraphPane.AddJapaneseCandleStick("candle", points).Stick; stick.FallingFill = new Fill(Color.Red); stick.RisingFill = new Fill(Color.LightGreen); stick.IsAutoSize = true; }
private void LoadPriceChart(DateTime startTime, int period, DateTime?endTime) { var points = new StockPointList(); double lastPrice = 0; double axesPrice = 0; var candles = _controller.GetDailyBitstampCandles(startTime, CurrencyName.BTC, period, endTime); if (candles.Length > 0) { lastPrice = candles.Last(x => x.Close > 0).Close; axesPrice = candles.First(x => x.Open > 0).Open; } foreach (var c in candles) { var xdate = new XDate(c.Time); points.Add(new StockPt(xdate, c.High, c.Low, c.Open, c.Close, 0)); } InitPriceChart(); CreateChart(points); SetPriceAxes(lastPrice - MinPriceOffset, lastPrice + MaxPriceOffset); SetTimeAxis(); DrawPriceLine(lastPrice); UpdateZedControl(); //_timer.Start(); }
public JapaneseCandleStickItem AddCandleStick(string name, double[] seriesHigh, double[] seriesLow, double[] seriesOpen, double[] seriesClose, double[] seriesVolume, Color color, Color stickColor, Color risingColor, Color fallingColor) { 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 = stickColor; myCurve.Color = color; myCurve.Stick.FallingColor = fallingColor; myCurve.Stick.RisingFill.Color = risingColor; return(myCurve); }
public JapaneseCandleStickDemo() : base("Demonstration of the Japanese Candlestick Chart Type", "Japanese CandleStick Demo", DemoType.Bar) { GraphPane myPane = base.GraphPane; 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); // 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); // 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(); }
private void CreateGraph_JapaneseCandleStick(ZedGraphControl z1) { GraphPane myPane = z1.GraphPane; 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 feb 1st XDate xDate = new XDate(2006, 2, 1); double open = 50.0; for (int i = 0; i < 100; 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 ); 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 z1.AxisChange(); z1.Invalidate(); }
public JapaneseCandleStickDemo() : base("Demonstration of the Japanese Candlestick Chart Type", "Japanese CandleStick Demo", DemoType.Bar) { GraphPane myPane = base.GraphPane; myPane.Title.Text = "UER/USD(欧/日)"; myPane.XAxis.Title.Text = "交易日期"; myPane.YAxis.Title.Text = "价格, $¥"; StockPointList spl = new StockPointList(); Random rand = new Random(); // First day is jan 1st XDate xDate = new XDate(2002, 12, 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() * 3.0; StockPt pt = new StockPt(x, hi, low, open, close, 100); spl.Add(pt); open = close; xDate.AddHours(1); if (XDate.XLDateToDayOfWeek(xDate.XLDate) == 6) { xDate.AddDays(1.0); } } JapaneseCandleStickItem myCurve = myPane.AddJapaneseCandleStick("蜡烛线", spl); myCurve.Stick.IsAutoSize = true; myCurve.Stick.Color = Color.Blue; myPane.XAxis.Type = AxisType.DateAsOrdinal; myPane.XAxis.Scale.Min = new XDate(2006, 1, 1); myPane.Chart.Fill = new Fill(Color.Black, Color.LightGoldenrodYellow, 45.0f); myPane.Fill = new Fill(Color.White, Color.FromArgb(220, 220, 255), 45.0f); //myPane.Chart.Fill = new Fill(Color.Black); //myPane.Fill = new Fill(Color.Black); base.ZedGraphControl.AxisChange(); }
public OHLCBarDemo() : base("Demonstration of the OHLCBar Chart Type", "OHLCBar Demo", DemoType.Bar) { GraphPane myPane = base.GraphPane; myPane.Title.Text = "Open-High-Low-Close Bar Chart Demo"; myPane.XAxis.Title.Text = "Trading Date"; myPane.YAxis.Title.Text = "Share Price, $US"; var spl = new StockPointList <StockPt>(); Random rand = new Random(); // First day is jan 1st XDate xDate = new XDate(2006, 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); spl.Add(x, open, hi, low, close, 50000, 50000); 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); myCurve.Bar.IsAutoSize = true; myCurve.Bar.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); base.ZedGraphControl.AxisChange(); }
private void CreateChart(StockPointList points = null) { switch (Chart) { case ChartType.JapaneseCandle: { SetJapaneseCandles(points); break; } case ChartType.Bars: { SetOHLCBars(points); break; } } }
public void LoadGraph(CurrencyPair currencyPair, IList <IMarketChartData> chartData) { GraphPane myPane = zgc1.GraphPane; myPane.Title.Text = "Candlestick Chart " + currencyPair.ToString(); myPane.XAxis.Title.Text = "Date"; myPane.YAxis.Title.Text = "Price " + currencyPair.BaseCurrency; StockPointList spl = new StockPointList(); Random rand = new Random(); foreach (var data in chartData) { var xDate = new XDate(data.Time.Year, data.Time.Month, data.Time.Day, data.Time.Hour, data.Time.Minute, data.Time.Second); double x = xDate; double close = data.Close; double hi = data.High; double low = data.Low; double open = data.Open; StockPt pt = new StockPt(x, hi, low, open, close, data.VolumeBase); spl.Add(pt); } JapaneseCandleStickItem myCurve = myPane.AddJapaneseCandleStick("Price", spl); myCurve.Stick.IsAutoSize = true; myCurve.Stick.Color = System.Drawing.Color.Red; // Use DateAsOrdinal to skip weekend gaps myPane.XAxis.Type = AxisType.Date; // pretty it up a little myPane.Chart.Fill = new Fill(System.Drawing.Color.WhiteSmoke, System.Drawing.Color.Gray, 45.0f); myPane.Fill = new Fill(System.Drawing.Color.WhiteSmoke, System.Drawing.Color.DarkOrange); zgc1.AxisChange(); zgc1.Refresh(); zgc1.Update(); zgc1.IsShowCursorValues = true; this.UpdateLayout(); IsGraphLoaded = true; }
public void addBars() { var spl = new StockPointList(); Objects.each(bars.toArray(), bar => spl.Add(stockPoint(bar))); var myCurve = AddJapaneseCandleStick(symbol.name, spl); myCurve.Stick.IsAutoSize = true; myCurve.Stick.Color = Color.Black; barsOnPlot = true; XAxis.Scale.IsVisible = true; var graphable = new BarSpudGraphable(bars); graphables.Add(graphable); var needsNewBar = false; bars.pushedDown += () => { needsNewBar = true; QControl.runOnGuiThread(dispatchTo, () => parentTyped.dataTable().addAtStart(parentTyped.dataTable().NewRow()) ); }; bars.valueSet += bar => QControl.runOnGuiThread(dispatchTo, () => { if (needsNewBar) { spl.Add(stockPoint(bar)); dateParent.setDate(bar.time, spl.Count); } else { spl[spl.Count - 1] = stockPoint(bar); } BarSpudGraph.addBarTo(Objects.first(parentTyped.dataTable().Rows), bar); needsNewBar = false; parentTyped.Invalidate(); }); }
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 void SetOHLCBars(StockPointList points) { if (points == null) { var bars = zedPrice.GraphPane.CurveList["candle"] as OHLCBarItem; if (bars != null) { points = (StockPointList)bars.Points; } else { var candles = zedPrice.GraphPane.CurveList["candle"] as JapaneseCandleStickItem; if (candles == null) { throw new InvalidOperationException("Other bars doensn't implemented"); } points = (StockPointList)candles.Points; } } RemovePriceChart(); // // https://csharp.hotexamples.com/ru/examples/ZedGraph/GraphPane/AddOHLCBar/php-graphpane-addohlcbar-method-examples.html // var myFill = new Fill(new Color[] { Color.Red, Color.Black }) { RangeMin = 1, RangeMax = 2, Type = FillType.GradientByColorValue, SecondaryValueGradientColor = Color.Empty }; var items = zedPrice.GraphPane.AddOHLCBar("candle", points, Color.Empty); items.Bar.GradientFill = myFill; items.Bar.IsAutoSize = true; items.Bar.Width = 2; }
/// <summary> /// 取出1分钟数据的时间,开收盘价,高低价,成交量等信息输入该图 /// </summary> private void Form_Load(object sender, EventArgs e) { //画一张大图,包含价格K线和成交量 MasterPane myPaneMaster = zedG.MasterPane; myPaneMaster.Title.Text = secCode; myPaneMaster.Title.FontSpec.FontColor = Color.Black; //PaneMaster里面画一张价格的小图 GraphPane panePrice = new GraphPane(new Rectangle(10, 10, 10, 10), "Mes", " t ( h )", "Rate"); myPaneMaster.PaneList[0] = (panePrice); //PaneMaster里面画一张成交量的小图 GraphPane paneVolume = new GraphPane(new Rectangle(10, 10, 10, 10), "Mes", " t ( h )", "Rate"); myPaneMaster.PaneList.Add(paneVolume); //蜡烛线例子 //设置名称和坐标轴 panePrice.Title.Text = "K线图"; panePrice.XAxis.Title.Text = "日期"; panePrice.XAxis.Title.FontSpec.FontColor = Color.Black; panePrice.YAxis.Title.Text = "价格"; panePrice.YAxis.Title.FontSpec.FontColor = Color.Black; //spl装载时间,价格数据 StockPointList spl = new StockPointList(); Random rand = new Random(); //将系统时间转化为xDate时间 XDate xStart = XDate.DateTimeToXLDate(startTime); XDate xEnd = XDate.DateTimeToXLDate(endTime); //取Sec的分钟数据,存储于data中 List <DateTime> tradeDays = DateUtils.GetTradeDays(startTime, endTime); //数据准备,取minute数据,然后再将数据进行转换为各个频率 Dictionary <string, List <KLine> > data = new Dictionary <string, List <KLine> >(); foreach (var tempDay in tradeDays) { var stockData = Platforms.container.Resolve <StockMinuteRepository>().fetchFromLocalCsvOrWindAndSave(secCode, tempDay); if (!data.ContainsKey(secCode)) { data.Add(secCode, stockData.Cast <KLine>().ToList()); } else { data[secCode].AddRange(stockData.Cast <KLine>().ToList()); } } //定义变量存储分钟数据 Dictionary <string, List <KLine> > minuteData = new Dictionary <string, List <KLine> >(); foreach (var variety in data) { minuteData.Add(variety.Key, data[variety.Key]); } //定义成交量 double[] volume = new double[minuteData[secCode].Count]; //根据频率选择累加的时间 switch (frequency) { //取tick数据 case 0: log.Info("暂时没有tick数据"); break; //1min K线 case 1: for (int i = 0; i < minuteData[secCode].Count; i++) { double timePoint = i; double open = minuteData[secCode][i].open; double close = minuteData[secCode][i].close; double high = minuteData[secCode][i].high; double low = minuteData[secCode][i].low; volume[i] = minuteData[secCode][i].volume; StockPt pt = new StockPt(timePoint, high, low, open, close, volume[i]); spl.Add(pt); // 时间加1分钟 xStart.AddMinutes(1.0); // but skip the weekends if (XDate.XLDateToDayOfWeek(xStart.XLDate) == 6) { xStart.AddDays(2.0); } } break; //显示5min K线 case 2: Dictionary <string, List <KLine> > minuteData5Min = new Dictionary <string, List <KLine> >(); foreach (var variety in data) { List <KLine> data5K = new List <KLine>(); data5K = MinuteFrequencyTransferUtils.MinuteToNPeriods(minuteData[variety.Key], "Minutely", 5); minuteData5Min.Add(variety.Key, data5K); } for (int i = 0; i < minuteData5Min[secCode].Count; i++) { double timePoint = i; double open = minuteData5Min[secCode][i].open; double close = minuteData5Min[secCode][i].close; double high = minuteData5Min[secCode][i].high; double low = minuteData5Min[secCode][i].low; volume[i] = minuteData[secCode][i].volume; StockPt pt = new StockPt(timePoint, high, low, open, close, volume[i]); spl.Add(pt); // 时间加5分钟 xStart.AddMinutes(5.0); // but skip the weekends if (XDate.XLDateToDayOfWeek(xStart.XLDate) == 6) { xStart.AddDays(2.0); } } break; //显示15min K线 case 3: Dictionary <string, List <KLine> > minuteData15Min = new Dictionary <string, List <KLine> >(); foreach (var variety in data) { List <KLine> data15K = new List <KLine>(); data15K = MinuteFrequencyTransferUtils.MinuteToNPeriods(minuteData[variety.Key], "Minutely", 15); minuteData15Min.Add(variety.Key, data15K); } for (int i = 0; i < minuteData15Min[secCode].Count; i++) { double timePoint = i; double open = minuteData15Min[secCode][i].open; double close = minuteData15Min[secCode][i].close; double high = minuteData15Min[secCode][i].high; double low = minuteData15Min[secCode][i].low; volume[i] = minuteData[secCode][i].volume; StockPt pt = new StockPt(timePoint, high, low, open, close, volume[i]); spl.Add(pt); // 时间加15分钟 xStart.AddMinutes(15.0); // but skip the weekends if (XDate.XLDateToDayOfWeek(xStart.XLDate) == 6) { xStart.AddDays(2.0); } } break; //显示30min K线 case 4: Dictionary <string, List <KLine> > minuteData30Min = new Dictionary <string, List <KLine> >(); foreach (var variety in data) { List <KLine> data30K = new List <KLine>(); data30K = MinuteFrequencyTransferUtils.MinuteToNPeriods(minuteData[variety.Key], "Minutely", 30); minuteData30Min.Add(variety.Key, data30K); } for (int i = 0; i < minuteData30Min[secCode].Count; i++) { double timePoint = i; double open = minuteData30Min[secCode][i].open; double close = minuteData30Min[secCode][i].close; double high = minuteData30Min[secCode][i].high; double low = minuteData30Min[secCode][i].low; volume[i] = minuteData[secCode][i].volume; StockPt pt = new StockPt(timePoint, high, low, open, close, volume[i]); spl.Add(pt); // 时间加30分钟 xStart.AddMinutes(30.0); // but skip the weekends if (XDate.XLDateToDayOfWeek(xStart.XLDate) == 6) { xStart.AddDays(2.0); } } break; //显示60min K线 case 5: Dictionary <string, List <KLine> > minuteData60Min = new Dictionary <string, List <KLine> >(); foreach (var variety in data) { List <KLine> data60K = new List <KLine>(); data60K = MinuteFrequencyTransferUtils.MinuteToNPeriods(minuteData[variety.Key], "Minutely", 60); minuteData60Min.Add(variety.Key, data60K); } for (int i = 0; i < minuteData60Min[secCode].Count; i++) { double timePoint = i; double open = minuteData60Min[secCode][i].open; double close = minuteData60Min[secCode][i].close; double high = minuteData60Min[secCode][i].high; double low = minuteData60Min[secCode][i].low; volume[i] = minuteData[secCode][i].volume; StockPt pt = new StockPt(timePoint, high, low, open, close, volume[i]); spl.Add(pt); // 时间加60分钟 xStart.AddMinutes(60.0); // but skip the weekends if (XDate.XLDateToDayOfWeek(xStart.XLDate) == 6) { xStart.AddDays(2.0); } } break; //显示日K线 case 6: Dictionary <string, List <KLine> > minuteDataDaily = new Dictionary <string, List <KLine> >(); foreach (var variety in data) { List <KLine> dataDaily = new List <KLine>(); dataDaily = MinuteFrequencyTransferUtils.MinuteToNPeriods(minuteData[variety.Key], "Minutely", 240); minuteDataDaily.Add(variety.Key, dataDaily); } for (int i = 0; i < minuteDataDaily[secCode].Count; i++) { double timePoint = i; double open = minuteDataDaily[secCode][i].open; double close = minuteDataDaily[secCode][i].close; double high = minuteDataDaily[secCode][i].high; double low = minuteDataDaily[secCode][i].low; volume[i] = minuteData[secCode][i].volume; StockPt pt = new StockPt(timePoint, high, low, open, close, volume[i]); spl.Add(pt); // 时间加1天 xStart.AddDays(1.0); // but skip the weekends if (XDate.XLDateToDayOfWeek(xStart.XLDate) == 6) { xStart.AddDays(2.0); } } break; } //添加栅格线 //myPane.XAxis.MajorGrid.IsVisible = true; //myPane.YAxis.MajorGrid.IsVisible = true; //myPane.XAxis.MajorGrid.Color = Color.LightGray; //myPane.YAxis.MajorGrid.Color = Color.LightGray; //myPane.YAxis.MajorGrid.DashOff = 0; //myPane.XAxis.MajorGrid.DashOff = 0; panePrice.XAxis.Type = AxisType.Date; panePrice.XAxis.Scale.Format = "MM-dd"; //myPane.XAxis.Scale.FontSpec.Angle = 45;//X轴文字方向,0-90度 //开始Y轴坐标设置 ////设置Y轴坐标的范围 //myPane.YAxis.Scale.Max = Math.Round(maxhi * 1.2, 2);//Math.Ceiling(maxhi); //myPane.YAxis.Scale.Min = Math.Round(minlow * 0.8, 2); //Y轴最大刻度,注意minStep只会显示刻度线不会显示刻度值,minStep为纵坐标步长 panePrice.YAxis.Scale.MajorStep = 0.01; //myPane.XAxis.Scale.FontSpec.FontColor = Color.Black; //myPane.YAxis.Scale.FontSpec.FontColor = Color.Black; panePrice.XAxis.Type = AxisType.DateAsOrdinal; //myPane.Legend.FontSpec.Size = 18f; //myPane.Legend.Position = LegendPos.InsideTopRight; //myPane.Legend.Location = new Location(0.5f, 0.6f, CoordType.PaneFraction, // AlignH.Right, AlignV.Top); JapaneseCandleStickItem myCurve = panePrice.AddJapaneseCandleStick(secCode, spl); myCurve.Stick.IsAutoSize = true; //myCurve.Stick.Color = Color.Blue; myCurve.Stick.FallingFill = new Fill(Color.Green); //下跌颜色 myCurve.Stick.RisingFill = new Fill(Color.Red); //上扬颜色 // pretty it up a little //myPane.Chart.Fill = new Fill(Color.LightBlue, Color.LightGoldenrodYellow, 135.0f); //myPane.Fill = new Fill(Color.Orange, Color.FromArgb(220, 220, 255), 45.0f); Color c1 = ColorTranslator.FromHtml("#ffffff"); Color c2 = ColorTranslator.FromHtml("#ffd693"); panePrice.Chart.Fill = new Fill(c1); //图形区域颜色 panePrice.Fill = new Fill(c2); //整体颜色 //成交量线例子 // Set the Titles paneVolume.Title.Text = "成交量"; paneVolume.XAxis.Title.Text = "Time"; paneVolume.YAxis.Title.Text = "Volume Num"; // Make up some random data points //string[] labels = { "Panther", "Lion", "Cheetah","Cougar", "Tiger", "Leopard" }; //double[] y1 = { 100, 115, 75, 22, 98, 40, -100, -20 }; //double[] y2 = { 90, 100, 95, 35, 80, 35 }; //double[] y3 = { 80, 110, 65, 15, 54, 67 }; //double[] y4 = { 120, 125, 100, 40, 105, 75 }; // Generate a red bar with "Curve 1" in the legend BarItem myBar = paneVolume.AddBar(null, null, volume, Color.Red); //myBar.Bar.Fill = new Fill(Color.Red); // Generate a blue bar with "Curve 2" in the legend //myBar = paneVolume.AddBar("Curve 2", null, y2, Color.Blue); //myBar.Bar.Fill = new Fill(Color.Blue, Color.White, Color.Blue); //设置bar宽度 paneVolume.BarSettings.ClusterScaleWidth = 0.5; log.Info(paneVolume.BarSettings.GetClusterWidth()); paneVolume.BarSettings.Type = BarType.Cluster; // Generate a green bar with "Curve 3" in the legend //myBar = myPane.AddBar("Curve 3", null, y3, Color.Green); //myBar.Bar.Fill = new Fill(Color.Green, Color.White, // Color.Green); // Generate a black line with "Curve 4" in the legend //LineItem myCurve = myPane.AddCurve("Curve 4", //null, y4, Color.Black, SymbolType.Circle); //myCurve.Line.Fill = new Fill(Color.White, //Color.LightSkyBlue, -45F); // Fix up the curve attributes a little //myCurve.Symbol.Size = 8.0F; //myCurve.Symbol.Fill = new Fill(Color.White); //myCurve.Line.Width = 2.0F; // Draw the X tics between the labels instead of // at the labels paneVolume.XAxis.MajorTic.IsBetweenLabels = true; // Set the XAxis labels //myPane.XAxis.Scale.TextLabels = labels; // Set the XAxis to Text type paneVolume.XAxis.Type = AxisType.Text; // Fill the Axis and Pane backgrounds paneVolume.Chart.Fill = new Fill(Color.White, Color.FromArgb(255, 255, 166), 90F); paneVolume.Fill = new Fill(Color.FromArgb(250, 250, 255)); using (Graphics g = CreateGraphics()) myPaneMaster.SetLayout(g, 2, 0); zedG.AxisChange(); }
public OHLCBarRealTimeDemo() : base("Demonstration of the OHLCBar Chart Type", "OHLCBar Real-Time Demo", DemoType.Financial) { m_Timer = new Timer { Interval = 500, Enabled = false, SynchronizingObject = ZedGraphControl }; m_Data = new StockPointList <StockPt>(true); m_ZigZagData = new PointPairList(); m_FilteredData = new DynFilteredPointList <StockPt>(new[] { 0.0 }, new[] { 0.0 }); m_EMAData = new PointPairList(); m_Rand = new Random(); var now = fillSampleData(); //int hi, lo; //var output = (IPointListEdit)m_ZigZagData; //Indicator.ZigZag(m_Data, 0, m_Data.Count - 1, m_ZigZagPercent, out lo, out hi, ref output); //Indicator.ZigZag(m_Data, m_ZigZagData, 0, m_Data.Count, m_ZigZagPercent, true, true); m_Pane = base.GraphPane; ZedGraphControl.HPanOverflow = 0.2; //------------------------------------------------------------------------ // Setup the pane and X/Y axis //------------------------------------------------------------------------ m_Pane.Title.Text = "OHLC Real-Time Bar Chart Demo"; //m_Pane.XAxis.Title.Text = "Trading Date"; //m_Pane.Y2Axis.Title.Text = "Share Price, $US"; m_Pane.Title.IsVisible = false; m_Pane.Legend.IsVisible = false; m_Pane.Margin.Top = 1; m_Pane.Margin.Left = 1; m_Pane.Margin.Right = 0; m_Pane.Margin.Bottom = 1; m_Pane.Legend.Gap = 0; m_Pane.MouseWheelAction = MouseWheelActions.Zoom | MouseWheelActions.PanH; m_Pane.IsPenWidthScaled = true; m_Pane.IsBoundedRanges = true; m_Pane.IsIgnoreMissing = true; m_Pane.IsAlignGrids = true; // Customize X axis m_Pane.XAxis.Title.IsVisible = false; m_Pane.XAxis.AxisGap = 5; m_Pane.XAxis.Scale.LabelGap = 0.2f; m_Pane.XAxis.MajorGrid.IsVisible = true; m_Pane.XAxis.MajorGrid.Color = Color.DarkGray; m_Pane.XAxis.MajorGrid.DashOff = 7; m_Pane.XAxis.MajorGrid.DashOn = 1; m_Pane.XAxis.MajorTic.Size = 3; m_Pane.XAxis.MinorTic.Size = 1; m_Pane.XAxis.Type = AxisType.DateAsOrdinal; //m_Pane.XAxis.Scale.MajorUnit = DateUnit.Minute; //m_Pane.XAxis.Scale.MinorUnit = DateUnit.Second; m_Pane.XAxis.Scale.Format = "yyyy-MM-dd\nHH:mm:ss"; m_Pane.XAxis.Scale.FontSpec.Size = 9; //m_Pane.XAxis.Scale.MajorStep = 2; //m_Pane.XAxis.Scale.MinorStep = 30; m_Pane.XAxis.MinZoom = 10; m_Pane.XAxis.Scale.MaxAuto = true; m_Pane.XAxis.Scale.MinAuto = true; // m_Pane.XAxis.Scale.MajorStep = new XDate(0, 0, 0, 0, 2, 0).XLDate; // m_Pane.XAxis.Scale.MinorStep = new XDate(0, 0, 0, 0, 0,15).XLDate; // // m_Pane.XAxis.Scale.MajorStep = 120.0f / XDate.SecondsPerDay; // 120s // m_Pane.XAxis.Scale.MinorStep = 15.0f / XDate.SecondsPerDay; // 15s // m_Pane.XAxis.Scale.BaseTic = new XDate(0, 0, 0, 0, 0, 5); // m_Pane.XAxis.Scale.FontSpec.ScaleFactor = 1.0f; // m_Pane.XAxis.Scale.MinAuto = true; //m_Pane.XAxis.Scale.MaxAuto = true; // m_Pane.XAxis.Scale.MinGrace = 50; //m_Pane.XAxis.Scale.MaxGrace = 50; m_Pane.XAxis.Scale.IsSkipFirstLabel = true; m_Pane.XAxis.Scale.IsSkipLastLabel = false; //m_Pane.XAxis.Scale.Max = new XDate(now); //m_Pane.XAxis.Scale.Min = new XDate(now) - 2*60; // m_Pane.XAxis.Scale.AlignH = AlignH.Center; // m_Pane.XAxis.Scale.Align = AlignP.Inside; m_Pane.XAxis.MajorTic.IsBetweenLabels = true; m_Pane.XAxis.MinorTic.Size = 2.5f; m_Pane.XAxis.MinorTic.IsInside = false; m_Pane.XAxis.MajorTic.IsInside = false; m_Pane.XAxis.MinorTic.IsOutside = true; m_Pane.XAxis.MajorGrid.IsVisible = true; m_Pane.XAxis.MajorGrid.DashOff = 10; m_Pane.XAxis.MajorGrid.DashOn = 1; m_Pane.XAxis.MajorGrid.Color = Color.SlateGray; m_Pane.XAxis.MinorGrid.IsVisible = false; // m_Pane.XAxis.Scale.MajorStep = new XDate(now - TimeSpan.FromSeconds(15)); // Disable left-side Y axis m_Pane.YAxis.IsVisible = false; m_Pane.YAxis.Title.IsVisible = false; m_Pane.YAxis.MinSpace = 0; // Enable the Y2 axis display m_Pane.Y2Axis.IsVisible = true; m_Pane.Y2Axis.Title.IsVisible = false; m_Pane.Y2Axis.MinSpace = 50; m_Pane.Y2Axis.AxisGap = 5; m_Pane.Y2Axis.Scale.LabelGap = 0; m_Pane.Y2Axis.MajorGrid.IsVisible = true; m_Pane.Y2Axis.MajorGrid.DashOff = 10; m_Pane.Y2Axis.MajorGrid.DashOn = 1; m_Pane.Y2Axis.MajorGrid.Color = Color.SlateGray; m_Pane.Y2Axis.MinorGrid.PenWidth = 1; m_Pane.Y2Axis.MinorGrid.IsVisible = false; /* * m_Pane.Y2Axis.MinorGrid.DashOff = 15; * m_Pane.Y2Axis.MinorGrid.DashOn = 1; * m_Pane.Y2Axis.MinorGrid.Color = Color.DarkGray; * m_Pane.Y2Axis.MinorGrid.PenWidth = 1; */ m_Pane.Y2Axis.MajorTic.Size = 3; m_Pane.Y2Axis.MinorTic.Size = 1; m_Pane.Y2Axis.MinZoom = 5.0; //m_Pane.Y2Axis.Scale.AlignH = AlignH.Right; m_Pane.Y2Axis.Scale.Align = AlignP.Outside; m_Pane.Y2Axis.Scale.MinAuto = true; m_Pane.Y2Axis.Scale.MaxAuto = true; m_Pane.Y2Axis.Scale.Format = "0.00000"; m_Pane.Y2Axis.MinorTic.IsInside = false; m_Pane.Y2Axis.MajorTic.IsInside = false; m_Pane.Y2Axis.MinorTic.IsOutside = true; m_Pane.Y2Axis.MajorTic.IsOutside = true; m_Pane.Y2Axis.Scale.FontSpec.Size = 9; // m_Pane.Y2Axis.Scale.FontSpec.ScaleFactor = 1.0f; m_Pane.Chart.Fill = new Fill(Color.Black); m_Pane.Fill = new Fill(Color.SlateGray, Color.FromArgb(220, 220, 255), 45.0f); m_Pane.IsAlignGrids = true; m_Pane.IsFontsScaled = false; //------------------------------------------------------------------------ // Add a line to track last close //------------------------------------------------------------------------ m_Line = m_Pane.Y2Axis.AddHLine(Color.Red, "close-price"); m_Line.Style = DashStyle.Custom; m_Line.DashOn = 1; m_Line.DashOff = 3; m_Line.Width = 1; ZedGraphControl.AxisChange(); m_Timer.Elapsed += (o, args) => { calc(DateTime.Now, true); //base.ZedGraphControl.AxisChange(); base.ZedGraphControl.Invalidate(); }; //------------------------------------------------------------------------ // ZigZag indicator //------------------------------------------------------------------------ var zigzag = m_Pane.AddCurve($"ZigZag({m_ZigZagPercent:0.0})", m_ZigZagData, Color.Red, SymbolType.None); zigzag.IsOverrideOrdinal = false; zigzag.Line.IsSmooth = false; //curve.Line.SmoothTension = 0.5F; zigzag.IsY2Axis = true; // Associate this curve with the Y2 axis zigzag.YAxisIndex = 0; // Associate this curve with the first Y2 axis zigzag.IsSelectable = true; zigzag.IsSelected = false; //------------------------------------------------------------------------ // Cardinal spline smoothing function //------------------------------------------------------------------------ LineItem curve = m_Pane.AddCurve($"EMA({EMA_ALPHA:0.0})", m_EMAData, Color.LightCoral, SymbolType.None); curve.Line.IsSmooth = true; curve.Line.SmoothTension = 0.5F; curve.IsY2Axis = true; // Associate this curve with the Y2 axis curve.YAxisIndex = 0; // Associate this curve with the first Y2 axis curve.IsSelectable = true; curve.IsSelected = false; //------------------------------------------------------------------------ // Add OHCL time series //------------------------------------------------------------------------ //OHLCBarItem myCurve = m_Pane.AddOHLCBar("trades", m_Data, Color.Black); // myCurve.Bar.Width = 2; // myCurve.Bar.IsAutoSize = true; // myCurve.Bar.Color = Color.DodgerBlue; var myCurve = m_Pane.AddJapaneseCandleStick("EUR/USD", m_Data, zOrder: 0); myCurve.Bar.FallingColor = Color.FromArgb(255, 0, 255, 0); myCurve.Bar.Color = Color.FromArgb(255, 0, 255, 0); myCurve.Bar.RisingFill.Color = Color.Black; myCurve.Bar.FallingFill.Color = Color.White; myCurve.Bar.FallingBorder.Color = Color.FromArgb(255, 0, 255, 0); myCurve.Bar.RisingBorder.Color = Color.FromArgb(255, 0, 255, 0); myCurve.IsY2Axis = true; // Associate this curve with the Y2 axis myCurve.YAxisIndex = 0; // Associate this curve with the first Y2 axis (this is actually default) myCurve.IsSelectable = true; myCurve.IsSelected = false; myCurve.BeforeDrawEvent += (c, item, index) => { ((JapaneseCandleStick)item).HighDotColor = index % 3 == 0 ? ((JapaneseCandleStickItem)c).HighDotColor : Color.Empty; ((JapaneseCandleStick)item).LowDotColor = index % 5 == 0 ? ((JapaneseCandleStickItem)c).LowDotColor : Color.Empty; }; /* * m_XHair = new LineObj(Color.SlateGray, 0, 0, m_Pane.Rect.Width, 0) * { * IsClippedToChartRect = true, * ZOrder = ZOrder.A_InFront, * IsVisible = false * }; * m_YHair = new LineObj(Color.SlateGray, 0, 0, 0, m_Pane.Rect.Height) * { * IsClippedToChartRect = true, * ZOrder = ZOrder.A_InFront, * IsVisible = false * }; * * m_XHair.Line.Style = DashStyle.Dash; * m_XHair.Location.CoordinateFrame = CoordType.AxisXYScale; * m_XHair.Location.AlignH = AlignH.Left; * m_XHair.Location.AlignV = AlignV.Top; * m_YHair.Line.Style = DashStyle.Dash; * m_YHair.Location.CoordinateFrame = CoordType.AxisXYScale; * m_YHair.Location.AlignH = AlignH.Left; * m_YHair.Location.AlignV = AlignV.Top; * * m_Pane.GraphObjList.Add(m_XHair); * m_Pane.GraphObjList.Add(m_YHair); * * //ZedGraphControl.GraphPane.XAxis.Scale.Max = m_Pane.XAxis.Scale.Max; * //ZedGraphControl.GraphPane.XAxis.Scale.Min = m_Pane.XAxis.Scale.Min; * * ZedGraphControl.MouseMove += ZedGraphControl_MouseMove; * ZedGraphControl.MouseLeave += ZedGraphControl_MouseLeave; */ m_Timer.Enabled = false; }
private void dataGridView1_SelectionChanged(object sender, EventArgs xx) { if (dataGridView1.SelectedRows.Count <= 0) { return; } var row = dataGridView1.SelectedRows[0]; string pairName = (string)row.Cells[0].Value; var pair = _pairs.FirstOrDefault(e => e.Symbol.NiceName == pairName); if (pair != null) { var candleStickPoints = new StockPointList(); var candles = pair.Symbol.Candles; var lastCandle = candles.Count - 1; for (int i = lastCandle; i >= 0; i--) { var candle = candles[i]; double x = new XDate(candles[lastCandle].OpenTime); StockPt pt = new StockPt(new XDate(candle.OpenTime), (double)candle.High, (double)candle.Low, (double)candle.Open, (double)candle.Close, 100000); candleStickPoints.Add(pt); } var masterPane = zedGraphControl1.MasterPane; // while (masterPane.PaneList.Count < 2) masterPane.PaneList.Add(new GraphPane()); var mainPane = masterPane.PaneList[0]; // var mbfxPane = masterPane.PaneList[1]; //mbfxPane. mainPane.Title.Text = pair.Symbol.NiceName + " " + pair.Symbol.NiceTimeFrame; mainPane.CurveList.Clear(); var candleSticks = mainPane.AddJapaneseCandleStick("candles", candleStickPoints); candleSticks.Stick.FallingFill = new Fill(Color.Red); candleSticks.Stick.RisingFill = new Fill(Color.Blue); mainPane.XAxis.Type = AxisType.DateAsOrdinal; var trendLine = new TrendLine(); trendLine.Refresh(pair.Symbol); var zigZag = new ZigZag(); zigZag.Refresh(pair.Symbol); var ma15Points = new PointPairList(); var trendPoints = new PointPairList(); var zigzagBuyPoints = new PointPairList(); var zigzagSellPoints = new PointPairList(); for (int i = lastCandle; i >= 0; i--) { var candle = candles[i]; ma15Points.Add(new XDate(candle.OpenTime), (double)MovingAverage.Get(pair.Symbol, i, 15, MaMethod.Sma, AppliedPrice.Close)); trendPoints.Add(new XDate(candle.OpenTime), (double)trendLine.GetValue(i) ); var arrow = zigZag.GetArrow(i); if (arrow == ArrowType.Buy) { zigzagBuyPoints.Add(new XDate(candle.OpenTime), (double)candle.Low); } else { zigzagBuyPoints.Add(new XDate(candle.OpenTime), (double)0); } if (arrow == ArrowType.Sell) { zigzagSellPoints.Add(new XDate(candle.OpenTime), (double)candle.High); } else { zigzagSellPoints.Add(new XDate(candle.OpenTime), (double)0); } } var ma15Curve = mainPane.AddCurve("MA15", ma15Points, Color.DarkGray, SymbolType.None); var trendCurve = mainPane.AddCurve("Trend", trendPoints, Color.Green, SymbolType.None); var zigZagCurveBuy = mainPane.AddCurve("", zigzagBuyPoints, Color.Green, SymbolType.Triangle); var zigZagCurveSell = mainPane.AddCurve("", zigzagSellPoints, Color.Red, SymbolType.TriangleDown); zigZagCurveBuy.Line.StepType = StepType.ForwardSegment; zigZagCurveSell.Line.StepType = StepType.ForwardSegment; // pretty it up a little mainPane.Chart.Fill = new Fill(Color.LightGray, Color.LightGray, 45.0f); mainPane.Fill = new Fill(Color.LightGray, Color.LightGray, 45.0f); // Tell ZedGraph to calculate the axis ranges zedGraphControl1.AxisChange(); zedGraphControl1.Invalidate(); if (_currentPair != pairName) { _currentPair = pairName; zedGraphControl1.RestoreScale(mainPane); } } }
public void UpdateHistoryGraphCurves() { GraphPane pane = historyGraph.GraphPane; // get rows DataRow[] rows = hs.HistoryTable.Select("", "Date ASC"); if (rows.Length <= 0) { return; } // start date DateTime d0 = (DateTime)(rows[0]["Date"]); DateTime d1 = d0; history_x = new double[rows.Length]; history_y = new double[rows.Length]; // build points list StockPointList spl = new StockPointList(); for (int i = 0; i < rows.Length; i++) { double close_adj = (double)(rows[i]["AdjClose"]); double close = (double)(rows[i]["Close"]); double factor = close_adj / close; double open = (double)(rows[i]["Open"]) * factor; double low = (double)(rows[i]["Low"]) * factor; double high = (double)(rows[i]["High"]) * factor; double volume = (double)(rows[i]["Volume"]); d1 = (DateTime)(rows[i]["Date"]); XDate date = new XDate(d1.Year, d1.Month, d1.Day); StockPt pt = new StockPt(date.XLDate, high, low, open, close_adj, volume); spl.Add(pt); history_x[i] = date.XLDate; history_y[i] = close_adj; } // period (maximum 6-months) if (d0 < d1.AddMonths(-6)) { d0 = d1.AddMonths(-6); } history_xaxis_prd = (5.0 / 7.0) * ((new XDate(d1.Year, d1.Month, d1.Day)).XLDate - (new XDate(d0.Year, d0.Month, d0.Day)).XLDate); // x-axis pane.XAxis.Type = AxisType.DateAsOrdinal; pane.XAxis.Scale.FormatAuto = false; pane.XAxis.Scale.Format = "dd-MMM-yy"; pane.XAxis.Scale.MinAuto = false; pane.XAxis.Scale.MaxAuto = false; pane.XAxis.Scale.Min = rows.Length - history_xaxis_prd; pane.XAxis.Scale.Max = rows.Length; pane.XAxis.Scale.MinorStepAuto = true; pane.XAxis.Scale.MajorStepAuto = true; // y-axis pane.YAxis.Scale.MinAuto = true; pane.YAxis.Scale.MinorStepAuto = true; pane.YAxis.Scale.MaxAuto = true; pane.YAxis.Scale.MajorStepAuto = true; history_jcurve = pane.AddJapaneseCandleStick("", spl); history_jcurve.Stick.Color = Config.Color.GraphCurveForeColor(0); history_jcurve.Stick.RisingFill = new Fill(Config.Color.PositiveForeColor); history_jcurve.Stick.RisingBorder = new Border(Config.Color.PositiveForeColor, 1); history_jcurve.Stick.FallingFill = new Fill(Config.Color.NegativeForeColor); history_jcurve.Stick.FallingBorder = new Border(Config.Color.NegativeForeColor, 1); history_jcurve.Label.IsVisible = false; history_jcurve.Stick.IsAutoSize = true; history_jcurve.Stick.IsOpenCloseVisible = true; history_jcurve.Stick.Width = 1.5F; //PenWidth history_vcurve = pane.AddCurve("", history_x, history_y, Config.Color.GraphCurveForeColor(0), SymbolType.None); history_vcurve.Line.IsAntiAlias = true; history_vcurve.Line.IsSmooth = false; history_vcurve.Line.Width = 1; history_vcurve.IsVisible = true; history_vcurve.Label.IsVisible = false; historyGraph.AxisChange(); historyGraph.Invalidate(); // update graph default axis history_xaxis_min = pane.XAxis.Scale.Min; history_xaxis_max = pane.XAxis.Scale.Max; history_xaxis_maj = pane.XAxis.Scale.MajorStep; history_xaxis_mor = pane.XAxis.Scale.MinorStep; history_yaxis_min = pane.YAxis.Scale.Min; history_yaxis_max = pane.YAxis.Scale.Max; history_yaxis_maj = pane.YAxis.Scale.MajorStep; history_yaxis_mor = pane.YAxis.Scale.MinorStep; // add history cursor curves AddHistoryCursorCurves(); }
public void Update(object sender, UpdateMRMPairedPeptideItemEventArgs e) { var summary = e.Item; if (summary == null) { throw new ArgumentNullException("UpdateMRMPairedPeptideItemEventArgs.Item cannot be null"); } var myMaster = zgcGraph.GraphPane; myMaster.Title.Text = "Retention time ranges"; myMaster.XAxis.Title.Text = "Files"; myMaster.YAxis.Title.Text = "Retention time"; myMaster.CurveList.Clear(); try { var splRange = new PointPairList(); var splEnabled = new PointPairList(); var splAll = new StockPointList(); List <string> filenames = new List <string>(); int index = 0; List <double> median = new List <double>(); for (int i = 0; i < summary.ProductIonPairs.Count; i++) { if (summary.ProductIonPairs[i] == null) { continue; } index++; filenames.Add(summary.ProductIonPairs[i].FileName); var ints = summary.ProductIonPairs[i].Light.Intensities; var low = ints.First().RetentionTime; var high = ints.Last().RetentionTime; var firstEnabled = ints.Find(m => m.Enabled); var open = firstEnabled == null ? (low + high) / 2 : firstEnabled.RetentionTime; var lastEnabled = ints.FindLast(m => m.Enabled); var close = lastEnabled == null ? (low + high) / 2 : lastEnabled.RetentionTime; median.Add((open + close) / 2); splRange.Add(new PointPair(index, low, high)); splEnabled.Add(new PointPair(index, open, close)); splAll.Add(index, high, low, open, close, 1000); } myMaster.XAxis.Type = AxisType.Text; myMaster.XAxis.Scale.TextLabels = filenames.ToArray(); var item = myMaster.AddJapaneseCandleStick("", splAll); item.Stick.RisingFill = new Fill(Color.Red); item.Stick.FallingFill = new Fill(Color.Blue); zgcGraph.AxisChange(); } finally { ZedGraphicExtension.UpdateGraph(this.zgcGraph); } }