matlab画股票烛形图,matlab怎么画股票的成交量的图 实现红绿两种柱状图

function candle(hi,lo,cl,op,color,dates,dateform)

if nargin < 5

cls = get(gca,'colororder');

color = cls(1,:);

end

if nargin < 4

error('finance:candle:missingInputs',sprintf('Missing high, low, closing, or opening data.'))

end

[m,n] = size(hi);

if size(hi, 2) > 1 | size(lo, 2) > 1 | size(cl, 2) > 1 | size(op, 2) > 1,

error('finance:candle:invalidInputs',sprintf('Please specify input data as column vectors.'))

elseif size(hi, 1) ~= size(lo, 1) | size(lo, 1) ~= size(cl, 1) | size(cl, 1) ~= size(op, 1),

error('finance:candle:mismatchInputData','Number of data must be consistent across inputs.');

end

if nargin == 6 | nargin == 7,

if size(dates, 2) ~= 1,

error('finance:candle:invalidDateSize','DATES must be a column vector.');

elseif size(dates, 1) ~= size(hi, 1),

error('finance:candle:mismatchDatesData','Number of dates must correspond to number of data.');

end

end

back = get(gca,'color');

% Determine if current plot is held or not

if ishold

hldflag = 1;

else

hldflag = 0;

end

m = length(hi(:));

% Need to pad all inputs with NaN's to leave spaces between day data

tmp = nan;

nanpad = tmp(1,ones(1,m));

hilo = [hi';lo';nanpad];

index = 1:m;

indhilo = index(ones(3,1),:);

%plot(indhilo(:),hilo(:))

clpad = [cl(:)';nanpad];

clpad = clpad(:)';

oppad = [op(:)';nanpad];

oppad = oppad(:)';

for i=1:m

if cl(i)>=op(i)

plot(indhilo(:,i),hilo(:,i),'r');

hold on;

else

plot(indhilo(:,i),hilo(:,i),'b');

hold on;

end

end

% Create boundaries for filled regions

xbottom = index-0.25;

xbotpad = [xbottom(:)';nanpad];

xbotpad = xbotpad(:)';

xtop = index+0.25;

xtoppad = [xtop(:)';nanpad];

xtoppad = xtoppad(:)';

ybottom = min(clpad,oppad);

ytop = max(clpad,oppad);

% Plot lines between high and low price for day

hold on

% Plot box representing closing and opening price span

% If the opening price is less than the close, box is empty

i = find(oppad(:) <= clpad(:));

boxes(i) = patch([xbotpad(i);xbotpad(i);xtoppad(i);xtoppad(i)],...

[ytop(i);ybottom(i);ybottom(i);ytop(i)],...

'r','edgecolor','r');

% If the opening price is greater than the close, box is filled

i = find(oppad(:) > clpad(:));

boxes(i) = patch([xbotpad(i);xbotpad(i);xtoppad(i);xtoppad(i)],...

[ytop(i);ybottom(i);ybottom(i);ytop(i)],...

'b','edgecolor','b');

setappdata(gca,'plottype','Candle ')        % set tag for use with timeser.m

% Add support for providing dates.

if nargin == 6 | nargin == 7,

dateset = dates;

hcdl_vl = findobj(gca, 'Type', 'line');

hcdl_bx = findobj(gca, 'Type', 'patch');

% The CANDLE plot is made up of patch(es) and a line.  hcdl_vl is the

% handle to the vertical lines; it's actually only 1 line object.

% hcdl_bx contains the handle(s) of the patch object(s) that make up the

% empty and filled boxes.  The XData of those objects need to be changed

% to dates so that ZOOM works correctly.

line_xdata = get(hcdl_vl, 'XData');

set(hcdl_vl, 'XData', dateset(line_xdata));

for pidx=1:length(hcdl_bx),   % Need to do loop since there can be 1 or 2 patches.

patch_xdata = get(hcdl_bx(pidx), 'XData');

offset = [-0.25*ones(2, size(patch_xdata, 2)); ...

+0.25*ones(2, size(patch_xdata, 2))] * min(abs(diff(dateset)));

set(hcdl_bx(pidx), 'XData', dateset(round(patch_xdata))+offset);

end

% Change XTickLabel to date string format.

if ~exist('dateform', 'var') | isempty(dateform),

datetick('x');

else,

datetick('x', dateform);

end

end

% If original figure was not held, turn hold off

if ~hldflag

hold off

end

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值