logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
magiclaas  
#1 Posted : Tuesday, November 25, 2014 11:10:18 AM(UTC)
magiclaas

Rank: Advanced Member

Groups: Registered, Registered Users, Unverified Users
Joined: 9/18/2008(UTC)
Posts: 37

hi,

     i would like to plot a linear regression line from date to date... ( with the chance to extend it to the right...) and the chance to plot parallel reg line up and down .. per example + 5% 10% 15% and -5% -10% -15%

is it possible?

can you help me?

thank you very much

Luigi

mstt  
#2 Posted : Tuesday, November 25, 2014 9:07:57 PM(UTC)
mstt

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/25/2005(UTC)
Posts: 1,042

Was thanked: 57 time(s) in 54 post(s)
Hi Luigi Yes it's possible to do what you ask. However it will take me a little time to include all the features you ask for into the existing formula below. I'll attempt to include end dates and percentage off sets. With only 6 Input() functions to work with I may have to leave something out. {Linear Regression Trend Line} {Roy Larsen, 2006-2012, 8/6/12} N:=Input("Linear Regression Trend Line, Periods",2,9999,250); Ed:=Input("End Day-of-Month",1,31,31); Em:=Input("End Month",1,12,12); Ey:=Input("End Year ",1900,2020,2014); K:=Input("Trend Price 1=O 2=C 3=H 4=L 5=WC",1,5,2); D:=DayOfMonth(); M:=Month(); Y:=Year(); K:=If(K=1,O,If(K=2,C,If(K=3,H,If(K=4,L,WC())))); C1:=Cum(1); L1:=LastValue(C1); En:=(D>=Ed)*(M=Em)*(Y=Ey)+(Y>Ey)+(Y=Ey)*(M>Em)+(C1=L1); Sf:=LastValue(Cum(En)-1); Lb:=Cum(En)=1; Lr:=LastValue(ValueWhen(1,Lb,LinearReg(K,N))); Ls:=LastValue(ValueWhen(1,Lb,LinRegSlope(K,N))); Fb:=C1=1+L1-Sf-N; Fr:=Lr-N*Ls; St:=Cum(Fb)>0; Ln:=ValueWhen(1,Fb,Fr)+Cum(St)*LS; Ref(Ref(Ln,-Sf),Sf); Roy
magiclaas  
#3 Posted : Wednesday, November 26, 2014 8:43:25 AM(UTC)
magiclaas

Rank: Advanced Member

Groups: Registered, Registered Users, Unverified Users
Joined: 9/18/2008(UTC)
Posts: 37

Thank you very much. Luigi
magiclaas  
#4 Posted : Wednesday, November 26, 2014 8:52:48 AM(UTC)
magiclaas

Rank: Advanced Member

Groups: Registered, Registered Users, Unverified Users
Joined: 9/18/2008(UTC)
Posts: 37

.. well i ask you a little modification if possible:

I would like to emphasize what is important to me in this formula

ok the input trend line period and the last date

but i need to add the right extension!(from the last date)  and the parallel reg line up and down  5 10 15% of the reg line

thank you very much

 

mstt  
#5 Posted : Wednesday, November 26, 2014 11:27:38 PM(UTC)
mstt

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/25/2005(UTC)
Posts: 1,042

Was thanked: 57 time(s) in 54 post(s)
Hi Luigi It's difficult to incorporate all the requirements you have asked for. Nevertheless I have modified the first sample and it offers the options I thought you were looking for in your first post. To get the trend lines to extend to the most recent bar on the chart you can change the last 3 lines by substituting zero ("0") for "Shift". The purpose of the Ref() function in those lines is to shuffle the "Line" variable first right then left. This action converts the line extensions that you want to display into N/A results (no plots after the end date). (Example of last three lines without the "shuffle" function) Ref(Ref(Line,-0),0)*(1+(Offset/100)); Ref(Ref(Line,-0),0)*(1-(Offset/100)); Ref(Ref(Line,-0),0); Hope this helps. Roy {Linear Regression Trend Line} {Roy Larsen, 2014, 27/11/14} Offset:=Input("Linear Regression Trend Line, Percent Offset",0,100,5); StrD:=Input("Start Day / End Day, 1-31/1-31",1,3131,0131); StrM:=Input("Start Month / End Month, 1-12/1-12",1,1212,0112); StrY:=Input("Start Year",1900,2020,2013); EndY:=Input("End Year",1900,2020,2013); EndD:=LastValue(Int(Frac(StrD/99.99)*100)); EndM:=LastValue(Int(Frac(StrM/99.99)*100)); StrD:=LastValue(Int(StrD/100)); StrM:=LastValue(Int(StrM/100)); B:=Cum(1); L1:=LastValue(B); Start:=(DayOfMonth()>=StrD)*(Month()=StrM)* (Year()=StrY)+(Year()>StrY)+(Year()=StrY)*(Month()>StrM); End:=(DayOfMonth()>=EndD)*(Month()=EndM)* (Year()=EndY)+(Year()>EndY)+(Year()=EndY)* (Month()>EndM); B:=B=1; B:=BarsSince(B+Start)<BarsSince(B+End); B:=LastValue(Cum(B)+1); Shift:=LastValue(Cum(End)-1 ); Lb:=Cum(End)=1; LinR:=LastValue(ValueWhen(1,Lb,LinearReg(C,B))); LinS:=LastValue(ValueWhen(1,Lb,LinRegSlope(C,B))); Fb:=Cum(1)=1+L1-Shift-B; Fr:=LinR-B*LinS; St:=Cum(Fb)>0; Line:=ValueWhen(1,Fb,Fr)+Cum(St)*LinS; Ref(Ref(Line,-Shift),Shift)*(1+(Offset/100)); Ref(Ref(Line,-Shift),Shift)*(1-(Offset/100)); Ref(Ref(Line,-Shift),Shift);
magiclaas  
#6 Posted : Thursday, November 27, 2014 11:51:11 AM(UTC)
magiclaas

