Code covered by the BSD License  

Highlights from
Technical Analysis Tool

image thumbnail

Technical Analysis Tool


Phil Goddard (view profile)


29 Mar 2006 (Updated )

GUI for viewing various simple technical analysis indicators of a time series

function out = rsi(data,period)
% Function to calculate the Relative Strength Index of a data set
% 'data' is the vector to operate on.  The first element is assumed to be
% the oldest data.
% 'period' is the length of the Wilder Smoothing window.
% Example:
% out = rsi(data,period)

% Error check
if nargin ~=2 
    error([mfilename,' requires 2 inputs.']);
if ~(m==1 || n==1)
    error(['The first input to ',mfilename,' must be a vector.']);
if numel(period) ~= 1
    error('The Wilder smoothing period must be a scalar.');
if length(data) < period+1
    error('The data set must be at least 1 element longer than the requested RSI period.');

% calculate the up and down data changes
dd = diff(data);
uc = dd;
dc = dd;
dc = -dc;
% perform Wilder Smoothing
wuc = wildersmoothing(uc,period);
wdc = wildersmoothing(dc,period);
% calculate the RSI (taking account of nan's in wuc and wdc)
out = [nan*ones(period-1,1); 100-(100./(1+wuc(period-1:end)./wdc(period-1:end)))];

Contact us