log in     sign up for free
 
There are many different classifications of exits other than your initial stop loss. These include exits that produce a loss but reduce your initial risk, exits that maximize profits, and exits that keep you from giving back too much money, and psychological exits.
Van K. Tharp
 
 
Home
systems (285)
 
 
Special offer: buy MetaStock (try for free)   |   Reuters QuoteCenter Real-Time Data (get a free month)   |   EOD Data
Formula Library
 
AmiBroker
MetaTrader
MetaStock
TradeStation
Wealth-Lab
NinjaTrader
 
add your formula
System Library
 
 
Account login
Your email:
Password:
 
Log in
New to s4t? Sign up.
If you forgot your password click here.
Search the Web
 
Custom Search

R-Squared

Formula for: TradeStation

indicator

 

 

Views:  1570

Added: July 19, 2008
 
Rate this code:  Rate: 1 Rate: 2 Rate: 3 Rate: 4 Rate: 5
This formula has not been rated yet
 

email this link

 
 
Tags: TradeStation, indicator
 


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;






Style:

Plot Name Type Color Weight
Plot1 AvgSqrR Line Cyan thinnest
Plot2 Trend Line red thinnest
Plot3 NoTrend Line red thinnest
Plot4 Running Point white medium

Scaling: Screen
Properties: Enable Alert


This code is available at Omega Research's Web site. The name of the file is "RSqrd.ELA." Please note that all Traders' Tips analysis techniques posted at Omega Research's Web site can be utilized by both TradeStation and SuperCharts. Whenever possible, the posted analysis techniques will include both Quick Editor and Power Editor formats.


Gaston Sanchez, Omega Research
800 422-8587, 305 270-1095
Internet: http://www.omegaresearch.com

 

 



Code:


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;


 





Code to difficult? Find somebody to help you with coding here.

 



Author: Jack Karczewski
Source: http://www.traders.com

 

View similar (indicator for TradeStation):

Swing Wave Indicator
VIDYA
DBS-Where
Moving Average Adjuster
Point of Balance Oscillator
Volatility Quality Index
Kase Peak Oscillator
SMI Oscillator
Hull Moving Average
Keltner Bands
...
 
 
all formulas for TradeStation
all formulas

 

 

Email to friend

Top

 

     
However we try to maintain hiqhest possible level of service - most formulas, oscillators, indicators
and systems are submitted by anonymous users.
Therefore S4T™ does not take any responsibility for it's quality.
If you use any of this information, use it at your own risk. You are responsible for your own trading decisions.
Be sure to verify that any information you see on these pages is correct, and is applicable to your particular trade.
In no case will S4T™ be responsible for your trading gains or losses.
PayPalSecure payments by PayPal S4T™ is a part of TAURO EDUCATION NETWORK
 
Privacy note | (c) copyrights systems4trading.com 2006-2009