Traders Laboratory - View Single Post - 'Linear Regression Line' indicator in Tradestation
View Single Post
  #1 (permalink)  
Old 11-30-2007, 08:34 AM
Dogpile Dogpile is offline
Dogpile has no status.

 
Join Date: May 2007
Posts: 577
Thanks: 0
Thanked 7 Times in 5 Posts
'Linear Regression Line' indicator in Tradestation

any coding buffs know how to run a continually updating linear regression line off the adv-decl line since 1st bar of day?

I changed the code to make it work off the first bar of the day on regular 'price'... but my adv-decl line runs as an 'indicator' keying off the difference of Data1($Adv) & Data2 ($Decl). thus, is there a simple way to tell this indicator to run off another indicator rather than re-coding the entire thing to reference the difference of data1 & data2??

thx in advance.

Here is my current code (which is currently the canned 'Linear Reg Line' TS indicator with a small adjustment to run off the first bar of the day):

Quote:
inputs:

EndDate_YYMMDD( 0 ), { 0 or YYMMDD, constant; if EndDate_YYMMDD = 0,
EndTime_HHMM ignored and last bar on chart used }
EndTime_HHMM( 0 ), { 0 or HHMM, constant; EndTime_HHMM ignored if 0 }
Color( Yellow ),
ExtRight( true ) ;

variables:
EndDate( iff( EndDate_YYMMDD < 500000, EndDate_YYMMDD + 1000000,
EndDate_YYMMDD ) ),
LRV( 0 ),
LRVAgo( 0 ),
TLLRV( 0 ),
Flag( 0 ),
Length( 0 ),
firstbar(0);

if date>date[1] then begin
firstbar=currentbar;
end;

length=currentbar-firstbar;



if Flag = 0 then

{ Insert a lin reg line for the first time and set it's color and extents }

begin
if EndDate = 1000000 and LastBarOnChart then
begin
LRV = LinearRegValue( C, Length, 0 ) ;
LRVAgo = LinearRegValue( C, Length, Length - 1 ) ;
TLLRV = TL_New( Date[ Length - 1 ], Time[ Length - 1 ], LRVAgo, Date, Time,
LRV ) ;
Flag = 1 ;
end
else if Date = EndDate and ( Time = EndTime_HHMM or EndTime_HHMM = 0 ) then
begin
LRV = LinearRegValue( C, Length, 0 ) ;
LRVAgo = LinearRegValue( C, Length, Length - 1 ) ;
TLLRV = TL_New( Date[ Length - 1 ], Time[ Length - 1 ], LRVAgo, Date, Time,
LRV ) ;
Flag = 2 ;
end ;
if Flag = 1 or Flag = 2 then
begin
TL_SetColor( TLLRV, Color ) ;
TL_SetExtLeft( TLLRV, false ) ;
if ExtRight then
TL_SetExtRight( TLLRV, true )
else
TL_SetExtRight( TLLRV, false ) ;
end ;
end
else if Flag = 1 then

{ Reset the end-points of the flag-1 LRLine at each new bar after it has been drawn
for the first time; this effectively results in a new LRLine each time. }

begin
LRV = LinearRegValue( C, Length, 0 ) ;
LRVAgo = LinearRegValue( C, Length, Length - 1 ) ;
TL_SetBegin( TLLRV, Date[ Length - 1 ], Time[ Length - 1 ], LRVAgo ) ;
TL_SetEnd( TLLRV, Date, Time, LRV ) ;
end ;


{ ** Copyright (c) 1991-2003 TradeStation Technologies, Inc. All rights reserved. **
** TradeStation reserves the right to modify or overwrite this analysis technique
with each release. ** }
Attached Images
File Type: png VIX Regression Line.png (12.2 KB, 54 views)

Reply With Quote