[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Correlation Index/RSI - AFL Indicators



PureBytes Links

Trading Reference Links

Attached are two AFL Indicators that I've been experimenting with that 
some of you may find of interest. They are intended for those of us who 
are dabbling with AFL code and exploring its possibilities.

My aim was to explore the 'Correlation' function and what I could use it 
for. This code, draws an indicator that compares stock data with an 
index (or other data). It attempts to identify if the stock price 
trends have any similarity with, or opposite movement to, that index (or 
other data).

So the closer the indicator is to +100% the closer the synchronicity of 
the data - ie similar tendency/trend. Conversely, the closer to -100% 
the indicator the more dissimilar the data - ie the two data sources 
tend to move in opposite directions to each other. I have found it 
useful in spotting divergences.

Of course, this is not a new idea and there must be many texts already 
written on this kind of indicator. There is also its clear relationship 
with the Relative Strength Indicator in its comparison with an index.

An explanation of each line of code follows for novices, I hope its 
helpful and apologise in advance if it's too simplistic :-)
====================================================
periods = 50 ;
/* 'Periods' are the number of days/ticks/bars chosen. The 'periods' 
variable has been used so that it can easily be adjusted without having 
to change other lines of code further down. The number can be changed 
to suit the user - lower is more sensitive, higher is smoother. 
'Periods' holds this value for later use. */

index = foreign( "UKX2", "close" ) ;
/* The 'Index' variable will hold the close value of the index (UKX2 in 
UK - change these letters to whatever your index ticker code is for your 
country). The 'foreign' function searches for the close value of the 
index and it is placed in 'index' for later use. */

graph0 = 100 * correlation( close, index, periods ) ;
/* 'graph0' is also a variable that will hold the result of the formula 
after the equals sign. Additionally, whatever is held in 'graph0' will 
be plotted on the graph. The Correlation function compares the selected 
stocks 'close' price with the 'index' close value over the number of 
'periods' originally chosen by the user. This calculation will produce 
a value between -1 and +1 and is multiplied by 100 to turn it into a 
percentage for the graph. */

title = name() + " Correlation Index (" + writeval( periods, 1.0 ) + ")"

+ writeval( graph0 ) + "%" ;
/* The 'title' variable will hold, and display on the graph, the 
name/ticker of the selected stock, PLUS the text placed in quotes, PLUS 
the value of 'periods' placed in parentheses, PLUS the current value of 
the 'graph0' variable, PLUS a percentage sign - because the correlation 
value was multiplied by 100.
====================================================


Peter


[ Section: 1/1 File: Correlation_Index.afl UUencoded by: Turnpike 6.00 Beta 4 ]

begin 644 Correlation_Index.afl
M+RH@($-/4E)%3$%424].($E.1$58(&)Y(%!E=&5R($-A<G(@,R!*=6YE(#(P
M,#$-"B`@("`@2...:6-A=&5S($-O<G)E;&%T:6]N(&)E='=E96X@<V5L96-T
M960@xxxx@86YD('1H92!-86EN($EN9&5X#0H@("`@($%L<V\@<')O=FED
M97,@8...@:6YD:6-A=&EO;B!O9B!D:79E<F=E;F-E<R!B971W965N('1H92!D
M871A#0H@("`@(%)E<&QA8V4@xxxx,B!W:71H('EO=7(@;W=N(&EN9&5X+W-T
M;V-K('1I8VME<@T*("`@("!3970@xxxx;&EN9R!T;R!!=71O;6%T:6,L($=R
M:60@xxxx&EN97,@=&\@3&5V96P@,"P@xxxx&5R8V5N="!A;F0@xxxx&QE#0H@("`@
M($%D:G5S="!P97)I;V1S(&9O<B!S96YS:71I=FET>2!O9B!R97-P;VYS90T*
M("`@("!!(&-O<G)E;&%T:6]N(&]F(#$N,"`H,3`P)2D@:6YD:6-A=&5S(&)O
M=&@@9&%T82!A<F4@<&5R9F5C=&QY('-Y;F-R;VYI<V5D("AP;W-I=&EV92!C
M;W)R96QA=&EO;BD-"B`@("`@0...!C;W)R96-L871I;VX@;V8@+...$N,"`H+3$P
M,"4I(&EN9&EC871E<R!D871A(&AA=F4@xxxx!P97)F96-T(&)U="!O<'!O<VET
M92!S>6YC<F]N;W5S(')E;&%T:6]N<VAI<"`H:6YV97)S92!O<B!N96=A=&EV
M92!C;W)R96QA=&EO;BD-"B`@("`@0...!C;W)R96QA=&EO;B!O9B`P+C`@:6YD
M:6-A=&5S(&YO('-Y;F-R;VYI<V%T:6]N(&%T(&%L;"`@*B\-"@T*<&5R:6]D
M<R`](#4P(#L-"FEN9&5X(#T@xxxx]R96EG;B@@(E5+6#(B+"`B8VQO<V4B("D@
M.PT*9W)A<&@P(#T@,3`P("H@xxxx]R<F5L871I;VXH(&-L;W-E+"!I;F1E>"P@
M<&5R:6]D<R`I(#L-"@T*=&ET;&4];F%M92@xxxx("L@(B!#;W)R96QA=&EO;B!)
M;F1E>"`H(B`K('=R:71E=F%L*"!P97)I;V1S+"`Q+C`@*2`K("(I(B`-"BL@
:=W)I=&5V86PH(&=R87!H,"`I("L@(B4B(#L`
`
end

sum -r/size 44263/1254 section (from "begin" to "end")
sum -r/size 30151/881 entire input file

[ Section: 1/1 File: Correlation_RSI.afl UUencoded by: Turnpike 6.00 Beta 4 ]

begin 644 Correlation_RSI.afl
M+RH@($-/4E)%3$%424].(%)322!B>2!0971E<B!#87)R(#,@2...`R,#`Q
M#0H@("`@($EN9&EC871E<R!#;W)R96QA=&EO;B!B971W965N('-E;&5C=&5D
M(%-T;V-K(&%N9"!24TD@xxxx%L=64-"B`@("`@0...;R!P<F]V:61E<R!A;B!I
M;F1I8V%T:6]N(&]F(&1I=F5R9V5N8V5S(&)E='=E96X@=&AE(&1A=&$-"B`@
M("`@4...(%-C86QI;F<@=&\@075T;VUA=&EC+"!'<FED($QI;F5S('1O($QE
M=F5L(#`L(%!E<F-E;G0@xxxx($UI9&1L90T*("`@("!!9&IU<W0@<&5R:6]D
M<R!F;W(@<V5N<VET:79I='D@;V8@<F5S<&]N<V4-"B`@("`@0...!C;W)R96QA
M=&EO;B!O9B`Q+C`@*#$P,"4I(&EN9&EC871E<R!B;W1H(&1A=&$@8...)E('!E
M<F9E8W1L>2!S>6YC<F]N:7-E9"`H<&]S:71I=F4@xxxx]R<F5L871I;VXI#0H@
M("`@0...]R<F5L871I;VX@/"`Q+C`@*#P@,3`P)2D@:6YD:6-A=&5S(&1E8W)E
M87-I;F<@;&5V96QS(&]F('-Y;F-R;VYI<V%T:6]N("T@xxxx@:6YC<F5A<VEN
M9R!D:79E<F=E;F-E("`J+PT*#0IP97)I;V1S(#T@,30@xxxx*4E-)=F%L(#T@
M4E-)*"`Q-"`I(#L-"F=R87!H,"`](#$P,"`J(&-O<G)E;&%T:6]N*"!C;&]S
M92P@xxxx)=F%L+"!P97)I;V1S("D@xxxx*#0IT:71L93UN86UE*"D@*R`B($-O
M<G)E;&%T:6]N(%)322`H(B`K('=R:71E=F%L*"!P97)I;V1S+"`Q+C`@*2`K
C("(I(B`-"BL@=W)I=&5V86PH(&=R87!H,"`I("L@(B4B(#L`
`
end

sum -r/size 61598/1016 section (from "begin" to "end")
sum -r/size 13020/710 entire input file

--
======================================================================
Peter Carr
Email: pcarr@xxxx ICQ: 22586379
======================================================================