在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例C#数据库操作 → 股票,期货,现货 K线开发实例

股票,期货,现货 K线开发实例

C#数据库操作

下载此实例
  • 开发语言:C#
  • 实例大小:4.53M
  • 下载次数:212
  • 浏览次数:951
  • 发布时间:2017-03-27
  • 实例类别:C#数据库操作
  • 发 布 人:50716809
  • 文件格式:.rar
  • 所需积分:2
 相关标签: 实例 开发

实例介绍

【实例简介】
【实例截图】

【核心代码】

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Threading;
using ImageOfStock;
using System.Drawing.Drawing2D;
using KCZXDataAccess;


namespace KCZX.Forms
{
    public partial class Form1 :  Form2   
    {
        public Form1()
        {
            InitializeComponent();
          
            CandleGraph();
            InitMainMenu();
         
        }

    
        public void InitMainMenu()
        {

            List<string[]> list = new List<string[]>();
            using (PeopleAccessClass da = new PeopleAccessClass())
            {
                DataSet ds = new DataSet();
                string x= MainForm .gudaima  ;
                string y = MainForm.mingcheng;
                string z = MainForm.k_string;
                ds = da.GETMAINdetail(x );
                if (ds.Tables[0].Rows.Count != 0)
                {
                    string[] languages = { z, x,y, "期货指数", "", "", "", "", "" };
                    list.Add(languages);
                    string[] languages1 = { "时间", "开盘价", "最高价", "最低价", "收盘价", "成交量", "成交额" };
                    list.Add(languages1);

                    for (int i = 0; i < ds.Tables[0].Rows.Count; i )
                    {
                        string[] records = new string[8];
                        records[0] = ds.Tables[0].Rows[i][0].ToString();
                        records[1] = ds.Tables[0].Rows[i][1].ToString();
                        records[2] = ds.Tables[0].Rows[i][2].ToString();
                        records[3] = ds.Tables[0].Rows[i][3].ToString();
                        records[4] = ds.Tables[0].Rows[i][4].ToString();
                        records[5] = ds.Tables[0].Rows[i][5].ToString();
                        records[6] = ds.Tables[0].Rows[i][6].ToString();
                        records[7] = ds.Tables[0].Rows[i][7].ToString();
                        list.Add(records);
                    }

                }
                else
                {
                    return;
                }
            }
            CandleGraph();
            this.chartGraph1.ProcessBarValue = 0;
            Thread refreshData = new Thread(new ParameterizedThreadStart(UpdateDataToGraph));
            refreshData.IsBackground = true;
            refreshData.Start(list);
        }

        private void tsmiClose_Click(object sender, EventArgs e) //
        {
            this.Close();
            //Application.Exit();
        }

        /// <summary>
        /// 导入数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
       
