PureBytes Links
Trading Reference Links
|
Wolfgang,
I assume that you mean a straight line.
I found this for you.
Marinus
=====================paste======================
{ // Note: Setting a begin date that is earlier than the amount of length
for the regression
will produce an extend to the left model that is date and time
restricted
The End Date must not be in the future // }
inputs:
Length ( 30), { // Length of Linear Regression // }
BeginDate ( 0 ), { // Choose Zero to use full length // }
BeginTime ( 0 ), { // Choose Zero to use full time // }
EndDate ( 0 ), { // Choose Zero for Current Day // }
EndTime ( 0 ), { // Choose Zero for Current Time // }
NumDevsUp ( 2 ), { // Standard deviations for upper // }
NumDevsDn ( -2 ), { // Standard deviations for lower // }
LRColor ( Blue ), { // Color for Linear Regression Line // }
UBColor ( Blue ), { // Color for Upper Boundary // }
LBColor ( Blue ), { // Color for Lower Boundary // }
ExtRight ( true ), { // Set to true to extend to right // }
ExtLeft ( false ); { // Set to true to extend to left // }
variables:
FirstDate ( 0 ),
FirstTime ( 0 ),
UpperBand ( 0 ),
LowerBand ( 0 ),
UpperBand_1 ( 0 ),
LowerBand_1 ( 0 ),
LRV ( 0 ),
LRV_1 ( 0 ),
TL_LRV ( 0 ),
TL_UB ( 0 ),
TL_LB ( 0 ),
Flag ( 0 ),
SDev ( 0 );
if BeginDate = 0 then
FirstDate = date[ Length - 1 ]
else
FirstDate = BeginDate;
if BeginTime = 0 then
FirstTime = time[ Length - 1 ]
else
FirstTime = BeginTime;
{ ///////////////////////////////////////////////////////////////////// }
if Flag = 0 then
begin
if ( EndDate = CurrentDate or EndDate = 0 ) and LastBarOnChart then
begin
LRV = LinearRegValue( Close, Length, 0 );
LRV_1 = LinearRegValue( Close, Length, Length - 1 );
SDev = StandardDev( Close, Length, 1 );
UpperBand = LRV + NumDevsUp * SDev;
LowerBand = LRV + NumDevsDn * SDev;
UpperBand_1 = LRV_1 + NumDevsUp * SDev;
LowerBand_1 = LRV_1 + NumDevsDn * SDev;
TL_LRV = TL_New( FirstDate, FirstTime, LRV_1, date, time, LRV );
TL_UB = TL_New( FirstDate, FirstTime, UpperBand_1, date, time,
UpperBand );
TL_LB = TL_New( FirstDate, FirstTime, LowerBand_1, date, time,
LowerBand );
Flag = 1 ;
end
else if date = EndDate and ( time = EndTime or EndTime = 0 ) then
begin
LRV = LinearRegValue( Close, Length, 0 );
LRV_1 = LinearRegValue( Close, Length, Length - 1 );
SDev = StandardDev( Close, Length, 1 );
UpperBand = LRV + NumDevsUp * SDev;
LowerBand = LRV + NumDevsDn * SDev;
UpperBand_1 = LRV_1 + NumDevsUp * SDev;
LowerBand_1 = LRV_1 + NumDevsDn * SDev;
TL_LRV = TL_New( FirstDate, FirstTime, LRV_1, date, time, LRV );
TL_UB = TL_New( FirstDate, FirstTime, UpperBand_1, date, time,
UpperBand );
TL_LB = TL_New( FirstDate, FirstTime, LowerBand_1, date, time,
LowerBand );
Flag = 2;
end;
if Flag = 1 or Flag = 2 then
begin
TL_SetColor( TL_LRV, LRColor );
TL_SetColor( TL_UB, UBColor );
TL_SetColor( TL_LB, LBColor );
TL_SetExtLeft( TL_LRV, ExtLeft );
TL_SetExtLeft( TL_UB, ExtLeft );
TL_SetExtLeft( TL_LB, ExtLeft );
TL_SetExtRight( TL_LRV, ExtRight );
TL_SetExtRight( TL_UB, ExtRight );
TL_SetExtRight( TL_LB, ExtRight );
end;
end
else
if Flag = 1 then
begin
LRV = LinearRegValue( Close, Length, 0 );
LRV_1 = LinearRegValue( Close, Length, Length - 1 );
SDev = StandardDev( Close, Length, 1 );
UpperBand = LRV + NumDevsUp * SDev;
LowerBand = LRV + NumDevsDn * SDev;
UpperBand_1 = LRV_1 + NumDevsUp * SDev;
LowerBand_1 = LRV_1 + NumDevsDn * SDev;
TL_SetBegin( TL_LRV, FirstDate, FirstTime, LRV_1 );
TL_SetBegin( TL_UB, FirstDate, FirstTime, UpperBand_1 );
TL_SetBegin( TL_LB, FirstDate, FirstTime, LowerBand_1 );
TL_SetEnd( TL_LRV, date, time, LRV );
TL_SetEnd( TL_UB, date, time, UpperBand );
TL_SetEnd( TL_LB, date, time, LowerBand );
end;
{ // Code modified from TradeStation indicator of LinearRegLine
by
Greg Ballard, 04/09/2003 // }
============end paste===============
|