{ If EndDate_YYMMDD = 0, this indicator inserts a lin reg line ending at the last bar on the chart at the time the indicator is applied to the chart (flag-1 line). Otherwise, it inserts a lin reg line ending at the bar with the specified date and time (flag-2 line). The flag-1 line is updated at each new real time bar; the flag-2 line is not updated - it is drawn only once. } // TS's LinRegLine code modified by John Hudson to draw channel boundaries at standard error distance from centerline and set colors and linestyles for different length channels. inputs: Length( 100), 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 } ExtRight(true) , Linewidth(0), Linestyle(3), NumDevs(2); variables: EndDate( iff( EndDate_YYMMDD < 500000, EndDate_YYMMDD + 1000000, EndDate_YYMMDD ) ), LRV( 0 ), LRVAgo( 0 ), TLLRV( 0 ), TLLRVHI(0), TLLRVLO(0), StdErrEnv(0), CumStdErr(0), AvgStdErr(0), EnvWidth(0), Flag( 0 ) ; StdErrEnv=NumDevs*StdError(C,Length); CumStdErr=CumStdErr + StdErrEnv; AvgStdErr=CumStdErr/Barnumber; 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 ) ; TLLRVHI = TL_New(Date[Length - 1], Time[Length-1],LRVAgo+IFF(StdErrEnv 50 and Length <=100 then TL_SetColor( TLLRV, Green); if Length > 100 and Length <=200 then TL_SetColor(TLLRV, Cyan); if Length > 200 and Length <=400 then TL_SetColor(TLLRV, BLUE); if Length > 400 and Length <=800 then TL_SetColor(TLLRV, Yellow); if Length > 800 then TL_SetColor(TLLRV, White); TL_SetColor( TLLRVHI, Green ); TL_SetColor( TLLRVLO, Red ); TL_SetSize(TLLRV, Linewidth); TL_SetSize(TLLRVHI, Linewidth); TL_SetSize(TLLRVLO, Linewidth); TL_SetStyle(TLLRVHI, Linestyle); TL_SetStyle(TLLRVLO, Linestyle); TL_SetExtLeft( TLLRV, false ) ; TL_SetExtLeft( TLLRVHI, false ); TL_SetExtLeft( TLLRVLO, false ); if ExtRight then begin TL_SetExtRight( TLLRV, true ); TL_SetExtRight( TLLRVHI, true ); TL_SetExtRight( TLLRVLO, true ); end else begin TL_SetExtRight( TLLRV, false ) ; TL_SetExtRight( TLLRVHI, false ) ; TL_SetExtRight( TLLRVLO, false ) ; end; 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_SetBegin( TLLRVHI, Date[ Length - 1 ], Time[ Length - 1 ], LRVAgo+IFF(StdErrEnv