ver important tradestation code for AFL

#1
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.
 
Last edited:

MurAtt

Well-Known Member
#4
Casoni,

Just by looking at the chart, I feel u've hit the hammer right on the head of the nail.

WoW ..
 
#5
Hi !!

This must be useful..

Hitesh

Dear hitesh

your given formula just like in ami library but problem is that it is not calculate exact R2 value, therefore lot of wrong trade will initiate. I want exact convertion of tradstation code to ami code . pl, provide.

As per tradstation code, Nifty detect No - trend Zone where as your given formula suggest strong up trend . You know in todays action tradstation given exact information. That why 99.99% professionals (fund manager & institutional players) play with tradstation R2 code.

Thanks

Pra
 

tlu

New Member
#10
Hi !!

This must be useful..

Hitesh
Yes, that's the formula I'm using, too. Just one hint: Somewhere in the Tradestation forum I once found a formula for calculating the r-squared critical value. It's surprisingly simple:

Crit=10/R2PDS *.4;

I'm not familiar with the maths behind this formula; its results, however, correspond very well with the values in the table (at least up to R2 periods of 50).
 

Similar threads