示例#1
0
        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);
        }
示例#2
0
        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);
                }
            }
        }
示例#3
0
        public ChartingForm(StockData aStock)
        {
            this.Stock    = aStock;
            this.SPList   = new StockPointList();
            this.MACDList = new List <MacdPoint>();

            for (int i = 0; i < this.Stock.DataPoints.Count; i++)
            {
                CandleStick nCandleStick = this.Stock.DataPoints[i];
                XDate       xDate        = new XDate(nCandleStick.Date);
                StockPt     nPoint       = new StockPt(xDate.XLDate, nCandleStick.High, nCandleStick.Low, nCandleStick.Open, nCandleStick.Close, nCandleStick.Volume);
                this.SPList.Add(nPoint);
            }

            InitializeComponent();

            this.ZedGraphControl.MasterPane = new MasterPane();
            this.mCandleStickPane           = new GraphPane();
            this.mMacdPane       = new GraphPane();
            this.mStochasticPane = new GraphPane();

            InitializeZedGraph();
            DrawSmaGraph(this.mCandleStickPane, 20, Color.Red);
            DrawSmaGraph(this.mCandleStickPane, 50, Color.Blue);
            DrawCandleStickGraph(this.mCandleStickPane);
            DrawMacdGraph(this.mMacdPane, 12, 26, 9, Color.Blue, Color.Red);
            DrawStochPane(this.mStochasticPane, 14, 3, 3, Color.Blue, Color.Red);

            this.ZedGraphControl.AxisChange();
            this.ZedGraphControl.Dock = DockStyle.Fill;
            this.ZedGraphControl.Refresh();
        }
示例#4
0
        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();
        }
示例#5
0
        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();
        }
示例#6
0
        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();
        }
示例#7
0
 public static void GetRangeY(JapaneseCandleStickItem curve, int fromId, int toId, ref ValueRange yRange)
 {
     for (int idx = fromId; idx <= toId; idx++)
     {
         StockPt item = (StockPt)curve.Points[idx];
         if (item.Low < yRange.Min)
         {
             yRange.Min = item.Low;
         }
         if (item.High > yRange.Max)
         {
             yRange.Max = item.High;
         }
     }
 }
示例#8
0
        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;
        }
示例#9
0
        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);
        }
示例#10
0
        /// <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();
        }
        /// <summary>
        /// Create candles from series x,y data:
        /// </summary>
        private 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);
        }
        private void DrawPriceChart(TradeEventArgs e = null)
        {
            var candles = zedPrice.GraphPane.CurveList["candle"];

            if (candles == null)
            {
                return;
            }

            StockPt point  = null;
            var     points = (StockPointList)candles.Points;

            if (e == null)
            {
                _currentTime = CurrentDate;

                var date = CurrentDate;
                var c    = _controller.GetBitstampCandle(date, CurrencyName.BTC, TickPeriodMinutes.PeriodMinutes);
                point = new StockPt(new XDate(date).XLDate, c.High, c.Low, c.Open, c.Close, 0);
            }
            else
            {
                if (points.Count == 0)
                {
                    return;
                }

                var pt = points.Last();
                points.RemoveAt(points.Count - 1);

                if (_currentTime.HasValue)
                {
                    _currentTime = CurrentDate;
                }

                if (e.Price > pt.High)
                {
                    pt.High = e.Price;
                }
                if (e.Price < pt.Low)
                {
                    pt.Low = e.Price;
                }

                point = new StockPt(new XDate(_currentTime.Value).XLDate, pt.High, pt.Low, pt.Open, e.Price, 0);
            }

            points.Add(point);
            Scale xScale = zedPrice.GraphPane.XAxis.Scale;

            if (_tickCount > xScale.Max - xScale.MajorStep)
            {
                xScale.Max = _tickCount + xScale.MajorStep;
                xScale.Min = xScale.Max - XScaleMax;
            }
            _tickCount++;

            //var elapsedMinutes = DateTime.UtcNow.Hour * 60 + DateTime.UtcNow.Minute;    // temp!!
            //SetTimeAxis(elapsedMinutes - 30);

            SetPriceAxes(point.High - MinPriceOffset, point.High + MaxPriceOffset);
            DrawPriceLine(point.Close);
            UpdateZedControl();
        }