        public void CandleGraph()
        {
            this.chartGraph1.ResetNullGraph();
            this.chartGraph1.UseScrollAddSpeed = true;
            this.chartGraph1.SetXScaleField("日期");
            this.chartGraph1.CanDragSeries = true;
            this.chartGraph1.SetSrollStep(10, 10);
            this.chartGraph1.ShowLeftScale = true;
            this.chartGraph1.ShowRightScale = true;
            this.chartGraph1.LeftPixSpace = 85;
            this.chartGraph1.RightPixSpace = 85;
            //K线图 BS点
            mainPanelID = this.chartGraph1.AddChartPanel(40);
            string candleName = "K线图-1";
            this.chartGraph1.AddCandle(candleName, "OPEN", "HIGH", "LOW", "CLOSE", mainPanelID, true);
            this.chartGraph1.YMBuySellSignal(mainPanelID, candleName, "BUYEMA", "(CLOSE HIGH LOW)/3", "SELLEMA", "BUYEMA");
            this.chartGraph1.AddBollingerBands("MID", "UP", "DOWN", "CLOSE", 20, 2, mainPanelID);
            this.chartGraph1.SetYScaleField(mainPanelID, new string[] { "HIGH", "LOW" });
            //成交量
            volumePanelID = this.chartGraph1.AddChartPanel(20);
            this.chartGraph1.AddHistogram("VOL", "", candleName, volumePanelID);
            this.chartGraph1.SetHistogramStyle("VOL", Color.Red, Color.SkyBlue, 1, false);
            this.chartGraph1.AddSimpleMovingAverage("VOL-MA1", "MA5", "VOL", 5, volumePanelID);
            this.chartGraph1.SetTrendLineStyle("VOL-MA1", Color.White, Color.White, 1, DashStyle.Solid);
            this.chartGraph1.AddSimpleMovingAverage("VOL-MA2", "MA10", "VOL", 10, volumePanelID);
            this.chartGraph1.SetTrendLineStyle("VOL-MA2", Color.Yellow, Color.Yellow, 1, DashStyle.Solid);
            this.chartGraph1.AddSimpleMovingAverage("VOL-MA3", "MA20", "VOL", 20, volumePanelID);
            this.chartGraph1.SetTrendLineStyle("VOL-MA3", Color.FromArgb(255, 0, 255), Color.FromArgb(255, 0, 255), 1, DashStyle.Solid);
            this.chartGraph1.SetTick(volumePanelID, 1);
            this.chartGraph1.SetDigit(volumePanelID, 0);
            kdjPanelID = this.chartGraph1.AddChartPanel(20);
            this.chartGraph1.AddStochasticOscillator("K", "D", "J", 9, "CLOSE", "HIGH", "LOW", kdjPanelID);
            macdPanelID = this.chartGraph1.AddChartPanel(20);
            this.chartGraph1.AddMacd("MACD", "DIFF", "DEA", "CLOSE", 26, 12, 9, macdPanelID);
        }
        int mainPanelID = -1;
        int volumePanelID = -1;
        int kdjPanelID = -1;
        int macdPanelID = -1;

        /// <summary>
        /// 窗体加载事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CustomForm_Load(object sender, EventArgs e)
        {
            this.Text = "Customr";
            this.Location = new Point(0, 0);
            this.Size = new Size(Screen.GetWorkingArea(this).Width, Screen.GetWorkingArea(this).Height);
            CandleGraph();
        }

        /// <summary>
        /// 更新进度条
        /// </summary>
        /// <param name="obj"></param>
        public void UpdateProcessBar(object obj)
        {
            int[] values = obj as int[];
            int total = values[0];
            int current = values[1];
            int processValue = Convert.ToInt32((double)current / (double)total * 100);
            if (processValue > this.chartGraph1.ProcessBarValue)
            {
                this.chartGraph1.ProcessBarValue = processValue;
            }
            if (current == total - 2)
            {
                this.chartGraph1.ProcessBarValue = 100;
                //this.tsmiImport.Enabled = true;
                this.chartGraph1.RefreshGraph();
            }
        }

        private delegate void UpdateProcessBarDelegate(object obj);

