Rank: Member
Groups: Registered, Registered Users, Subscribers Joined: 12/20/2005(UTC) Posts: 11 Location: Australia
|
Hi Folks
I am trying to plot displaced (2 stdev) simple moving averages (14 day) over a given lookback period (eg 60 days) from a given date enterd as an input, so that the bands catch 95% of the price action over the lookback period.
The credit for the idea goes to Jose Siva - while playing around with his Linear Regression Trendline & Bands codes but trying to unravel his very clever code has got me beat. The issue for me is trying to nail the beginning and end of the plot.
Below is the template for what I am tryig to do - have removed all my unsuccessful code clutter to make it easier to follow (I hope). If anyone has any suggestions I would very much appreciate it. The attached picture may or may not help to clarify the objective. (BTW I have overlayed Jose's plot Linear Regression Trendline & Bands as an indicator of the target area if that helps)
Thanks in anticipation to anyone who can nudge me in the right direction.
{User Inputs}
pds:=14;
LookBk:= 60;
Day1 := Input("Day",1,31,5);
Month1 := Input("Month",1,12,2);
Year1 := Input("Year",1900,2400,2002);
FstDate:=DayOfMonth() = Day1 AND Month() = Month1 AND Year() = Year1;
BkDays:= Ref(FstDate, LookBk);
MA:= Mov(C,Pds,S);
{ End date point - Credit to Jose Silva}
end:=Year()>Year1
OR (Year()=Year1 AND (Month()>Month1
OR Month()=Month1 AND DayOfMonth()>=Day1));
end:=end AND Alert(end=0,2);
end:=If(LastValue(Cum(Ref(end,pds)))=0, LastValue(Cum(1))=Cum(1),end);
{ Moving Average end-point }
lastValMA:=LastValue(Highest( If(end, Mov(C,Pds,S),0)));
{ MA Segment }
MaSeg:=Ref(Ref(MA,-LookBk),LookBk);
{main}
{ Envelope bands }
offset:= 2 * Stdev(H - MA, LookBk);
HiBand:= MA+offset;
LoBand:= MA-offset;
{Plot}
MA ; HiBand; LoBand;
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users Joined: 8/13/2005(UTC) Posts: 170
Thanks: 7 times
|
Dear Ed;
Jose dose not need to baffle "{Does not Work!!! Is just the MA} " if an exponential MA is used then many a times the
Exploration Report will vary than that in chart,moreover if you use "MaSeg:=Ref(Ref(MA,-LookBk),LookBk); " it is just
backward & forward referencing to fortify the exact segment /period ,which is Jose's way of removing Ghost.
However you may have missed one Line ,because there is no use of 1st line "Pct:= 5; " in the entire body of the code
i assume you wanted to use that in 23rd & 24th line.Moreover there is no defined variable as Midband ,which i believe
you wanted to use,after the line MaSeg, with values derived from (Jose's MaSeg + user input Pct) .Kindly rectify your code & post to benifit us from your effort & endeveour.
Regards
Asish
|
|
|
|
Rank: Member
Groups: Registered, Registered Users, Subscribers Joined: 12/20/2005(UTC) Posts: 11 Location: Australia
|
Hi Asish
Far be it for me to criticize Jose - the comment was for my benefit - not intended in any way to be derogitory. I have had number of attempts to solve this with varying code, and what I do to perhaps aid my request is to strip out my unsuccessful attempts at coding, in this case I overlooked some of the offending code. I do this as I am time poor and sometimes comments to myself help recall what has or has not been achieved, when I come back to the issue after some weeks between attemps.
I have edited the above and removed the uneccessary code, as per your request.
Ed
|
|
|
|
Rank: Member
Groups: Registered, Registered Users, Subscribers Joined: 12/20/2005(UTC) Posts: 11 Location: Australia
|
The code is a part solution but I cannot seem to stop the plot at the end of the input date - has anyone a suggestion as to how I might go about this? I don't quite understand what the countback is doing other than Jose uses it for calculating the gradient of the linear regression slope of the segment.
{ Linear Regression Trendline & Bands v4.0 }
{ ©Copyright 2004-2005 Jose Silva }
{ For personal use only }
{ http://www.metastocktools.com
RE: http://www.metastocktool...etaStock/LinRegTrend.txt
Modified }
{User Inputs}
pds:=14;
LookBk:= 60;
Day1 := Input("Day",1,31,5);
Month1 := Input("Month",1,12,2);
Year1 := Input("Year",1900,2400,2002);
FstDate:=DayOfMonth() = Day1 AND Month() = Month1 AND Year() = Year1;
BkDays:= Ref(FstDate, LookBk);
MA:= Mov(C,Pds,S);
{ End date point - Credit to Jose Silva}
end:=Year()>Year1
OR (Year()=Year1 AND (Month()>Month1
OR Month()=Month1 AND DayOfMonth()>=Day1));
end:=end AND Alert(end=0,2);
end:=If(LastValue(Cum(Ref(end,LookBk)))=0, LastValue(Cum(1))=Cum(1),end);
{ Moving Average end-point }
lastValMA:=LastValue(Highest( If(end,MA,0)));
adjust:=LastValue(LastValue(Cum(1))-Highest(If(end,Cum(1),0)));
countback:=LastValue(Cum(1))-Cum(1)-adjust;
{ Rem next line to extend plot to end of chart }
countback:=Ref(Ref(countback,-adjust),adjust);
{ MA Segment }
restrict:=adjust-(LastValue(Cum(1))-lookbk);
MaSeg:=Ref(Ref(MA,- restrict), restrict);
{main}
{ Envelope bands }
offset:= 2 * Stdev(H - MA, LookBk);
HiBand:= MA+offset;
LoBand:= MA-offset;
{Plot}
maseg;
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users Joined: 1/19/2005(UTC) Posts: 1,065 Location: Koh Pha-Ngan, Earth
Was thanked: 2 time(s) in 2 post(s)
|
ed wrote:The code is a part solution but I cannot seem to stop the plot at the end of the input date - has anyone a suggestion as to how I might go about this?
Maybe this post can be of help.
jose '-
|
|
|
|
Rank: Member
Groups: Registered, Registered Users, Subscribers Joined: 12/20/2005(UTC) Posts: 11 Location: Australia
|
Thanks Jose
but I am still at a wall - in the original "Linear Regression Trendline & Bands" indicator, as far as I can tell the restriction of the plot hinges on LastValRI (which is relabelled as lastValMA above), and also lastValLRS which contructs the restricion in LR:=lastValLRI-lastValLRS*countback;
lastValLRS:=LastValue(Highest( If(end,LinRegSlope(x,pds),-10000)));
and the restricted plot is given by LRT:=Ref(Ref(LR,-restrict),restrict);
All my attempts seem to fail - like sqeezing the middle of a tube of toothpaste - the plot goes off to one end or the other on the chart. I cannot seem to get it to restrict.
I seem to have the same issue with modifying the "Display plot restiction indicator" as per your suggestion when I base the plot on the end date looking back x (ie 60) days from the end date.
Tried to set start:=Ref(end, -60) rather than an input date?
Hope this makes some sense
Ed
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users Joined: 1/19/2005(UTC) Posts: 1,065 Location: Koh Pha-Ngan, Earth
Was thanked: 2 time(s) in 2 post(s)
|
Sorry Ed - I've got no idea as to what you are trying to do.
jose '-)
|
|
|
|
Rank: Member
Groups: Registered, Registered Users, Subscribers Joined: 12/20/2005(UTC) Posts: 11 Location: Australia
|
Jose
appologies for not replying sooner, but to simplify things, I am trying to do what you have coded in the "display plot restriction" indicator, but with only and end date (input) and a lookback period to calculate the start date in the indicator itself.
This will make a very useful tool for visual inspection when focusing on small sections of a chart and varying parameters such as your plot:=Mov(C,5,E); in what if situations.
I hope that this explanation is a little clearer.
Ed
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users Joined: 1/19/2005(UTC) Posts: 1,065 Location: Koh Pha-Ngan, Earth
Was thanked: 2 time(s) in 2 post(s)
|
Ed, I'd like to help you, but unfortunately I can't find the extra time required to deal with the difficult intricacies of posting code, images and links in this new forum.
Check out the "Indicator plot restriction" code available from MetaStockTools.com.
jose '-)
|
|
|
|
Rank: Member
Groups: Registered, Registered Users, Subscribers Joined: 12/20/2005(UTC) Posts: 11 Location: Australia
|
Thanks Jose
I'll keep plugging away at it - until I get something happening.
Cheers
Ed
|
|
|
|
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.