Rank: Advanced Member

Groups: Registered, Registered Users, Unverified Users
Joined: 9/18/2008(UTC)
Posts: 37

hi,

     thank you very much for your kindness,  maybe i forget something but as you can see in the attached pic

it does not seem to work as request

im not able to choose correctly start date end date and how to extend right..

then it seems that the up and down lines are not parallel as they should be...

is it a semplification if i tell you that i want to use this indicator on a monthly chart? for long time period?

maybe is it possible to create a simple trend reg line (with right extension) as present in metastock 10.1 as i have, and give the chance to create a parallel line multiplying by the required amount (up by 5% is 1.05, down by 5% multiplier is 0.95)

how can i attached a pictures here?

 if possible thank you

 

 

mstt  
#7 Posted : Thursday, November 27, 2014 6:43:14 PM(UTC)
mstt

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/25/2005(UTC)
Posts: 1,042

Was thanked: 57 time(s) in 54 post(s)
Hi Luigi To allow extensions of the "Line" variable the last three lines must be changed to ... Line*(1+(Offset/100)); Line*(1-(Offset/100)); Line; These outputs allow each line to extend to the right side of the chart. The upper and lower lines are not parallel because they are based on a plus or minus percentage of the primary trend line. I would need to lock in the price difference as at the end date rather than using a fixed percentage as at present. Don't know when I'll get time to make that and other changes that might still be necessary. The start day-of-month and the end day-of-month are combined in the first definition of the "StrD" variable. The first two digits represent the starting day-of-month, and the second two digits represent the ending day-of-month for the basic trend line. StrD:=Input("Start Day / End Day, 1-31/1-31",1,3131,0131); The start month-of-year and the end month-of-year are also combined in the first definition of the "StrM" variable. The first two digits represent the starting month-of-year, and the second two digits represent the ending month-of year. StrM:=Input("Start Month / End Month, 1-12/1-12",1,1212,0112); This is done because only 6 Input() functions can be used, and 7 would be required to enter all date details separately. There's one Input() function still available but that could be used later to switch the line extensions on or off. Once you understand how the dates are entered I'm sure you'll be able to operate the indicator quite easily. There's more work I'd like to do to improve the indicator but it's unlikely I'll have time to do that for at least two weeks. Roy
mstt  
#8 Posted : Thursday, November 27, 2014 11:15:35 PM(UTC)
mstt

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/25/2005(UTC)
Posts: 1,042

Was thanked: 57 time(s) in 54 post(s)
Hi Luigi I've modified the Trend Line indicator so that you can turn extensions on or off, and the offsets are now based on a fixed price rather than a fixed percentage (i.e. using the end-date price difference at the nominated percentage). There are still some questions in my mind about the indicator's accuracy but any fixes required really will have to wait. Roy {Linear Regression Trend Line} {Roy Larsen, 2014, 28/11/14} Offset:=Input("Linear Regression Trend Line, Percent Offset",0,100,5); StrM:=Input("Starting Month / Ending Month, 1-12/1-12",1,1212,0112); StrD:=Input("Starting Day / Ending Day, 1-31/1-31",1,3131,0131); StrY:=Input("Starting Year",1900,2020,2013); EndY:=Input("Ending Year",1900,2020,2013); Ext:=Input("Extend Trend and Offset Lines, 0=No 1=Yes",0,1,1); EndD:=LastValue(Int(Frac(StrD/99.99)*100)); EndM:=LastValue(Int(Frac(StrM/99.99)*100)); StrD:=LastValue(Int(StrD/100)); StrM:=LastValue(Int(StrM/100)); B:=Cum(1); L1:=LastValue(B); Start:=(DayOfMonth()>=StrD)*(Month()=StrM)* (Year()=StrY)+(Year()>StrY)+(Year()=StrY)*(Month()>StrM); End:=(DayOfMonth()>=EndD)*(Month()=EndM)* (Year()=EndY)+(Year()>EndY)+(Year()=EndY)* (Month()>EndM); B:=B=1; B:=BarsSince(B+Start)<BarsSince(B+End); B:=LastValue(Cum(B)+1); Shift:=LastValue(Cum(End)-1 ); Lb:=Cum(End)=1; LinR:=LastValue(ValueWhen(1,Lb,LinearReg(C,B))); LinS:=LastValue(ValueWhen(1,Lb,LinRegSlope(C,B))); Fb:=Cum(1)=1+L1-Shift-B; Fr:=LinR-B*LinS; St:=Cum(Fb)>0; Line:=ValueWhen(1,Fb,Fr)+Cum(St)*LinS; Shift:=LastValue(If(Ext,0,Shift)); B:=LastValue(ValueWhen(1,Lb,Line*(Offset/100))); Ref(Ref(Line,-Shift),Shift)+B; Ref(Ref(Line,-Shift),Shift)-B; Ref(Ref(Line,-Shift),Shift);
magiclaas  
#9 Posted : Friday, November 28, 2014 8:35:21 AM(UTC)
magiclaas

Rank: Advanced Member

Groups: Registered, Registered Users, Unverified Users
Joined: 9/18/2008(UTC)
Posts: 37

Thank you very much...it seems to work well...

anyway if you think that improvement can be done and you want to work on it.. you are welcome

thank you again

Users browsing this topic
Guest (Hidden)
Similar Topics
Slope of a Linear Regression Line (Formula Assistance)
by Patrick 8/19/2005 4:41:10 PM(UTC)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.