        /// <summary>
        /// 更新数据到图像
        /// </summary>
        /// <param name="obj"></param>
        public void UpdateDataToGraph(object obj)
        {
            List<string[]> list = obj as List<string[]>;
            string[] str = list[0];
            this.chartGraph1.SetTitle(mainPanelID, str[2] "(" str[1] ") " str[0]);
            this.chartGraph1.SetTitle(kdjPanelID, "KDJ(9,3,3)");
            this.chartGraph1.SetTitle(volumePanelID, "VOL(5,10,20)");
            this.chartGraph1.SetTitle(macdPanelID, "MACD(12,26,9)");
            string lineType = str[0];
            switch (lineType)
            {
                case "5分钟":
                    this.chartGraph1.SetIntervalType(mainPanelID, ChartGraph.IntervalType.Second );
                    this.chartGraph1.SetIntervalType(volumePanelID, ChartGraph.IntervalType.Second);
                    this.chartGraph1.SetIntervalType(kdjPanelID, ChartGraph.IntervalType.Second);
                    break;
                case "15分钟":
                case "30分钟":
                case "60分钟":
                    this.chartGraph1.SetIntervalType(mainPanelID, ChartGraph.IntervalType.Minute);
                    this.chartGraph1.SetIntervalType(volumePanelID, ChartGraph.IntervalType.Minute);
                    this.chartGraph1.SetIntervalType(kdjPanelID, ChartGraph.IntervalType.Minute);
                    break;
                case "日线":
                    this.chartGraph1.SetIntervalType(mainPanelID, ChartGraph.IntervalType.Day);
                    this.chartGraph1.SetIntervalType(volumePanelID, ChartGraph.IntervalType.Day);
                    this.chartGraph1.SetIntervalType(kdjPanelID, ChartGraph.IntervalType.Day);
                    break;
                case "周线":
                    this.chartGraph1.SetIntervalType(mainPanelID, ChartGraph.IntervalType.Week);
                    this.chartGraph1.SetIntervalType(volumePanelID, ChartGraph.IntervalType.Week);
                    this.chartGraph1.SetIntervalType(kdjPanelID, ChartGraph.IntervalType.Week);
                    break;
                case "月线":
                    this.chartGraph1.SetIntervalType(mainPanelID, ChartGraph.IntervalType.Month);
                    this.chartGraph1.SetIntervalType(volumePanelID, ChartGraph.IntervalType.Month);
                    this.chartGraph1.SetIntervalType(kdjPanelID, ChartGraph.IntervalType.Month);
                    break;
            }
            this.chartGraph1.RefreshGraph();
            for (int i = list.Count - 1; i >= 2; i--)
            {
                string[] records = list[i];
                string timeKey = records[0];
                int year = 1970;
                int month = 1;
                int day = 1;
                int hour = 0;
                int minute = 0;
                switch (lineType)
                {
                    case "5分钟":
                    case "15分钟":
                    case "30分钟":
                    case "60分钟": 
                        month = Convert.ToInt32(timeKey.Substring(4,2));
                        day = Convert.ToInt32(timeKey.Substring(6, 2));
                        hour = 11;
                        minute = 22;
                        //hour = Convert.ToInt32(timeKey.Substring(3, 2));
                        //minute = Convert.ToInt32(timeKey.Substring(5, 2));
                        break;
                    case "日线":
                    case "周线":
                        year = Convert.ToInt32(timeKey.Substring(0, 4));
                        month = Convert.ToInt32(timeKey.Substring(4, 2));
                        day = Convert.ToInt32(timeKey.Substring(6, 2));
                        break;
                    case "月线":
                        year = Convert.ToInt32(timeKey.Substring(0, 4));
                        month = Convert.ToInt32(timeKey.Substring(4, 2));
                        break;
                }
                DateTime dt = new DateTime(year, month, day, hour, minute, 0);
                this.chartGraph1.SetValue("OPEN", records[1], dt);
                this.chartGraph1.SetValue("HIGH", records[2], dt);
                this.chartGraph1.SetValue("LOW", records[3], dt);
                this.chartGraph1.SetValue("CLOSE", records[4], dt);
                this.chartGraph1.SetValue("VOL", records[6], dt);
                double ymValue = (Convert.ToDouble(records[4]) Convert.ToDouble(records[3]) Convert.ToDouble(records[2])) / 3;
                this.chartGraph1.SetValue("(CLOSE HIGH LOW)/3", ymValue, dt);
                this.BeginInvoke(new UpdateProcessBarDelegate(UpdateProcessBar), new int[] { list.Count, list.Count - i });
            }
            this.chartGraph1.Enabled = true;
        }

