Matlab画k线图
来源:互联网 发布:wifi网络监控软件 编辑:程序博客网 时间:2024/04/27 19:39
KLine.m
function KLine(varargin)%% fun help% function Kplot(O,H,L,C)% Kplot(O,H,L,C,date)% Kplot(O,H,L,C,date,colorUp,colorDown,colorLine)%% Kplot(OHLC)% Kplot(OHLC,date)% Kplot(OHLC,date,colorUp,colorDown,colorLine)%% KLine(OHLC, 0, 'r', 'g', 'w');%%isMat = size(varargin{1}, 2); %返回第一个参数的值的列数indexShift = 0; %参数索引位置useDate = 0; %是否使用%提取OHLCif isMat == 4, O = varargin{1}(:,1); H = varargin{1}(:,2); L = varargin{1}(:,3); C = varargin{1}(:,4);else O = varargin{1}; H = varargin{2}; L = varargin{3}; C = varargin{4}; indexShift = 3;end%设置颜色的值if nargin + isMat < 7 colorDown = 'g'; colorUp = 'r'; else colorUp = varargin{3+indexShift}; colorDown = varargin{4+indexShift};end%设置Date值if nargin + isMat < 6 date = (1:length(O))';else if varargin{2+indexShift} ~= 0 date = varargin{2+indexShift}; useDate = 1; else date = (1:length(O))'; endend%设置宽度w = .3 * min([(date(2)-date(1)) (date(3)-date(2))]);d = C - O; %收盘价-开盘价hold on%画k线, 收盘价小于开盘价,跌n = find(d < 0);for i = 1:length(n) line([date(n(i)) date(n(i))], [L(n(i)) H(n(i))], 'Color', colorDown) %x1, x2, y1, y2 x = [date(n(i))-w date(n(i))-w date(n(i))+w date(n(i))+w date(n(i))-w]; y = [O(n(i)) C(n(i)) C(n(i)) O(n(i)) O(n(i))]; fill(x, y, colorDown)end%画k线,收盘价大于开盘价,涨n = find(d > 0);for i = 1:length(n) line([date(n(i)) date(n(i))], [L(n(i)) H(n(i))], 'Color', colorUp) %x1, x2, y1, y2 x=[date(n(i))-w date(n(i))-w date(n(i))+w date(n(i))+w date(n(i))-w]; y=[O(n(i)) C(n(i)) C(n(i)) O(n(i)) O(n(i))]; fill(x, y, colorUp)end%画k线,收盘价等于开盘价n = find(d == 0);for i = 1:length(n) line([date(n(i)) date(n(i))], [L(n(i)) H(n(i))], 'Color', 'w') %x1, x2, y1, y2 x=[date(n(i))-w date(n(i))-w date(n(i))+w date(n(i))+w date(n(i))-w]; y=[O(n(i)) C(n(i)) C(n(i)) O(n(i)) O(n(i))]; fill(x, y, 'w')endhold off
volume.m
function Volume(varargin)%% fun help% function Kplot(O,H,L,C)% Kplot(O,H,L,C,date)% Kplot(O,H,L,C,date,colorUp,colorDown,colorLine)%% Kplot(OHLC)% Kplot(OHLC,date)% Kplot(OHLC,date,colorUp,colorDown,colorLine)%% KLine(OHLC, 0, 'r', 'g', 'w');%%isMat = size(varargin{1}, 2); %返回第一个参数的值的列数indexShift = 0; %参数索引位置useDate = 0; %是否使用%提取OHLCif isMat == 6, O = varargin{1}(:,1); H = varargin{1}(:,2); L = varargin{1}(:,3); C = varargin{1}(:,4); V = varargin{1}(:,5);else O = varargin{1}; H = varargin{2}; L = varargin{3}; C = varargin{4}; indexShift = 3;end%设置颜色的值if nargin + isMat < 7 colorDown = 'g'; colorUp = 'r'; else colorUp = varargin{3+indexShift}; colorDown = varargin{4+indexShift};end%设置Date值if nargin + isMat < 6 date = (1:length(O))';else if varargin{2+indexShift} ~= 0 date = varargin{2+indexShift}; useDate = 1; else date = (1:length(O))'; endend%设置宽度w = .3 * min([(date(2)-date(1)) (date(3)-date(2))]);d = C - O; %收盘价-开盘价hold on%画k线, 收盘价小于开盘价,跌n = find(d < 0);for i = 1:length(n) x = [date(n(i))-w date(n(i))-w date(n(i))+w date(n(i))+w]; y = [0 V(n(i)) V(n(i)) 0]; fill(x, y, colorDown)end%画k线,收盘价大于开盘价,涨n = find(d > 0);for i = 1:length(n) x=[date(n(i))-w date(n(i))-w date(n(i))+w date(n(i))+w]; y=[0 V(n(i)) V(n(i)) 0]; fill(x, y, colorUp)end%画k线,收盘价等于开盘价n = find(d == 0);for i = 1:length(n) x=[date(n(i))-w date(n(i))-w date(n(i))+w date(n(i))+w]; y=[0 V(n(i)) V(n(i)) 0]; fill(x, y, 'w')endhold off
%加载数据,改为从网上直接获取或者从通达信客户端load IF-20120104.mat;F = F(1:100, :);%画k线subplot(3, 1, [1,2]);OHLC = F(:, 3:6);KLine(OHLC, 0, 'r', 'g', 'w');%xlim([1,length( OHLC )]);%画坐标轴文本XTick = [];XTickLabel = []; XTick = [XTick; 1];str = [num2str(F(1,1)), '-', num2str(F(1,2))];XTickLabel{numel(XTickLabel)+1, 1} = str;%10:00ind = find(F(:,2) == 1000, 1);if ~isempty(ind) XTick = [XTick; ind ]; str = [num2str(F(ind, 1)),'-',num2str(F(ind, 2))]; XTickLabel{numel(XTickLabel)+1, 1} = str;end %11:30ind = find(F(:,2) == 1130, 1);if ~isempty(ind) XTick = [XTick; ind ]; str = [num2str(F(ind, 1)),'-',num2str(F(ind, 2))]; XTickLabel{numel(XTickLabel)+1, 1} = str;end%14:00ind = find(F(:,2) == 1400, 1);if ~isempty(ind) XTick = [XTick; ind ]; str = [num2str(F(ind, 1)),'-',num2str(F(ind, 2))]; XTickLabel{numel(XTickLabel)+1, 1} = str;end ind = length(F(:,1));if XTick(end) ~= ind XTick = [XTick; ind ]; str = [num2str(F(ind, 1)),'-',num2str(F(ind, 2))]; XTickLabel{numel(XTickLabel)+1, 1} = str;end set(gca,'XTick', XTick);set(gca,'XTickLabel', XTickLabel);title('IF20120104 1分钟K线图', 'FontWeight','Bold', 'FontSize', 15);grid on%画成交量subplot(3, 1, 3);OHLCV = F(:, 3:8);Volume(OHLCV, 0, 'r', 'g', 'w');%title('成交量', 'FontWeight','Bold', 'FontSize', 15);%xlim([1,length( OHLC )]); %画坐标轴文本set(gca,'XTick', XTick);set(gca,'XTickLabel', XTickLabel);grid on
要达到国内客户端软件的样式还有很多地方需要修改,会继续完善。
0 0
- Matlab画k线图
- 如何用matlab和R语言画K线图
- JS画K线图
- JFreeCharts画k线图
- K线图
- matlab 外汇接口显示k线图以bid为准
- php画K线图的一个工具
- php画K线图的一个工具
- 小猫统计画股票K线图
- 使用Python画股票的K线图
- echarts画k线图(折线)
- echarts异步画k线图折线图
- 什么是K线图,怎么看K线图
- k线图表
- 如何分析K线图
- K线图经典图解
- K线图基础专题
- 怎样看K线图
- JavaScript省市二级联动
- 代码片段-Thymeleaf常见用法(六)
- Hadoop大数据平台入门——HDFS和MapReduce
- web.右键菜单.随笔
- C++:向上转型
- Matlab画k线图
- Java的参数传递
- LINUX网卡收到包,进程收不到包
- 547. Friend Circles
- Oracle12c多租户CDB 与 PDB 参数文件位置探讨、查询CDB 与 PDB 不同值的参数
- 用大白话聊聊分布式系统
- typedef
- 在win10下安装terminator使用bash
- liunx shell基础四之运算