示例#13
0
        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);
                }
            }
        }
        //------------------------------------------------------------------------
        // Update data on initialization or on timer
        //------------------------------------------------------------------------
        private void calc(XDate now, bool timer)
        {
            var oldTimerEnabled = m_Timer.Enabled;

            m_Timer.Enabled = false;
            const double diff = 5.0f / XDate.SecondsPerDay;
            var          tm   = now - 5;
            var          add  = !timer || (m_Data.Count > 0 && ((now - LastPoint.Date) > diff));
            StockPt      pt   = null;
            var          up   = m_Rand.NextDouble() > 0.5;
            var          val  = up ? LastPoint.Low : LastPoint.High;

            Action <double, double, bool> set_min_max = (min, max, absolute) =>
            {
                var grace = (m_Pane.Y2Axis.Scale.Max - m_Pane.Y2Axis.Scale.Min) *
                            m_Pane.Y2Axis.Scale.MaxGrace;
                var gap = grace; //m_Pane.Y2Axis.Scale.ReverseTransform(10) + grace;
                m_Pane.Y2Axis.Scale.Min = absolute
                                    ? min - gap
                                    : Math.Min(m_Pane.Y2Axis.Scale.Min, min - gap);
                m_Pane.Y2Axis.Scale.Max = absolute
                                    ? max + gap
                                    : Math.Max(m_Pane.Y2Axis.Scale.Max, max + gap);
            };

            if (add)
            {
                var open  = (float)(m_Open + m_Rand.NextDouble() * 10.0 - 5.0);
                var close = (float)(m_Open + m_Rand.NextDouble() * 10.0 - 5.0);
                var hi    = (float)(Math.Max(open, close) + m_Rand.NextDouble() * 5.0);
                var low   = (float)(Math.Min(open, close) - m_Rand.NextDouble() * 5.0);
                var bvol  = m_Rand.NextDouble() * 1000;
                var svol  = m_Rand.NextDouble() * 1000;

                var x = now.XLDate - (now.XLDate % diff);
                pt = new StockPt(x, open, hi, low, close, (int)bvol, (int)svol);

                m_Data.Add(pt);
                m_Open = close;

                m_EMA = EMA_ALPHA * close + (1.0 - EMA_ALPHA) * m_EMA;
                m_EMAData.Add(x, m_EMA);

                if (timer)
                {
                    //m_Pane.XAxis.Scale.Max = now + 5;
                    //m_Pane.XAxis.Scale.Min += diff;

                    if (Math.Abs(Math.Round(m_Pane.XAxis.Scale.Max) - m_Data.Count) < 5)
                    {
                        var window = (int)(m_Pane.XAxis.Scale.Max - m_Pane.XAxis.Scale.Min);
                        //m_Pane.XAxis.Scale.SetRange();
                        m_Pane.XAxis.Scale.Max = m_Data.Count + 1;
                        m_Pane.XAxis.Scale.Min = m_Pane.XAxis.Scale.Max - window;

                        double min = double.MaxValue, max = double.MinValue;
                        var    xMin = Scale.MinMax(0, (int)m_Pane.XAxis.Scale.Min, m_Data.Count);
                        var    xMax = Scale.MinMax(0, (int)m_Pane.XAxis.Scale.Max, m_Data.Count);
                        for (int i = xMin; i < xMax; ++i)
                        {
                            var d = (StockPt)m_Data[i];
                            min = Math.Min(d.Low, min);
                            max = Math.Max(d.High, max);
                        }

                        set_min_max(min, max, true);
                        m_Pane.AxisChange();
                    }

                    if (m_Data.Count % 1 == 0)
                    {
                        var yy =
                            m_Pane.Y2Axis.Scale.ReverseTransform(m_Pane.Y2Axis.Scale.Transform(val) +
                                                                 (up ? 5 : -5));
                        //var y2 = val * (up ? 0.96 : 1.03);
                        var arrow = new PointObj(m_Data.Count - 1, yy, 5,
                                                 up ? SymbolType.ArrowUp : SymbolType.ArrowDown,
                                                 up ? Color.Green : Color.Red)
                        {
                            IsMovable  = false,
                            IsY2Axis   = true,
                            YAxisIndex = 0,
                            //Fill = {Type = FillType.None},
                            IsClippedToChartRect = true
                        };

                        //arrow.Line.Width = 1;
                        //arrow.Location.CoordinateFrame = CoordType.AxisXYScale;
                        m_Pane.GraphObjList.Add(arrow);
                    }
                }
            }
            else if (m_Data.Count > 0)
            {
                pt       = LastPoint;
                pt.Close = (float)(m_Open + m_Rand.NextDouble() * 10.0 - 5.0);
                pt.High  = (float)Math.Max(pt.High, Math.Max(m_Open, pt.Close) + m_Rand.NextDouble() * 5.0);
                pt.Low   = (float)Math.Min(pt.Low, Math.Min(m_Open, pt.Close) - m_Rand.NextDouble() * 5.0);

                if (timer && Math.Abs(Math.Round(m_Pane.XAxis.Scale.Max) - m_Data.Count) < 5)
                {
                    set_min_max(pt.Low, pt.High, false);
                }
            }

            if (m_Line != null)
            {
                m_Line.Value = pt.Close;
            }

            m_Now           = now;
            m_Timer.Enabled = oldTimerEnabled;
        }
