log in     sign up for free
 
I turned from a loser to a winner when I was able to separate my ego needs from making money. When I was able to accept being wrong. Before that, admitting I was wrong was more upsetting than losing the money.
Marty Schwartz
 
 
Home
systems (284)
 
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

Standard Error Bands

Formula for: TradeStation

indicator


 

 

Views:  1963

Added: August 01, 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
 
Your Ad Here
To create the standard error bands described by Jon Andersen in "Standard Error Bands" in the September 1996 STOCKS & COMMODITIES, you must calculate the beta and alpha coefficients of the linear regression. First, create the calcB and calcA user functions, which refer to the beta and alpha coefficients. Be sure to create and verify these functions before building the indicator. Create calcB first, then calcA. These functions are used in calculating the regression coefficients for the standard error bands.


Type: User Function, Name: calcB
Inputs: Length(Numeric);
Vars: X(0);

X = BarNumber;

Value1 = Summation(X * Close, Length) - (Length * Average(X, Length) *Average(Close, Length));
Value2 = Summation(Square(X), Length) - (Length * Square(Average(X, Length)));

calcB = Value1/Value2;





Type: User Function, Name: calcA
Inputs: Length(Numeric);
Vars: X(0);

X = BarNumber;

calcA = Average(Close, Length) - (calcB(Length) * Average(X, Length));




Next, build the standard error bands indicator. The "length" value specifies the period of the linear regression line; the default is 21. The SDeg value specifies the smoothing factor that is used to smooth the linear regression and standard error bands; the default is 3.




Type: Indicator, Name: Std Error Bands Smooth
Inputs: Length(21), SDeg(3);
Vars: LinRegY(0), X(0), StdErr(0), LinRegS(0), SErr(0);

LinRegY = LinearRegValue(Close, Length, 0);
X = CurrentBar;

IF CurrentBar > Length then Begin
Value1 = (Summation(Square(Close), Length)) - ((calcA(Length) *
Summation(Close, Length))) - ((calcB(Length) *
Summation(X * Close, Length)));
Value2 = Length - 2;
StdErr = SquareRoot(Value1 / Value2);
LinRegS = Average(LinRegY, SDeg);
SErr = 2 * Average(StdErr, SDeg);

Plot1(LinRegS, "LinRegS");
Plot2(LinRegS + SErr, "+StdErrS");
Plot3(LinRegS - SErr, "-StdErrS");
End;






The indicator for the related %A standard error bands is built using the code below. It's best plotted with the bar type set to "histogram."


Type: Indicator, Name: Standard Error Bands %A

Inputs: Length(21), SDeg(3);
Vars: LinRegY(0), X(0), StdErr(0), LinRegS(0), SErr(0), PcntA(0);

LinRegY = LinearRegValue(Close, Length, 0);
X = CurrentBar;

IF CurrentBar > Length then Begin
Value1 = (Summation(Square(Close), Length)) - ((calcA(Length) *
Summation(Close, Length))) - ((calcB(Length) *
Summation(X * Close, Length)));
Value2 = Length - 2;
StdErr = SquareRoot(Value1 / Value2);
LinRegS = Average(LinRegY, SDeg);
SErr = 2 * Average(StdErr, SDeg);
PcntA = (Close - (LinRegS-SErr)) / ((LinRegS+SErr)-(LinRegS-SErr)) * 100;

Plot1(PcntA, "%A");
End;






This code is available at both the Omega Research Forum on America On-Line as well as at Omega's Web site.
-- Gaston Sanchez, Omega Research
Internet: http://www.omegaresearch.com

 

 



Code:

Type: User Function, Name: calcB
Inputs: Length(Numeric);
Vars: X(0);

X = BarNumber;

Value1 = Summation(X * Close, Length) - (Length * Average(X, Length) *Average(Close, Length));
Value2 = Summation(Square(X), Length) - (Length * Square(Average(X, Length)));

calcB = Value1/Value2;





Type: User Function, Name: calcA
Inputs: Length(Numeric);
Vars: X(0);

X = BarNumber;

calcA = Average(Close, Length) - (calcB(Length) * Average(X, Length));





Type: Indicator, Name: Std Error Bands Smooth
Inputs: Length(21), SDeg(3);
Vars: LinRegY(0), X(0), StdErr(0), LinRegS(0), SErr(0);

LinRegY = LinearRegValue(Close, Length, 0);
X = CurrentBar;

IF CurrentBar > Length then Begin
Value1 = (Summation(Square(Close), Length)) - ((calcA(Length) *
Summation(Close, Length))) - ((calcB(Length) *
Summation(X * Close, Length)));
Value2 = Length - 2;
StdErr = SquareRoot(Value1 / Value2);
LinRegS = Average(LinRegY, SDeg);
SErr = 2 * Average(StdErr, SDeg);

Plot1(LinRegS, "LinRegS");
Plot2(LinRegS + SErr, "+StdErrS");
Plot3(LinRegS - SErr, "-StdErrS");
End;







Type: Indicator, Name: Standard Error Bands %A

Inputs: Length(21), SDeg(3);
Vars: LinRegY(0), X(0), StdErr(0), LinRegS(0), SErr(0), PcntA(0);

LinRegY = LinearRegValue(Close, Length, 0);
X = CurrentBar;

IF CurrentBar > Length then Begin
Value1 = (Summation(Square(Close), Length)) - ((calcA(Length) *
Summation(Close, Length))) - ((calcB(Length) *
Summation(X * Close, Length)));
Value2 = Length - 2;
StdErr = SquareRoot(Value1 / Value2);
LinRegS = Average(LinRegY, SDeg);
SErr = 2 * Average(StdErr, SDeg);
PcntA = (Close - (LinRegS-SErr)) / ((LinRegS+SErr)-(LinRegS-SErr)) * 100;

Plot1(PcntA, "%A");
End;


 






Author: Jon Andersen
Source: http://www.activetradermag.com

 

View similar (indicator for TradeStation):

MACD\\Rise\\Fall
Seasonal SB
Volatility Quality Index
## Top & Bottom Indicator
Triangle Pattern Indicator
StochRSI
R - Squared
Distance Coefficient Ehlers Filter
HamnEggs
Hilbert Channel Indicator
...
 
 
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.
 
Privacy note | (c) copyrights systems4trading.com 2006-2012