Jump to content

Welcome to the new Traders Laboratory! Please bear with us as we finish the migration over the next few days. If you find any issues, want to leave feedback, get in touch with us, or offer suggestions please post to the Support forum here.

  • Welcome Guests

    Welcome. You are currently viewing the forum as a guest which does not give you access to all the great features at Traders Laboratory such as interacting with members, access to all forums, downloading attachments, and eligibility to win free giveaways. Registration is fast, simple and absolutely free. Create a FREE Traders Laboratory account here.

wsam29

Linear Regression Channel

Recommended Posts

I have no clue how to upload the indicator so I'll just post the coding.

 

[LegacyColorValue = true];

{Updated by DJ Reda on Sat 4/16/05

Added option to use either Standard Deviation or Standard Error of Estimate to plotchannel bands}

{ // 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:

STD1_SEE2(2),

Length ( 50), { // Length of Linear Regression // }

Size(1),//Trend Line Thickness

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 ( Green), { // Color for Linear Regression Line // }

STDDevColor( Magenta), { // Color for Upper Boundary // }

SEEColor(Magenta) , { // Color for Lower Boundary // }

ExtRight ( false), { // 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 );

{++++++++New Code to Choose between plotting Std Dev or Std Error++++++}

If STD1_SEE2 = 1 then

SDev = StandardDev( Close, Length, 1 );

If STD1_SEE2 = 2 then begin //use Standard Error of Estimate

Value1 = StdError(Close, Length);

SDEV = Value1;

end;

{++++++++End New Code++++++}

 

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 );

 

{++++++++New Code to Choose between plotting Std Dev or Std Error++++++}

If STD1_SEE2 = 1 then

SDev = StandardDev( Close, Length, 1 );

If STD1_SEE2 = 2 then begin //use Standard Error of Estimate

Value1 = StdError(Close, Length);

SDEV = Value1;

end;

{++++++++End New Code++++++}

 

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 );

If STD1_SEE2 = 1 then begin

TL_SetColor( TL_UB, STDDevColor );

TL_SetColor( TL_LB, STDDevColor );

end;

If STD1_SEE2 = 2 then begin

TL_SetColor( TL_UB, SEEColor );

TL_SetColor( TL_LB, SEEColor );

end;

 

TL_SetSize(TL_LRV, size);

TL_SetSize(TL_UB, size);

TL_SetSize(TL_LB, size);

 

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 );

 

{++++++++New Code to Choose between plotting Std Dev or Std Error++++++}

If STD1_SEE2 = 1 then

SDev = StandardDev( Close, Length, 1 );

If STD1_SEE2 = 2 then begin //use Standard Error of Estimate

Value1 = StdError(Close, Length);

SDEV = Value1;

end;

{++++++++End New Code++++++}

 

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 // }

 

 

This indicator was sent to me from Pat B. from TTM

 

LRC

 

I'd attach some screen shots of how I use the LRC, but I have no clue what I'm doing.

LRC_01.thumb.jpg.fe600d59484b9c6a9be54ea4459066b9.jpg

LRC_02.thumb.jpg.1fdf27cb724afb0c6499efc41871f378.jpg

Share this post


Link to post
Share on other sites

I would like a way to use the linear regression lines like they are in eSignal, with an open source code or jump box so you can adjust the standard deviation, but coded for Tradestation. It's been proven that a linear regression/standard deviation of plus and minus 2 usually contains about 90% of the range of a stock, and a LR/SD +-3 contains approx. 98% of the range, so I'd like the code please for Tradestation 8.3 for those linear regression channels, but where it's comparable to eSigs and objective and draws the lines over the whole chart monthly, weekly etc., not like Tradestations that is subjective to where you have to put it in like Fib channels and twist it to make it fit, and can start out (on TS charts) from a place that is incorrect. If someone has some TS codes for objective lines for a whole chart for LR/SD +-2 and +-3, that would be great, and I would really appreciate it, and if it could be open source so it could be changed for LR/SD lines for charts for whatever you want, +-1, 1.5, 2.5, etc, some stocks deviate more or less than others, and you can find the outer reaches to which a stock has always been contained in(tempted to get eSig just for that and cleaner charts/trendlines), and would help to see why a stock stops in it's tracks to the bottom or top, even when it seems like it has broken out, or down.

 

Curtis

Share this post


Link to post
Share on other sites
Guest forsearch
I would like a way to use the linear regression lines like they are in eSignal, with an open source code or jump box so you can adjust the standard deviation, but coded for Tradestation. It's been proven that a linear regression/standard deviation of plus and minus 2 usually contains about 90% of the range of a stock, and a LR/SD +-3 contains approx. 98% of the range, so I'd like the code please for Tradestation 8.3 for those linear regression channels, but where it's comparable to eSigs and objective and draws the lines over the whole chart monthly, weekly etc., not like Tradestations that is subjective to where you have to put it in like Fib channels and twist it to make it fit, and can start out (on TS charts) from a place that is incorrect. If someone has some TS codes for objective lines for a whole chart for LR/SD +-2 and +-3, that would be great, and I would really appreciate it, and if it could be open source so it could be changed for LR/SD lines for charts for whatever you want, +-1, 1.5, 2.5, etc, some stocks deviate more or less than others, and you can find the outer reaches to which a stock has always been contained in(tempted to get eSig just for that and cleaner charts/trendlines), and would help to see why a stock stops in it's tracks to the bottom or top, even when it seems like it has broken out, or down.

 

Curtis

 

OK. We'll get right on that for ya, mate. :rofl:

 

BTW, have you tried looking over at the TS forum? You might find your answer there as well....:crap:

Share this post


Link to post
Share on other sites

Thanks for replying, sorry it took a little while to get back to you, I work nights and trade during the day. Guess what I'm looking for is a standard deviation channel like on this page:

http://ta.mql4.com/linestudies/standard_deviation_channel, based on a linear regression line, not an indicator or oscillator, but an overlay like Bollinger Bands or moving averages. The one at TS is hard to use and when I stretch regression channels around a linear regression line, no matter how skinny or wide I make the channel, it always says 2 SD (Open).

 

Investor/RT has another page which demonstrates what I'm looking for here:

http://www.linnsoft.com/tour/techind/linReg.htm, and I can put them in individually in TS if that's what it takes one by one, that's how I had to change parameters on slow shotastics and RSI to 5, 7, and 21, had to copy the original page and just change the numbers for different RSI screens.

 

Inv.R/T also has a follow-up page which shows linear regression forecast/bands similar to Bollinger bands for the E-mini; I don't do futures, just stocks & options, but this looks promising. The E-mini example of the linear reg. forecast/bands is at http://www.linnsoft.com/tour/techind/linRegForecast.htm, which shows this example: http://www.linnsoft.com/tour/techind/images/lrfKessler.jpg.

 

There is an Amibroker page with good ideas for a formula:http://www.amibroker.com/library/detail.php?id=438&hilite=IIF,

just need one for TS, and like I mentioned, I could change the individual #s and set up different Easy Language Documentsto be used like Bol. Bands if need be for each one like LR/SD 1, 1.5, 2.5, 3, 3.5, just would like a code for a linear regression with 2 standard deviations plotted off of it, just need a low number period to work with because I'll mostly be looking at it weekly and monthly more than that.

 

Esig has a page with people discussing formulas for plotting it, but they have and easy way with jumpboxes to adjust LR and SD and standard error to whatever you want, and the moving linear regression is not necessary, just would like cleaner pre-plotted LR/SD that I can change to gauge more about stocks and the market. Thanks for your help in advance, have to go to work right after the market closes like Tue. again today.

 

Curtis

Share this post


Link to post
Share on other sites

I would like a code for a chart overlay of standard deviation channels built on a base of a linear regression trend like Bollinger bands, with 2 standard deviations above and below the LR line. When it is attempted on TS, it's hard to use, unlike eSig and a few other platforms I've used before, which make it easy with jumpboxes where you can change the SD to 1, 2, 3, 5, 1.5,etc., and eSig has standard error. On TS, I can plot an objective LR line on daily, weekly, and monthly charts, the longer time frame seems more reliable, and when I try to use the regression channels with it, no matter how very skinny or extremely wide I make the channels, it always says 2 SD (Open), and I know that's not right. Metastock, Amibroker, Investor R/T, Esig has the best one, but they all have easy ways to plot the LR/SD +-2, 1, 3 overlays on charts, or whatever you want, but TS doesn't. Can you make a formula for a concrete overlay LR/SD channel of +-2 above and below a LR line so I can use it for D, W, and most important to me monthly charts, and show me where to change to couple-5 #s in the equation so I can make several screens of a few different numbers, sure there is no way to make a jumpbox like in other platforms. This is what I hope it will look like:

 

http://www.onlinetradingconcepts.com/TechnicalAnalysis/LinRegChannel.html

 

Except with the SD of 2 instead of 1.....Thanks in advance and I'll check back in another day or so, have to work nights again tomorrow, and am glued to the marker during the weekdays.

 

Curtis

Share this post


Link to post
Share on other sites

Thanks for posting that wsam29. That code does work, but I tried to change it to +3 & -3 standard deviation and just changed the #s on lines 8 and 9 that say NumDevsUp and NumDevsDn. Is that right or do I need to change other numbers in the code? Also the channel only works at the very right side of the charts, is there a way to get it to go all the way across the chart, mainly use it on monthly and weekly charts. Thanks for any help.

 

Curtis

Share this post


Link to post
Share on other sites

Hi Guys,

 

I am not very good at all with paisting indicators in multicharts, can someone please tell me how to copy and past that code into multicharts or maybe post the indicator.

Many thanks,

email

Share this post


Link to post
Share on other sites
Hi Guys,

I am not very good at all with paisting indicators in multicharts, can someone please tell me how to copy and past that code into multicharts or maybe post the indicator.

Many thanks,

email

 

 

Open PowerEditor,

 

select File > New

 

enter indicator name,

 

paste in code.

 

click Compile

Share this post


Link to post
Share on other sites

dear

I am not very good at all with paisting indicators in multicharts, could someone please just post the indicator.( EazyLanguageDocumenFile)

 

thank you very much

Share this post


Link to post
Share on other sites

dear traders

I am very bad at all with paisting indicators in multicharts, could someone please just post the indicator.( EazyLanguageDocumen File)

 

thank you very much

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.