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

Notification

Icon
Error

Options
Go to last post Go to first unread
vikas  
#1 Posted : Thursday, July 21, 2016 2:54:19 PM(UTC)
vikas

Rank: Member

Groups: Registered Users, Subscribers
Joined: 2/7/2015(UTC)
Posts: 15

Thanks: 9 times
Say, I want to find average of last 5 up days. From this thread I got a formula that I thought might help me, but I can't quite figure out how to get it to work.
------------------------------------------------
count:=Cum(C>O);

y:=LastValue(count)-count;

Mod(y,5)
-------------------------------------------------

This correctly identifies the last 5 up days but this is meant to plot only (?). I need to add the CLOSES of these 5 days and I don't know how to go about it.

Thanks in advance.

 

MS Support  
#2 Posted : Thursday, July 21, 2016 9:30:58 PM(UTC)
MS Support

Rank: Advanced Member

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

Thanks: 86 times
Was thanked: 155 time(s) in 150 post(s)
Hi, I suppose there are different ways to arrive at the desired value. The most straightforward approach for me would be to simply use multiple ValueWhen statements, i.e.: (ValueWhen(1,C > O,C) + ValueWhen(2,C > O,C) + ValueWhen(3,C > O,C) + ValueWhen(4,C > O,C) + ValueWhen(5,C > O,C)) / 5
thanks 1 user thanked MS Support for this useful post.
vikas on 7/22/2016(UTC)
vikas  
#3 Posted : Friday, July 22, 2016 3:05:26 AM(UTC)
vikas

Rank: Member

Groups: Registered Users, Subscribers
Joined: 2/7/2015(UTC)
Posts: 15

Thanks: 9 times
Originally Posted by: MS Support Go to Quoted Post
Hi,

I suppose there are different ways to arrive at the desired value. The most straightforward approach for me would be to simply use multiple ValueWhen statements, i.e.:

(ValueWhen(1,C > O,C) + ValueWhen(2,C > O,C) + ValueWhen(3,C > O,C) + ValueWhen(4,C > O,C) + ValueWhen(5,C > O,C)) / 5

Works like a charm. ;)

Just out of curiosity, can I automate this procedure. Here I am manually putting 5 expressions and if, say for example, I want a 20 period average I have to again edit this formula to put in 15 more expressions.

What if I just input 20 or any number, using the Input() function, and it gives me the average of CLOSE of that many up close days?

Is it at all possible?

Again, thanks a bunch. 

MS Support  
#4 Posted : Friday, July 22, 2016 2:05:43 PM(UTC)
MS Support

Rank: Advanced Member

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

Thanks: 86 times
Was thanked: 155 time(s) in 150 post(s)
This one will probably work better dynamically: X:=Input("Enter Average Periods",1,999,5); Sum(ValueWhen(1,C > O,C),X) / X
vikas  
#5 Posted : Saturday, July 23, 2016 4:20:53 AM(UTC)
vikas

Rank: Member

Groups: Registered Users, Subscribers
Joined: 2/7/2015(UTC)
Posts: 15

Thanks: 9 times
Originally Posted by: MS Support Go to Quoted Post
This one will probably work better dynamically:

X:=Input("Enter Average Periods",1,999,5);

Sum(ValueWhen(1,C > O,C),X) / X

 

Thanks. I had tried this earlier, but it has 2 problems.

1st, it reflects CLOSE of UP day for all days until the next UP day. For example, say Day 1 is UP, Day 2 & 3 are DOWN, Day 4 is UP and Day 5 is DOWN, this will add Day 1 CLOSE thrice (Day 1,2 & 3), Day 4 twice (Day 4 & 5).

2nd, Sum() will just add the conditions that are fulfilled within the specified number days, not for the specified number of days. For example, if 5-period summation is sought, it will look for the conditions being fulfilled within 5 days. So if there are 2 Up days within 5-day period it will add those 2 days only. Whereas the requirement is adding 5 UP days, irrespective of how far back it has to look.

 

MS Support  
#6 Posted : Monday, July 25, 2016 2:10:37 PM(UTC)
MS Support

Rank: Advanced Member

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

Thanks: 86 times
Was thanked: 155 time(s) in 150 post(s)
Yep you're right, I knew there was a reason I avoided using Sum the first time :). I'll see what I can find out for this.
MS Support  
#7 Posted : Monday, July 25, 2016 3:33:16 PM(UTC)
MS Support

Rank: Advanced Member

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

Thanks: 86 times
Was thanked: 155 time(s) in 150 post(s)
In running this by our lead formula writer here he did confirm that making the "Nth" parameter dynamic is not possible and that a DLL would be required for this. Specifically: "You can not do this dynamically. There is no looping functionality to add additional Valuewhen() functions with higher Nth parameters. What the user wants will require a DLL."
thanks 1 user thanked MS Support for this useful post.
vikas on 7/28/2016(UTC)
vikas  
#8 Posted : Thursday, July 28, 2016 3:20:25 AM(UTC)
vikas

Rank: Member

Groups: Registered Users, Subscribers
Joined: 2/7/2015(UTC)
Posts: 15

