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