Entropy Indicator in TradeStation using Matlab: TradeStation TS.Entropy Indicator
Here is an example of computation of entropy in TradeStation using matlab
| EasyLanguage: | {******************************************************************* Name: TS.MATLAB.Entropy Analysis Type: Indicator Description: An example of using Matlab into Tradeststion Used: TS.MATLAB.LINK.dll Provided By: Trade Smart Research (c) Copyright 2001 - 2005 www.tsresearch.com *******************************************************************} Input: Length(500), q(1); {create array x and add new value} if currentbar = 1 then begin Value1 = TS.MATLAB.LINK("x = ["+ NumToStr(C,4)+" ]"); end else begin {add next value to array} Value1=TS.MATLAB.LINK("x=[x "+ NumToStr(C,4) +" ]"); if currentbar > Length then {if array > our periods (length) then delete first element from array} Value1=TS.MATLAB.LINK("x(1)=[]"); {calculating TSentropy.m function} Value1=TS.MATLAB.LINK("TSentropy(x,"+NumToStr(q,2)+")"); end; Plot1(value1, "Entropy"); {***** Copyright (c) 2001-2005 Trade Smart Research, Ltd. All rights reserved. www.tsresearchgroup.com ***** ***** Trade Smart Research reserves the right to modify or overwrite this analysis technique with each release. *****} |
| Matlab: | function entr = TSentropy(x, q) % TSentropy estimates the entropy of signals . % entr : The entropy estimate % q : input parameter, q >=1; % x : The time series to be analyzed % q : Tsallis non-extensive parameter value, q >=1; % if q=1 then Tsallis' entropy concides with Shannon's % http://www.TSResearch.com % D. Tolstonogov % Copyright (c) by Trade Smart Research % 08/04/2004 [NRow,NCol]=size(x); if NRow~=1 x=x'; end; % The number of cells of the histogram minx=min(x); maxx=max(x); delta=(maxx-minx)/(length(x)-1); ncell=ceil(sqrt(length(x))); % histogram h = hist(x, ncell); entr=0; count=0; % Shannon's entropy if q==1 for n=1:ncell if h(n)~=0 hn=log(h(n)); else hn=0; end; count=count+h(n); entr=entr-h(n)*hn; end; entr=entr/count+log(count); else % Tsallis entropy for n=1:ncell hn=(h(n))^q; count=count+h(n); entr=entr+hn; end; entr=entr/(count)^q; entr=(1-entr)/(q-1); end; |
|