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

Notification

Icon
Error

Options
Go to last post Go to first unread
Derek Worswick  
#1 Posted : Wednesday, May 24, 2017 10:53:18 AM(UTC)
Derek Worswick

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 8/11/2005(UTC)
Posts: 104

Hi Equis Formual Assatance

I would like to Extend the Trend Line in the Formula below past the Second date 

to the Last Data Point on the Chart     i.e. extend plot to end of chart

Hoping you can oblige

Thanking you in advace

Derek

Code:

======================
Trendline - date range
======================
---8<--------------------------

{ Trendline - date range v3.0

©Copyright 2002~2006 Jose Silva.  For personal use only.  All code remains the property of Jose Silva.  http://www.metastocktools.com }

{ Dates user input } StDay:=Input("start Day",1,31,1); StMnth:=Input("start Month",1,12,1); StYear:=Input("start Year",1800,2200,2006); EnDay:=Input("end Day",1,31,1); EnMnth:=Input("end Month",1,12,6); EnYear:=Input("end Year",1800,2200,2006);

{ Selected date periods } start:=Year()>StYear  OR (Year()=StYear AND (Month()>StMnth  OR Month()=StMnth AND DayOfMonth()>=StDay)); end:=Year()<EnYear  OR (Year()=EnYear AND (Month()<EnMnth  OR Month()=EnMnth AND DayOfMonth()<=EnDay));

{ Date signals } date1:=start AND Alert(start=0,2); date2:=end=0 AND Alert(end,2); date2:=Zig(end AND Cum(1)>1,1,$)=1;

{ Restrict out of range dates to chart } date1:=If(LastValue(Cum(date1))>0,date1,  Cum(1)=1); date2:=If(LastValue(Cum(date2))>0,date2,  LastValue(Cum(1))=Cum(1));

{ Sort dates in chronological order } dateOk:=LastValue(BarsSince(date1))  >LastValue(BarsSince(date2)); day1:=If(dateOk,date1,date2); day2:=If(dateOk,date2,date1);

{ Data Array type, levels } dataArray:=C; price1:=ValueWhen(1,day1,dataArray); price2:=LastValue(ValueWhen(1,day2,dataArray));

{ Trendline definition } x1:=LastValue(BarsSince(day1)); x2:=LastValue(BarsSince(day2)); trendline:=price1  +BarsSince(day1)*(price2-price1)  /Max(x1-x2,.000001);

{ Rem next line to extend plot to end of chart } trendline:=Ref(Ref(trendline,-x2),x2);

{ Plot on price chart } trendline

---8<--------------------------

wabbit  
#2 Posted : Thursday, May 25, 2017 12:13:12 AM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
Have a look at line 38 of the code (above), especially the part where it says, "Rem next line to extend plot to end of chart" Remove or comment-out line 39.
mstt  
#3 Posted : Thursday, May 25, 2017 8:23:33 AM(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 Derek Wabbit is correct. Some folk might not have understood how this line of code works. The inner Ref() function first moves the earlier Trendline result to the right, and in the process loses data off the right side of the chart. The outer Ref() function then moves the modified trendline to the left but without the data that was shifted beyond the last data bar. Simple but effective. Roy
Derek Worswick  
#4 Posted : Thursday, May 25, 2017 10:50:59 AM(UTC)
Derek Worswick

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 8/11/2005(UTC)
Posts: 104

Hi  Wabbit & Roy

Thank you both very much for your help and expiation of

 trendline:=Ref(Ref(trendline,- x2),x2);

It is good to hear from you both on the forum

​​​​​​​Best regards

Derek

Users browsing this topic
Guest (Hidden)
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.