PureBytes Links
Trading Reference Links
|
> can someone help me to code an correlation indicator?
> If the RSI rises 5 days together with the price the indicator
> should have an value of +1 which shows the high correlation.
> On the other hand of course a negative correlation is -1.
The Pearson's R function that Bob posted is the mathematically
"correct" way to do it.
But if what you really want is something simple that scores a "win"
if both RSI & price go up (even if RSI goes up 0.0001 and price goes
up 1000) and vice-versa, you could do something like this:
inputs: Price(Close), Length(5), RSIlen(9);
vars: RSIval(0), Score(0), Correl(0);
RSIval = RSI(C,Length);
Score = iff((Price > Price[1] and RSIval > RSIval[1])
or (Price < Price[1] and RSIval < RSIval[1]), 1, -1);
Correl = summation(Score, Length) / Length;
plot1(Correl, "Correl");
If I've got my code right, RSI seems to correlate pretty highly with
price.
Gary
|