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

Notification

Icon
Error

Options
Go to last post Go to first unread
DavidF  
#1 Posted : Thursday, February 18, 2016 3:55:47 PM(UTC)
DavidF

Rank: Member

Groups: Registered, Registered Users
Joined: 2/8/2014(UTC)
Posts: 11

Thanks: 1 times
Hi all
Is it possible to create a straight line indicator, anchored at a particular price and day, that increases that price by a fixed annual percentage?

As an example, let's say on Feb 17 equity WXYZ closed at $40.00. That's the anchor point. I then want to plot a line that increases that $40.00 by 15% per annum. Is such a thing possible? And if so, can one of you coding gurus explain how, as I haven't a clue.

Assistance with this would be greatly appreciated.
DavidF  
#2 Posted : Saturday, February 20, 2016 4:28:50 AM(UTC)
DavidF

Rank: Member

Groups: Registered, Registered Users
Joined: 2/8/2014(UTC)
Posts: 11

Thanks: 1 times
Hi all As an interim solution to my initial query I've developed a workaround by using a combination of Excel and Metastock. I've set up an Excel spreadsheet that takes my anchor point (purchase date and price), goes back 3 months and discounts the price by a selected annual percentage. That then gives me the second point to use for drawing a straight line in Metastock. In Metastock I then draw a random Trendline, open Trendline Properties and enter the Start date and value, and End date and value. I tick 'Right extension' and that gives me exactly the line I'm looking for, passing through my anchor point. It's a time consuming process to do this on every chart in my portfolio but at least it works and it will suffice until somebody out there in Metastock guru land is kind enough to tell me if/how I can create an indicator to accomplish this.
MS Support  
#3 Posted : Wednesday, February 24, 2016 11:26:55 PM(UTC)
MS Support

Rank: Advanced Member

Groups: Moderators, Registered, Registered Users, Subscribers
Joined: 10/8/2010(UTC)
Posts: 1,960

Thanks: 92 times
Was thanked: 155 time(s) in 150 post(s)
I'm not a formula master by any means. Also not entirely sure if a per annum percentage would increase every day, month, end-of-year, etc. A formula that might be a starting point would be:

X:=Input("Enter Start Month",1,12,1);
Y:=Input("Enter Start Day",1,31,4);
Z:=Input("Enter Start Year",1980,2050,2016);
Start:=ValueWhen(1,Month()=X AND DayOfMonth()=Y AND Year()=Z,C);
Start

Note this formula does not increase the value over time but could probably be made to do so. Additionally if you enter a date that does not trade, you will not see the indicator plot at all, at which point you may need to Tab through the chart until you've highlighted your invisible indicator, then click Format > Selected object to modify it. As you tab through the chart, the name of the selected objects will appear in the lower left corner of MetaStock.

Edited by user Wednesday, February 24, 2016 11:32:52 PM(UTC)  | Reason: Not specified

mstt  
#4 Posted : Thursday, February 25, 2016 1:30:43 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 MS Support I attempted to respond to David's request several days ago but clicked the wrong button when finished and wiped my post. Didn't have time to rewrite then and don't intend to do so now. I must say that drawing a straight line from a nominated starting point and price is not particularly difficult. However, I too have some concern that "per annum percentage" might need to be calculated separately for each year of data. As for plotting just one straight line the trick to getting an appropriate increment (or decrement) for each bar-to-bar progression is to subtract the starting value from the ending value and divide that difference by the number of bars apart between start and end point (give or take perhaps 1 bar, don't remember exactly). Setting a starting point with your formula is good as long as the date setting points to an actual trading day. Most of us at some time or other will set the starting point to a non-trading day, and that generates an N/A result and a certain amount of frustration in trying to get the plot back on the chart. Adding a little extra code eliminates that situation - see the "Date Filter Start" indicator below, and below that a "Date Filter" that returns a TRUE between the start and end dates. Hope this helps somebody. Roy {Date Filter Start} Sd:=Input("Date Filter, Start day" ,1,31,1); Sm:=Input("Start month",1,12,1); Sy:=Input("Start year" ,1980,2015,2012); Start:=(DayOfMonth()>=Sd AND Month()=Sm AND Year()=Sy) OR Year()>Sy OR (Year()=Sy AND Month()>Sm); Cum(Start)=1; {Date Filter} {Roy Larsen, 2003-2015, 12/5/15} Sd:=Input("Start day" ,1,31,1); Sm:=Input("Start month",1,12,1); Sy:=Input("Start year" ,1980,2015,2012); Ed:=Input("End day" ,1,31,31); Em:=Input("End month" ,1,12,12); Ey:=Input("End year" ,1980,2020,2015); Start:=(DayOfMonth()>=Sd AND Month()=Sm AND Year()=Sy) OR Year()>Sy OR (Year()=Sy AND Month()>Sm); End:=(DayOfMonth()<=Ed AND Month()=Em AND Year()=Ey) OR Year()<Ey OR (Year()=Ey AND Month()<Em); Start AND (End OR (Start AND Alert(Start=0,2)));
thanks 1 user thanked mstt for this useful post.
MS Support on 2/25/2016(UTC)
DavidF  
#5 Posted : Thursday, February 25, 2016 12:38:33 PM(UTC)
DavidF

