TREND DETECTION BY CALCULATING R-SQUARES

TREND DETECTION BY CALCULATING R-SQUARES

Type: Function, Name: coeffR

Inputs:
Length(Numeric);
Vars:
X(0),
UpEQ(0),
LowEQ1(0),
LowEQ2(0),
LowEQT(0);

X = BarNumber;
UpEQ = Summation(X * Close, Length) — (Length * Average(X, Length) * Average(Close, Length));
LowEQ1 = Summation(Square(X), Length) — (Length * Square(Average(X, Length)));
LowEQ2 = Summation(Square(Close), Length) — (Length * Square(Average(Close, Length)));
IF LowEQ1 * LowEQ2 > 0 Then
LowEQT = SquareRoot(LowEQ1 * LowEQ2);
IF LowEQT <> 0 Then
CoeffR = UpEQ / LowEQT;

Type: Indicator, Name: R-Squared

Inputs:
Length(30),
Smooth(1),
Trend(.7),
NoTrend(.3),
RunLen(10);

Vars: R(0),
SquareR(0),
AvgSqrR(0);

R = coeffR(Length);
SquareR = Square(R);
IF Smooth > 0 Then
AvgSqrR = Average(SquareR, Smooth)
Else
AvgSqrR = SquareR;
Plot1(AvgSqrR, «AvgSqrR»);
Plot2(Trend, «Trend»);
Plot3(NoTrend, «NoTrend»);
IF MRO(AvgSqrR > Trend, RunLen, RunLen) <> -1 OR
MRO(AvgSqrR < NoTrend, RunLen, RunLen) <> -1 Then Begin
Plot4(AvgSqrR, «Running»);
Alert = True;
End;

Подписаться
Уведомить о
0 комментариев
Межтекстовые Отзывы
Посмотреть все комментарии