Hello,
I would like to be able to create the Standard Error band Indicator as described below
It should draw the bands based on the linear regression indicator
Thank you
////////////////
Description
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
/////////////////////////
I would like to be able to create the Standard Error band Indicator as described below
It should draw the bands based on the linear regression indicator
Thank you
////////////////
Description
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
/////////////////////////