Dear friends
Pl, convert this tradestaion code to Ami AFL for detection or measurement of current trend. This is very useful & most pofessionals like it . code given below----
R-Squared by Jack Karczewski
The r-squared calculation that Jack Karczewski focuses on in "Identifying market trends" is very useful in identifying trending and nontrending periods in the markets. This month, I'll present a revised version of the r-squared indicator given in Jon Andersen's September 1996 STOCKS & COMMODITIES article, "Standard error bands." I'll also include two PaintBar studies that identify trending and nontrending periods by painting the price bars. All three studies reference a function named "coeffR" for their basic calculation.
The "coeffR" function must be created and verified in the Power Editor prior to creating the studies. The EasyLanguage code for the function follows:
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;
The next step is to develop the r-squared indicator. The r-squared indicator plots the r-squared line as well as a zone for the trending and nontrending levels. In addition, a dot will be displayed on the r-squared line when it has been above/below a trending/nontrending level for a specified number of bars. The Length input determines the length of the r-squared calculation. The Smooth input allows for the r-squared line to be smoothed with a moving average. The Trend input determines the level above which the market is considered trending. The NoTrend input determines the level below which the market is considered nontrending. The RunLen input determines how many consecutive bars must be above/below the trending/nontrending levels in order for a mark to be placed on the r-squared line and an alert to be triggered. The suggested format settings are displayed after the EasyLanguage code.
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;
Pl, follow chart with attached pdf with this indicator.
Pl, convert this tradestaion code to Ami AFL for detection or measurement of current trend. This is very useful & most pofessionals like it . code given below----
R-Squared by Jack Karczewski
The r-squared calculation that Jack Karczewski focuses on in "Identifying market trends" is very useful in identifying trending and nontrending periods in the markets. This month, I'll present a revised version of the r-squared indicator given in Jon Andersen's September 1996 STOCKS & COMMODITIES article, "Standard error bands." I'll also include two PaintBar studies that identify trending and nontrending periods by painting the price bars. All three studies reference a function named "coeffR" for their basic calculation.
The "coeffR" function must be created and verified in the Power Editor prior to creating the studies. The EasyLanguage code for the function follows:
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;
The next step is to develop the r-squared indicator. The r-squared indicator plots the r-squared line as well as a zone for the trending and nontrending levels. In addition, a dot will be displayed on the r-squared line when it has been above/below a trending/nontrending level for a specified number of bars. The Length input determines the length of the r-squared calculation. The Smooth input allows for the r-squared line to be smoothed with a moving average. The Trend input determines the level above which the market is considered trending. The NoTrend input determines the level below which the market is considered nontrending. The RunLen input determines how many consecutive bars must be above/below the trending/nontrending levels in order for a mark to be placed on the r-squared line and an alert to be triggered. The suggested format settings are displayed after the EasyLanguage code.
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;
Pl, follow chart with attached pdf with this indicator.
Last edited: