Problem With DATES: Plotting Stock Chart And Lines From Excel Data

4 次查看(过去 30 天)
Hello!!!
I hope you can help me with this difficulty.
I have been trying to assign the Excel-exported matlab series date vector as the X axis tick labels. I am using a script to import a price data and then plot this data with the help of the CANDLE function. I try to plot a few more lines onto this chart. And have the original price series data to be used as the X axis label vector. I have two outcomes of this process:
1) I plot both the prices using the CANDLE function (using the CANDLE(HI, LO, CL, OP ) format) and the additional lines – FINE, except that the lower axis shows the usual integers in the ascending order – from 0 to 1000.
Code used:
candle(Num(7:end2,3),Num(7:end2,4),Num(7:end2,5),Num(7:end2,2),'k');
2) I plot the prices using the CANDLE function ( in the CANDLE(HI, LO, CL, OP, COLOR, DATES, DATEFORM) format, in which the DATES are the serial vector of the dates exported from Excel and converted into the Matlab format) BUT I cannot plot the rest of the lines over this chart. It shows only the candles…..
Code used:
candle(Num(7:end2,3),Num(7:end2,4),Num(7:end2,5),Num(7:end2,2),'k',matlabdate,'mmmyy');
I have not been able to “marry” the CANDLE(HI, LO, CL, OP, COLOR, DATES, DATEFORM) function with the usual LINE plots – the lines just refuse to plot over the candlestick charts with the dates on the x axis…I am not sure why….maybe this is because in this case the X axis starts at the serial dates much larger than the 0 origin used in with CANDLE(HI, LO, CL, OP ) format?
I also thought if it might be possible to use just the CANDLE(HI, LO, CL, OP ) format and then simply assign the labels over the x axis based on the MATLABDATE Date series vector?
I tried this with:
a=gca;
xtick=get(a,'xtick');
xticklabel=datestr(matlabdate,'yyyy/mm/dd');
set(a,'xticklabel',xticklabel);
And it does not seem to work…
I also used the
% dateaxis('x', 12, startdstr);
And it does not seem to work as well as it does not match the dates exported from the Excel….lagging the originals….
I hope you can help me with this problem. I need to ensure that the candlestick plots display the candles at the exactly the same times that are exported from excel and that the lines show up on this date-labeled chart as well. I hope this is possible
I will be happy to hear any opinion!!
Thank you for your time!)
D
PS: Here is the data file (press Request Download Ticket):
And the WHOLE script CODE:
[Num,Txt,Raw]=xlsread('testg2.xls');
end2=1200;
ntls=Num(6,2)+5;
figure(1);hold on;
grid;
ntls=Num(6,2)+5;
end2=1000;
date = Num(7:end2,56);
matlabdate= x2mdate(date);
datem=datestr(matlabdate);
startd=matlabdate(1,1);
startdstr=datestr(startd);
candle(Num(7:end2,3),Num(7:end2,4),Num(7:end2,5),Num(7:end2,2),'k');
% candle(Num(7:end2,3),Num(7:end2,4),Num(7:end2,5),Num(7:end2,2),'k',matlabdate,'mmmyy');
plot(Num(7:end2,1),Num(7:end2,6));
plot(Num(7:end2,1),Num(7:end2,8));
plot(Num(7:end2,1),Num(7:end2,10));
%candle(Num(7:end,3),Num(7:end,4),Num(7:end,5),Num(7:end,2),'k'); %,matlabdate,'DD.MM.YYYY')
% ch = get(gca,'children');
% set(ch(1),'FaceColor','r')
% set(ch(2),'FaceColor','g')
% a=gca;
% xtick=get(a,'xtick');
% xticklabel=datestr(matlabdate,'yyyy/mm/dd');
% set(a,'xticklabel',xticklabel);
% dateaxis('x', 12, startdstr);
% candle(Num(7:end,3),Num(7:end,4),Num(7:end,5),Num(7:end,2),'k'); %,matlabdate,'DD.MM.YYYY')
% ch = get(gca,'children');
% set(ch(1),'FaceColor','r')
% set(ch(2),'FaceColor','g')
% subplot(2,1,2);
% hold on;
% candle(Num(7:1000,3),Num(7:1000,4),Num(7:1000,5),Num(7:1000,2),'k'); %,matlabdate,'DD.MM.YYYY')
% plot (Num(7:1000,1),upb,'r'); % plots upper bollinger band
% plot (Num(7:1000,1),dnb,'b'); % plots lower bollinger band
% plot (Num(7:1000,3),upb,'r'); % plots upper bollinger band
% plot (Num(7:1000,3),dnb,'b'); % plots lower bollinger band
% [Movavgv, UpperBand, LowerBand] = bolling(closes,20,1);
% plot(Num(25:1000,1),Movavgv);
% TIME
% startDate = datenum('01-01-2009');
% a=gca;
% xtick=get(a,'xtick');
% xticklabel=datestr(matlabdate,'yyyy/mm/dd');
% set(a,'xticklabel',xticklabel);
% TIME END
% datetick('x','DD.MM.YYYY')
% startDate = datenum('01-01-2009');
% endDate = datenum('12-31-2009');
% xData = linspace(startDate,endDate,12);
print -dpng now.png -r250
  2 个评论
bym
bym 2011-10-23
FYI - matlab and excel use different epochs for dates:
matlab: Jan 0,0000
excel: Jan 1,1900
Dima
Dima 2011-10-23
yes thanks for your comment...I converted excel dates into matlab dates::
date = Num(7:end2,56);
matlabdate= x2mdate(date);

请先登录,再进行评论。

回答(1 个)

Dima
Dima 2011-10-24
Absolutely no way this can be resolved????
  1 个评论
Dima
Dima 2011-10-24
The whole problem can be summarized into the following question:
How do I plot additional time series over a candlestick chart generated with the help of the CANDLE function in the following format:
CANDLE(HI, LO, CL, OP, COLOR, DATES, DATEFORM)
thanks!!
because platting more data over a chart like this does not seem to work.
Thanks!!)

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Bar Plots 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by