        private void chartGraph1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)13)
            {
                using (PeopleAccessClass da = new PeopleAccessClass())
                {
                    string riqi1 = "";
                    string riqi2 = "";
                    if (DateTime.Parse(new AutoOIDManager().GetSystemDateTime().ToShortTimeString().ToString()) < DateTime.Parse("21:00"))
                    {
                        riqi1 = new AutoOIDManager().GetSystemDateTime().AddDays(-1).ToString("yyyy-MM-dd") " 21:00:00";
                        riqi2 = new AutoOIDManager().GetSystemDateTime().ToString("yyyy-MM-dd") " 15:00:00";
                    }
                    else
                    {
                        riqi1 = new AutoOIDManager().GetSystemDateTime().ToString("yyyy-MM-dd") " 21:00:00";
                        riqi2 = new AutoOIDManager().GetSystemDateTime().AddDays(1).ToString("yyyy-MM-dd") " 15:00:00";
                    }
                    DataSet dsd = new DataSet();
                    dsd = da.getshuju(MainForm.gudaima, riqi1, riqi2);  //获得从9:00 开始到 15 dian 看有没有数据。
                    if (dsd.Tables[0].Rows.Count != 0)
                    {
                        FormLine ChildForm = new FormLine();
                        //ChildForm.MdiParent = this;
                        ChildForm.Show();
                    }
                    else
                    {
                        MessageBox.Show("网络连接异常,请检查数据连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                }
            }

            if (e.KeyChar == (char)27)
            {
                Close();
            }


        }

        private void chartGraph1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            using (PeopleAccessClass da = new PeopleAccessClass())
            {
                string riqi1 = "";
                string riqi2 = "";
                if (DateTime.Parse(new AutoOIDManager().GetSystemDateTime().ToShortTimeString().ToString()) < DateTime.Parse("21:00"))
                {
                     riqi1 = new AutoOIDManager().GetSystemDateTime().AddDays (-1).ToString("yyyy-MM-dd") " 21:00:00";
                     riqi2 = new AutoOIDManager().GetSystemDateTime().ToString("yyyy-MM-dd") " 15:00:00";
                }
                else
                {
                     riqi1 = new AutoOIDManager().GetSystemDateTime().ToString("yyyy-MM-dd") " 21:00:00";
                     riqi2 = new AutoOIDManager().GetSystemDateTime().AddDays (1).ToString("yyyy-MM-dd") " 15:00:00";
                }
                DataSet dsd = new DataSet();
                dsd = da.getshuju(MainForm.gudaima, riqi1, riqi2);  //获得从9:00 开始到 15 dian 看有没有数据。
                if (dsd.Tables[0].Rows.Count != 0)
                {
                    FormLine ChildForm = new FormLine();
                    //ChildForm.MdiParent = this;
                    ChildForm.Show();
                }
                else
                {
                    MessageBox.Show("网络连接异常,请检查数据连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
            }
         
        }

    }
}


标签: 实例 开发

实例下载地址

股票,期货,现货 K线开发实例

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

第 1 楼 senglin 发表于: 2017-03-27 21:38 06
好测试通过

支持(0) 盖楼(回复)

第 2 楼 风云争霸 发表于: 2017-05-25 14:32 49
代码无法运行起来,少了一些必要的类库文件

支持(0) 盖楼(回复)

第 3 楼 scopezth 发表于: 2020-02-19 17:33 50
没有数据库文件,项目不完成,希望楼主提供。

支持(0) 盖楼(回复)

第 4 楼 hehe1019 发表于: 2021-11-27 20:49 42
代码无法运行起来,缺少必要的运行文件

支持(0) 盖楼(回复)

第 5 楼 vsoko88 发表于: 2022-04-11 15:17 57
跑不起来

支持(0) 盖楼(回复)

第 6 楼 万安 发表于: 2022-04-12 20:34 18
跑不起来

支持(0) 盖楼(回复)

发表评论

(您的评论需要经过审核才能显示)

查看所有6条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警