% ----- User inputs BEGIN -----
ticker_symbol=input('Enter the ticker symbol: ','s');
data_period=input('Enter the number of days of data to plot: ');
% ----- The following code will load data into the workspace -----
% ----- GIVE APPROPRIATE PATH FOR tickerdata.txt FILE -----
[date open high low close volume closeadj]=...
get_stock_data('C:\Users\CAMCAD\Desktop\tickerdata.txt',ticker_symbol,data_period);
if length(date)<data_period
data_period=length(date);
msg=['The data is available for ' num2str(data_period) ' days only.'];
disp(msg);
end
% ----------------------------------------------------------------
fsma_period=input('Enter the period (number of days) for computing fast SMA: ');
ssma_period=input('Enter the period (number of days) for computing slow SMA: ');
% ----- Enter the stock data variable for which -----
% ----- u want to compute slow and fast SMAs -----
disp('Stock data available: open, high, low, close and closeadj');
stock_data=input('Enter the stock data name: ');
% ----- User inputs END -----
% ----- Computation of fast and slow SMA using function 'npma' -----
% ----- the function 'npma' is stored as m-file titled 'npma.m' -----
fastSMA=npma(stock_data,fsma_period);
slowSMA=npma(stock_data,ssma_period);
% --------------------------------------------------------------------
% ----- Code to identify crossing points of fast SMA and slow SMA -----
% ----- The function x_point (x_point.m file) is used for this purpose ---
xing_from_below=[];
abscissa_below=[];
xing_from_above=[];
abscissa_above=[];
for i=1:length(date)-1
[absc fSMA f]=x_point(date(i:i+1),fastSMA(i:i+1),slowSMA(i:i+1));
if f==-1
abscissa_below=[abscissa_below absc];
xing_from_below=[xing_from_below fSMA];
elseif f==1
abscissa_above=[abscissa_above absc];
xing_from_above=[xing_from_above fSMA];
end
end
if length(abscissa_below)==0 & length(abscissa_above)==0
plot(date,close,'-k',...
date,slowSMA,'-b',...
date,fastSMA,'-r');
elseif length(abscissa_below)~=0 & length(abscissa_above)==0
plot(date,close,'-k',...
date,slowSMA,'-b',...
date,fastSMA,'-r',...
abscissa_below,xing_from_below,'gs');
elseif length(abscissa_below)==0 & length(abscissa_above)~=0
plot(date,close,'-k',...
date,slowSMA,'-b',...
date,fastSMA,'-r',...
abscissa_above,xing_from_above,'rs');
else
plot(date,close,'-k',...
date,slowSMA,'-b',...
date,fastSMA,'-r',...
abscissa_below,xing_from_below,'gs',...
abscissa_above,xing_from_above,'rs');
end
hold on;
grid on;
set(gca,'XTick',date);
set(gca,'XTickLabel',datestr(date,'mm/dd'));
legend('Closing price','Slow SMA','Fast SMA',0);
plot_title=['Technical Analysis of Stock Price History - ' ticker_symbol];
title(plot_title);
xlabel('Date ->');
ylabel('Stock Closing Price, Slow SMA, Fast SMA ->');
hold off;