//按钮加载K线
private void button1_Click(object sender, EventArgs e)
{
int count = int.Parse(this.comboBox1.Text.Trim());
half = count;
string jintian = DateTime.Now.ToShortDateString().ToString();
curdate = jintian;
begindate = jintian;
this.Refresh();
string sql = “select top " + count + " begintime,dayopen,dayclose,dayhigh,daylow,day5,day10 from zhy880301 where begintime<=’” + jintian + “’ order by begintime desc”;
huatu(sql, count);
label1.Text = curdate;
}
//画K线方法
private void huatu(string sql,int num)
{
Graphics g = CreateGraphics();
Pen p = new Pen(Color.Red, 1);//上涨
Pen p1 = new Pen(Color.Green, 1);//下跌
Pen p2 = new Pen(Color.Black, 1);
Pen p3 = new Pen(Color.Blue, 1);
Point[] pointList5;//用来绘制曲线图的关键点,依次将这些点连接起来即得到曲线图(Ma5)
Point[] pointList10;
DataSet ds = null;
DataTable dt = null;
ds = db.getds(sql, “mminfo”);
dt = ds.Tables[0];
pointList5 = new Point[dt.Rows.Count];//初始化坐标数组
pointList10 = new Point[dt.Rows.Count];//初始化坐标数组
int width = 1050;
int height = 400;
int Kwidth = width / dt.Rows.Count - 10;
g.DrawRectangle(p, 80, 80, width, height);
//k线开始
Font myFont = new Font(“微软雅黑”, 8);
string begindate1 = null;
string overdate1=dt.Rows[dt.Rows.Count-1][“begintime”].ToString();
overdate =overdate1.Substring(0,overdate1.IndexOf(" “));
string begindate2 = dt.Rows[0][“begintime”].ToString();
begindate = begindate2.Substring(0, begindate2.IndexOf(” "));
decimal high = (decimal)dt.Compute(“Max(dayhigh)”, null);//选择的K线组合中最高价
decimal low = (decimal)dt.Compute(“Min(daylow)”, null);//选择的K线组合中最低价
decimal hhigh = Math.Floor(high);
decimal llow = Math.Floor(low);
float llow1 = float.Parse(llow.ToString());
int changdu = width / dt.Rows.Count;//横轴每个日期的长度
decimal hlow = hhigh - llow;//纵轴总共差价
decimal oneprice = hlow / 10;
float onepoint = float.Parse((height / hlow).ToString());//单个价格所占的纵轴坐标
for (int i = 0; i < dt.Rows.Count; i++)//横轴时间
{
g.DrawLine(p, width + 80 - changdu * (i + 1) + Kwidth / 2, height + 80, width + 80 - changdu * (i + 1) + Kwidth / 2, height + 80 + 10);//横线N等分(20整体向右移动20单位,600为矩形长度,80为矩形离窗体左边为80)
}
for (int i = 0; i < 9; i++)//纵轴价格
{
g.DrawLine(p, width + 80, 480 - 40 * (i + 1), width + 90, 480 - 40 * (i + 1));//纵线10等分
g.DrawString(((i + 1) * oneprice + llow).ToString(), myFont, Brushes.Red, width + 95, height + 73 - height / 10 * (i + 1));

        }for (int i = 0; i < dt.Rows.Count; i++){int len1 = dt.Rows[i]["begintime"].ToString().IndexOf(" ");int len = dt.Rows[i]["begintime"].ToString().LastIndexOf('/') + 1;int len2 = dt.Rows[i]["begintime"].ToString().IndexOf('/') + 1;begindate1 = dt.Rows[i]["begintime"].ToString().Substring(len2, len1 - len2);float o = float.Parse(dt.Rows[i]["dayopen"].ToString());float c = float.Parse(dt.Rows[i]["dayclose"].ToString());float h = float.Parse(dt.Rows[i]["dayhigh"].ToString());float l = float.Parse(dt.Rows[i]["daylow"].ToString());float day5=float.Parse(dt.Rows[i]["day5"].ToString());float day10 = float.Parse(dt.Rows[i]["day10"].ToString());int px5 = int.Parse((width + 80 - changdu * (i + 1) + Kwidth / 2).ToString());int py5 = int.Parse(Math.Floor(height - (day5 - llow1) * onepoint+80).ToString());int py10 = int.Parse(Math.Floor(height - (day10 - llow1) * onepoint + 80).ToString());if (begindate1 == "10/30"){label17.Text = px5.ToString();label16.Text = py5.ToString();}pointList5[i] = new Point(px5, py5);pointList10[i] = new Point(px5, py10);g.DrawString(begindate1, myFont, Brushes.Red, new PointF(width + 80 - changdu * (i + 1) + Kwidth / 2-5, height + 100));if (c > o){g.DrawLine(p, width + 80 - changdu * (i + 1) + Kwidth / 2, height - (c - llow1) * onepoint + 80, width + 80 - changdu * (i + 1) + Kwidth / 2, height - (h - llow1) * onepoint + 80);//上影(600为矩形长度,80为矩形到窗体左边的距离,60为长度10等分,10为纵柱最高价)g.DrawRectangle(p, width + 80 - 20 - changdu * (i + 1) + 20, height - (c - llow1) * onepoint + 80, Kwidth, (c - o) * onepoint);//实体(Kwidth为K线宽度)(20,40为调节K线大小)g.DrawLine(p, width + 80 - changdu * (i + 1) + Kwidth / 2, height - (o - llow1) * onepoint + 80, width + 80 - changdu * (i + 1) + Kwidth / 2, height - (l - llow1) * onepoint + 80);//下影 (20为整体向左平移20个单位)}else if (c < o){g.DrawLine(p1, width + 80 - changdu * (i + 1) + Kwidth / 2, height - (o - llow1) * onepoint + 80, width + 80 - changdu * (i + 1) + Kwidth / 2, height - (h - llow1) * onepoint + 80);//上影g.DrawRectangle(p1, width + 80 - 20 - changdu * (i + 1) + 20, height - (o - llow1) * onepoint + 80, Kwidth, (o - c) * onepoint);//实体g.DrawLine(p1, width + 80 - changdu * (i + 1) + Kwidth / 2, height - (c - llow1) * onepoint + 80, width + 80 - changdu * (i + 1) + Kwidth / 2, height - (l - llow1) * onepoint + 80);//下影 }else if (c == o){g.DrawLine(p, width + 80 - changdu * (i + 1) + Kwidth / 2, height - (o - llow1) * onepoint + 80, width + 80 - changdu * (i + 1) + Kwidth / 2, height - (h - llow1) * onepoint + 80);//上影g.DrawLine(p1, width + 80 - 20 - changdu * (i + 1) + 20, height - (o - llow1) * onepoint + 80, width + 80 - 20 - changdu * (i + 1) + 20 + Kwidth, height - (o - llow1) * onepoint + 80);//实体g.DrawLine(p, width + 80 - changdu * (i + 1) + Kwidth / 2, height - (c - llow1) * onepoint + 80, width + 80 - changdu * (i + 1) + Kwidth / 2, height - (l - llow1) * onepoint + 80);//下影 }}g.DrawCurve(p2, pointList5);g.DrawCurve(p3, pointList10);p.Dispose();g.Dispose();}/// <summary>/// 重写ProcessDialogKey,来允许监听方向键/// </summary>/// <param name="keycode"></param>/// <returns></returns>protected override bool ProcessDialogKey(Keys keycode){switch (keycode){case Keys.Left:case Keys.Up:case Keys.Right:case Keys.Down:return false;}return true;}/// <summary>/// 监听方向键的KeyDown事件/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void Kxian_KeyDown(object sender, KeyEventArgs e){DataSet ds;string curdate1 = null;string sql = null;            string bdate = null;string odate = null;int count = int.Parse(this.comboBox1.Text.Trim());switch (e.KeyCode){case Keys.Left:sql = "select top 1 begintime,dayopen,dayclose,dayhigh,daylow,day5,day10 from zhy880301 where begintime<'" + curdate + "' order by begintime desc";ds = db.getds(sql, "previous");if (ds.Tables[0].Rows.Count > 0){curdate1 = ds.Tables[0].Rows[0]["begintime"].ToString();curdate = curdate1.Substring(0, curdate1.IndexOf(" "));label1.Text = curdate;label7.Text = ds.Tables[0].Rows[0]["dayopen"].ToString();label6.Text = ds.Tables[0].Rows[0]["dayclose"].ToString();label9.Text = ds.Tables[0].Rows[0]["dayhigh"].ToString();label8.Text = ds.Tables[0].Rows[0]["daylow"].ToString();label12.Text = ds.Tables[0].Rows[0]["day5"].ToString();label11.Text = ds.Tables[0].Rows[0]["day10"].ToString();if (CompareDate(curdate, overdate) < 0){this.Refresh();sql = "select * from(select top " + count + "  begintime,dayopen,dayclose,dayhigh,daylow,day5,day10 from zhy880301  where begintime>='" + curdate + "' order by begintime asc) a order by begintime desc";huatu(sql, count);overdate = curdate;}}break;case Keys.Up:                    half = half / 2;if (half > 0){this.Refresh();bdate = DateTime.Parse(curdate).AddDays(-half).ToShortDateString();odate = DateTime.Parse(curdate).AddDays(half).ToShortDateString();sql = "select  begintime,dayopen,dayopen,dayclose,dayhigh,daylow,day5,day10 from zhy880301  where begintime between '" + bdate + "' and '" + odate + "' order by begintime desc ";huatu(sql, half);label2.Text = half.ToString();}else{half = 1;}break;case Keys.Right:sql = "select top 1 begintime,dayopen,dayclose,dayhigh,daylow,day5,day10 from zhy880301 where begintime>'" + curdate + "' order by begintime asc";ds = db.getds(sql, "next");if (ds.Tables[0].Rows.Count > 0){curdate1 = ds.Tables[0].Rows[0]["begintime"].ToString();curdate = curdate1.Substring(0, curdate1.IndexOf(" "));label1.Text = curdate;label7.Text = ds.Tables[0].Rows[0]["dayopen"].ToString();label6.Text = ds.Tables[0].Rows[0]["dayclose"].ToString();label9.Text = ds.Tables[0].Rows[0]["dayhigh"].ToString();label8.Text = ds.Tables[0].Rows[0]["daylow"].ToString();label12.Text = ds.Tables[0].Rows[0]["day5"].ToString();label11.Text = ds.Tables[0].Rows[0]["day10"].ToString();if (CompareDate(curdate, begindate) > 0){this.Refresh();sql = "select top " + count + "  begintime,dayopen,dayclose,dayhigh,daylow,day5,day10 from zhy880301  where begintime<='" + curdate + "' order by begintime desc";huatu(sql, count);overdate = curdate;}}break;case Keys.Down:this.Refresh();half = half * 2;bdate = DateTime.Parse(curdate).AddDays(-half).ToShortDateString();odate = DateTime.Parse(curdate).AddDays(half).ToShortDateString();sql = "select  begintime,dayopen,dayopen,dayclose,dayhigh,daylow,day5,day10 from zhy880301  where begintime between '" + bdate + "' and '" + odate + "' order by begintime desc ";huatu(sql, half);label2.Text = half.ToString();break;}}

C#画K线实现加载均线(5日,10日)相关推荐

  1. C#画K线实现加载不同股票和5,10,20,60均线

    //按钮加载K线 private void button1_Click(object sender, EventArgs e) { if (this.comboBox1.Text == "热 ...

  2. 【python量化交易学习】pandas获取mysql数据,使用pyecharts画K线图,ma移动均线。

    将pyecharts官方提供的数据源,替换成已经存在mysql中的数据.画出专业的k线图(k线+ma移动均线+交易额柱状图(单位是千)) 参考: [python量化交易学习]pandas获取tusha ...

  3. 画K线图、画N日均线 python3

    记下自己的研究成果是件开心的事情,本文介绍用Python3将股票历史行情画成K线图,以及添加5日,10日,N日均线. 首先,是获取数据源,一般分两种,一是直接从财经类网站读取:二是读取本地数据文件.我 ...

  4. python绘制动态k线及均线,python : pyecharts 1.1.0 画K线图

    pip install pyecharts ; 会安装 pyecharts-1.1.0 画K线图 kline1.py # coding: utf-8 import os, sys from pyech ...

  5. python画k线_python画k线,python绘制动态k线及均线

    内容导航: Q1:k线图上怎么画线 一般你看K线软件都有画图功能,以同花顺为例,在上方菜单栏找到画图,点击,会在菜单栏下方一行或者屏幕最右边一列出现相应的画图工具. Q2:求教使用python绘制K线 ...

  6. C#画K线实现画K线和截图保存

    string begindate = null; string curdate = null; string overdate = null; int half = 0; string gpname ...

  7. python k线图_如何用python画K线图(成交量+MACD+KDJ)

    最近一直在研究股票的形态,一些量化的东西,虽然量化听起来很高大上,通寻找到一个策略,通过程序的手段去找到这样一批股票,避免了人为的因素在其中.这样有个问题就是,程序选出来的股票太机械了,某个参数或条件 ...

  8. python k线图和指标_量化交易中,如何使用Python画K线、成交量、买卖点【邢不行】...

    引言: 邢不行的系列帖子"量化小讲堂",通过实际案例教初学者使用python进行量化投资,了解行业研究方向,希望能对大家有帮助. [历史文章汇总] 请点击此处 这是邢不行第  68 ...

  9. d3js mysql_使用d3js画K线图 - ObjectNotFoundException - OSCHINA - 中文开源技术交流社区

    使用 必应和谷歌 搜索了一圈,发现只有一篇使用d3js画K线图的文章,但是将相关的HTML和JavaScript代码内容保存为.html文件并在浏览器打开后,发现当使用d3js V4版本时并不能画出K ...

最新文章

  1. Python带参数复数表示
  2. 【自动驾驶】摄像头单目测距原理及实现
  3. 笔记-项目范围管理-需求工程-需求管理
  4. APICloud方法
  5. [2013.9.27][cpp]一个简单的链接栈模型
  6. mysql hibernate 延迟_在mysql数据库中,hibernate一对多的集合的延迟加载无效
  7. 设计模式(Python)-观察者模式
  8. 【基于熵权-模糊综合评价法】《基于熵权-模糊综合评价法的施工项目风险评价研究》论文笔记(内附MATLAB代码)
  9. shiro 框架实现 LDAP 登录
  10. DM7 达梦数据库 物理备份 相关概念说明
  11. http的响应码200,404,302,500表示的含义分别是?
  12. 第一章 使用SOAPUI测试和开发Web Services Stubs
  13. 基于单片机的D/A三角波发生器设计(电路+程序)
  14. pandas学习task11综合任务
  15. 使用wireshark进行安卓抓包分析
  16. 1.4 安装Kali Linux
  17. 【Android】解决aab上传Google Play后下载语言文件缺失的问题
  18. MySql 高级查询强化学习
  19. 2021 年国产数据库名录和产品信息一览
  20. 实用帖!分享5个素材丰富的资源网站

热门文章

  1. SpringCloud-4.服务网关(GateWay)
  2. Unity【SwitchableObject】- 实现一个物体开关控制系统
  3. win10 cmd 中文乱码
  4. 弘辽科技:抖音小店差评如何补救?
  5. “知识分享与交流”活动有感
  6. aliyun短信及短信模板操作
  7. 联想Y471A加装固态硬盘及解决启动黑屏问题
  8. Molecular weight相对分子质量
  9. python tushare量化股票大数据分析整合版
  10. 如何在Dynamic CRM 2011中使用自定义Workflow