Rank: Member

Groups: Registered, Registered Users
Joined: 2/8/2014(UTC)
Posts: 11

Thanks: 1 times
Thanks - MS Support, and Roy - that's certainly a very useful start. When added to a chart it gives a horizontal line, anchored at the buy date (input date) and extending to the current date. Is it possible to input a slope for the line? It wouldn't be difficult to calculate the daily increment as Roy suggests, either as a $ figure or as a %; an Excel spreadsheet and a calendar should easily handle it. That would effectively enable me to set the desired percentage that I want to look at - but how do I modify the line plot to make it slope? The only other thing that I'd then need to do is adjust (or input?) the $ value on the input date, to reflect my buying price rather than the closing price. I've tried adding an amount to "Plot:=0;" so that ". . . =Z,Plot+C);" moves the indicator line to the buying price rather than to the close but it places the line, vertically, in the wrong place. On the charts I've tried so far it moves the line more than the value I add. I then tried adding the adjustment to ". . . =Z,Plot+C);" so that it became . . . =Z,Plot+C+adjustment); but that made the indicator line disappear. It's still on the chart somewhere as when I re-added it a pop-up told me it was already on the chart and asked if I wanted to add it again. Is the above practicable?
MS Support  
#6 Posted : Thursday, February 25, 2016 3:12:25 PM(UTC)
MS Support

Rank: Advanced Member

Groups: Moderators, Registered, Registered Users, Subscribers
Joined: 10/8/2010(UTC)
Posts: 1,960

Thanks: 92 times
Was thanked: 155 time(s) in 150 post(s)
There is a bit of an annoyance with the fact that when you modify the formula, it puts the input values back to the defaults. I initially had my formula set to use 1 / 1 / 2016 as the default values which is a non-trading day. I had also removed the plot aspect of the formula, although it doesn't hurt by being there and instead of using Plot + C you could just use Plot at that part of the formula. I also made the default input values 1/4/2016 to avoid that annoyance of the line disappearing when trying to tweak the formula.

I would think if the increase is a fixed daily percentage increase it could be added to the plot value each bar. Roy is a far savvier programmer than I. If I am able to get some free time to think about it I can give it a shot. If you don't get a full answer here, you can also try submitting a formula request to our formula department.

https://www.metastock.co...s/CustomFormulaForm.aspx

Edited by user Thursday, February 25, 2016 3:14:34 PM(UTC)  | Reason: Not specified

DavidF  
#7 Posted : Friday, February 26, 2016 2:03:40 AM(UTC)
DavidF

Rank: Member

Groups: Registered, Registered Users
Joined: 2/8/2014(UTC)
Posts: 11

Thanks: 1 times
OK, thanks - I appreciate the help. In the interim, as per my second post, I do have a usable workaround. It would just be nice if it was possible for an indicator to do the same job.
mstt  
#8 Posted : Sunday, February 28, 2016 10:56:47 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 David Here's an indicator that should at least partially meet your needs. I've used 252 as the nominal number of trading days, which I believe is true for most US trading years. Sadly this is not the case for every year. Apart from trade entry date and an annual percentage target there's also a control for blanking extraneous data to the right of the entry date if required. This feature caters for a reduction of any chart distortions caused by extreme values at the right side of the chart. The "Shft" control effectively turns rightmost plot values into N/A results. Hope this helps Roy {Annual % Target} {Roy Larsen, 29/02/2016} Pc:=Input("Annual % Target",-99,199,20); Dy:=Input("Open Trade Day",1,31,1); Mn:=Input("Month",1,12,1); Yr:=Input("Year" ,1980,2020,2013); Shft:=Input("Blank Rightmost Bars",0,999,0); Buy:=(DayOfMonth()>=Dy AND Month()=Mn AND Year() =Yr) OR Year()>Yr OR (Year()=Yr AND Month()>Mn); Buy:=Buy*Alert(Buy=0,2); Cost:=(Cum(Buy)=1)*Buy*CLOSE; Hold:=LastValue(Highest(Cost)); Plot:=Cum(Cost+(Hold*(Pc/100)/252)*(Ref(Cum(Cost>0),-1))); Ref(Ref(ValueWhen(1,Plot<>0,Plot),-Shft),Shft);
thanks 1 user thanked mstt for this useful post.
MS Support on 2/29/2016(UTC)
DavidF  
#9 Posted : Monday, February 29, 2016 4:09:22 AM(UTC)
DavidF

