function [rsi]=RSI_TS(price,longueur)

if size(price,2)>size(price,1)
    price=price';
end;
rsi=zeros(size(price,1),1);
coef=1/longueur;
netchg=coef*(price(longueur+1)-price(2));
totchg=coef*sum(abs(price(2:longueur+1)-price(1:longueur)));

for i=longueur+2:size(price,1)
    netchg=netchg+coef*(price(i)-price(i-1)-netchg);
    totchg=totchg+coef*((abs(price(i)-price(i-1)))-totchg);
    if totchg~=0 
        rsi(i)=50*((netchg/totchg)+1);
    else
        rsi(i)=0;
    end;
end;
rsi=round(100*rsi)*0.01;