示例#15
0
        private void xxxGraph_UpdateCursor(ZedGraphControl zgc, double x, double y)
        {
            string pos_string = "";

            GraphPane pane = zgc.GraphPane;

            if (zgc == historyGraph && history_x != null)
            {
                int i = (int)Math.Round(x - 1, 0);

                history_last_cursor_x = history_x[i];
                history_last_cursor_y = history_y[i];

                XDate xdate = new XDate(history_last_cursor_x);

                // update cursor position
                history_cursor_symb.Points[0].X = (double)i + 1;
                history_cursor_symb.Points[0].Y = history_last_cursor_y;
                history_cursor_line.Points[0].X = (double)i + 1;
                history_cursor_line.Points[0].Y = pane.YAxis.Scale.Min;
                history_cursor_line.Points[1].X = (double)i + 1;
                history_cursor_line.Points[1].Y = pane.YAxis.Scale.Max;
                history_cursor_line.Line.Style  = System.Drawing.Drawing2D.DashStyle.Dot;

                history_cursor_line.IsVisible = true;
                history_cursor_symb.IsVisible = true;

                // tool strip message
                StockPt pt = (StockPt)history_jcurve.Points[i];

                // calculate bussiness days
                TimeSpan ts = DateTime.Now - ((DateTime)xdate);
                int      dy = (ts.Days % 7) + (ts.Days / 7) * 5;

                pos_string = "Date = " + xdate.ToString("dd-MMM-yy") +
                             ", Open = " + pt.Open.ToString("f2") +
                             ", Close = " + pt.Close.ToString("f2") +
                             ", High = " + pt.High.ToString("f2") +
                             ", Low = " + pt.Low.ToString("f2") +
                             ", Vol = " + pt.Vol.ToString("N0") +
                             "  (" + dy + " Days Ago)";

                if (pt.Close >= pt.Open)
                {
                    history_cursor_line.Color = Config.Color.PositiveForeColor;
                }
                else
                {
                    history_cursor_line.Color = Config.Color.NegativeForeColor;
                }

                // update status string
                toolStripStatus2.Text = pos_string;
            }
            else if (zgc == volatilityGraph && volatility_x != null)
            {
                string imp_option = HighlightImpliedVolatilityPoint(5, x, y);

                y = CurveTransform(volatility_mcurve, x);

                volatility_last_cursor_x = x;
                volatility_last_cursor_y = y;

                // update cursor position
                volatility_cursor_symb.Points[0].X = x;
                volatility_cursor_symb.Points[0].Y = y;
                volatility_cursor_line.Points[0].X = x;
                volatility_cursor_line.Points[0].Y = pane.YAxis.Scale.Min;
                volatility_cursor_line.Points[1].X = x;
                volatility_cursor_line.Points[1].Y = pane.YAxis.Scale.Max;
                volatility_cursor_line.Line.Style  = System.Drawing.Drawing2D.DashStyle.Dot;

                volatility_cursor_line.IsVisible = true;
                volatility_cursor_symb.IsVisible = true;

                pos_string = "Period = " + x.ToString("N0") + " days" +
                             ", Mean = " + y.ToString("N2") + " %" +
                             ", StdDev = " + (CurveTransform(volatility_mcurve_1u, x) - y).ToString("N2") + " %" +
                             ", Low = " + CurveTransform(volatility_mcurve_lo, x).ToString("N2") + " %" +
                             ", High = " + CurveTransform(volatility_mcurve_hi, x).ToString("N2") + " %";

                // update status string
                toolStripStatus1.Text = pos_string;
                toolStripLabel1.Text  = imp_option;
            }

            // refresh graph
            zgc.Invalidate();
        }
示例#16
0
        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();
        }