Thanks: 9 times

Originally Posted by: MS Support Go to Quoted Post
In running this by our lead formula writer here he did confirm that making the "Nth" parameter dynamic is not possible and that a DLL would be required for this. Specifically: "You can not do this dynamically. There is no looping functionality to add additional Valuewhen() functions with higher Nth parameters. What the user wants will require a DLL."

Appreciate it.

Now, my inner nerd is waking up (not a computer nerd though).

How do I get such DLL file? Is it available for free?

Thanks 

MS Support  
#9 Posted : Thursday, July 28, 2016 2:05:23 PM(UTC)
MS Support

Rank: Advanced Member

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

Thanks: 86 times
Was thanked: 155 time(s) in 150 post(s)
Hi, The MetaStock Developer's Kit can be used to create DLLs that could do something like this. https://www.metastock.com/partners/developers.aspx Familiarity with the programming languages supported would be needed, otherwise you can sometimes find/hire programmers to help.
thanks 1 user thanked MS Support for this useful post.
vikas on 7/29/2016(UTC)
Callum  
#10 Posted : Thursday, July 28, 2016 2:39:32 PM(UTC)
Callum

Rank: Newbie

Groups: Registered Users, Subscribers
Joined: 7/28/2016(UTC)
Posts: 2

Where I can download software? I can`t find
MS Support  
#11 Posted : Thursday, July 28, 2016 2:45:49 PM(UTC)
MS Support

Rank: Advanced Member

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

Thanks: 86 times
Was thanked: 155 time(s) in 150 post(s)
Hi Callum, The MetaStock Developer's Kit is a purchase (not directly orderable online). You can contact our Sales team directly if you are interested in purchasing. https://www.metastock.co...mpany/about/contact.aspx
mstt  
#12 Posted : Saturday, July 30, 2016 4:59:10 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 Vikas I'm not sure that what I've put together is what you actually want but I think it's close to what you were looking for. This indicator feeds the required number of UP bars into the variable Sum function found in the Forum DLL. I assume that the DLL is still available from this site. Hope this is on the right track It shouldn't be too difficult to create an exponential MA using the MSTT DLL {SMA of Up-Bars} {Roy Larsen, 29/7/16} Pds1:=Input("UP bars (CLOSE>OPEN)",1,99,5); Down:=Cum(C<=O); Back:=ValueWhen(Pds1+1,C>O,Down-Pds1); Pds2:=Down-Back; SMA:=ExtFml("Forum.Sum",C*(C>O),Pds2)/Pds1; ValueWhen(1,SMA>0,SMA); Roy
thanks 2 users thanked mstt for this useful post.
MS Support on 8/1/2016(UTC), vikas on 8/4/2016(UTC)
mstt  
#13 Posted : Saturday, July 30, 2016 11:45: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)
Here's the exponential EMA version for averaging up-bars only. This formula is even simpler than the SMA version. That's because the MSTT.EMA function ignores unwanted bars (as signaled by a ValidBars value of -1), so there's no need to count back the appropriate number of bars. {EMA of Up-Bars} {Roy Larsen, 30/7/16} Pds:=Input("EMA Up-bar Periods (C>O)",1,99,5); ValidBars:=If(C>O,Pds,-1); ExtFml("MSTT.EMA",C,ValidBars); Roy
thanks 2 users thanked mstt for this useful post.
MS Support on 8/1/2016(UTC), vikas on 8/4/2016(UTC)
vikas  
#14 Posted : Thursday, August 4, 2016 6:06:20 AM(UTC)
vikas

Rank: Member

Groups: Registered Users, Subscribers
Joined: 2/7/2015(UTC)
Posts: 15

Thanks: 9 times
Originally Posted by: mstt Go to Quoted Post
Hi Vikas

I'm not sure that what I've put together is what you actually want but I think it's close to what you were looking for. This indicator feeds the required number of UP bars into the variable Sum function found in the Forum DLL. I assume that the DLL is still available from this site. Hope this is on the right track

It shouldn't be too difficult to create an exponential MA using the MSTT DLL

{SMA of Up-Bars}
{Roy Larsen, 29/7/16}
Pds1:=Input("UP bars (CLOSE>OPEN)",1,99,5); Down:=Cum(C<=O);
Back:=ValueWhen(Pds1+1,C>O,Down-Pds1);
Pds2:=Down-Back;
SMA:=ExtFml("Forum.Sum",C*(C>O),Pds2)/Pds1;
ValueWhen(1,SMA>0,SMA);

Roy

Hi Roy,

WOW. Just WOW. Exactly what I was looking for.

May your tribe increase exponentially ;)

P.S. I am terribly sorry for responding so late. This pesky little thing called life was kicking me in the, well, you know where. Couldn't even check this thread. 

mstt  
#15 Posted : Thursday, August 4, 2016 9:20:24 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 Vikas WOW is exactly the reponse I just had to your reply. It's good to know that I was able to put the code together for you, but your reaction was way better than I could have hoped for. Especially since you've clearly had a bad week. You've truly made my day and my week. Roy
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.