Rank: Member

Groups: Registered, Registered Users
Joined: 2/8/2014(UTC)
Posts: 11

Thanks: 1 times
Thanks Roy. I'm working off my laptop at the moment, which doesn't have MS on it. I'll check it on my desktop when I get home later today. Should have an update for tomorrow morning your time.
DavidF  
#10 Posted : Monday, February 29, 2016 12:53:15 PM(UTC)
DavidF

Rank: Member

Groups: Registered, Registered Users
Joined: 2/8/2014(UTC)
Posts: 11

Thanks: 1 times
Hi Roy Your coding does a lot more than "at least partially meet your needs"; it almost completely fulfills what I was hoping to achieve. If I could trouble you just a little further - as per the 3rd paragraph of my #5 post above: "The only other thing that I . . . need to do is adjust (or input?) the $ value on the input date, to reflect my buying price rather than the closing price." I could either enter the actual price as an input, or I could enter a variation to the Close - whichever is easier to incorporate. Is that practicable?
mstt  
#11 Posted : Monday, February 29, 2016 7:40:06 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 David

I've added a "Start Price" input that gives you the ability to over-ride the CLOSE with a different value. Using a default of zero allows the CLOSE to set the "Start Price". The "Cost" variable now selects CLOSE when the Start Price is zero or the adjusted start price when other than zero.

If you're trading a market other than the US then the nominal number of days in a trading year might need to be changed from 252. The first draft of this indicator (not posted) used the actual number of daily bars per year. The problem with that was that the start date needed to be at least one year earlier than the last data bar.

This indicator should also work with weekly data if the 252 constant is replaced by 52.

Regards

Roy

{Annual % Target}
{Roy Larsen, 1/3/2016}

Pc:=Input("Annual % Target",-99,199,20);
Sp:=Input("Adjust Start Price",0,999,0);
Dy:=Input("Open Trade Day",1,31,1);
Mn:=Input("Month",1,12,1);
Yr:=Input("Year" ,1980,2020,2013);
Shft:=Input("Blank Rightmost Bars",0,999,0);

Buy:=(DayOfMonth()>=Dy AND Month()=Mn AND Year()
=Yr) OR Year()>Yr OR (Year()=Yr AND Month()>Mn);
Buy:=Buy*Alert(Buy=0,2);

Cost:=(Cum(Buy)=1)*Buy*If(Sp=0,C,Sp);
Hold:=LastValue(Highest(Cost));
Plot:=Cum(Cost+(Hold*(Pc/100)/252)*(Ref(Cum(Cost>0),-1)));
Ref(Ref(ValueWhen(1,Plot<>0,Plot),-Shft),Shft);

Edited by user Monday, February 29, 2016 7:43:30 PM(UTC)  | Reason: Not specified

thanks 1 user thanked mstt for this useful post.
DavidF on 3/1/2016(UTC)
DavidF  
#12 Posted : Tuesday, March 1, 2016 12:22:54 AM(UTC)
DavidF

Rank: Member

Groups: Registered, Registered Users
Joined: 2/8/2014(UTC)
Posts: 11

Thanks: 1 times
Thanks Roy - absolutely perfect! Very much appreciated. And MS Support - thank you again for your initial help - it gave me the encouragement that a solution to the problem was really achievable.
DavidF  
#13 Posted : Saturday, June 4, 2016 3:47:25 AM(UTC)
DavidF

Rank: Member

Groups: Registered, Registered Users
Joined: 2/8/2014(UTC)
Posts: 11

Thanks: 1 times
The addition of "Larson Lines" to my charts has proven extremely helpful; every chart now has at least one line. It's been interesting also to see just how deceptive a plot of price bars can be; it's only once I have the fixed percentage, price increase line plotted that the true rate of growth of a stock becomes apparent. On some charts the line will sit at 60 degrees, on others it's only 20 degrees, whereas without those lines the charts appeared to be showing similar rates of price growth. But I'm digressing. If it's practicable I'd like to enhance the coding. Is it possible, when adding the indicator to a chart, that it simultaneously adds two lines - in place of the current single line with a 20% default value I'd like one line with a default value of 50% and one with a default value of 100%? The other inputs - start price, open trade day, month and year - would be identical for each line. Is this practicable?
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.