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.
|
|
|
|
Rank: Advanced Member
Groups: Moderators, Registered, Registered Users, Subscribers Joined: 10/8/2010(UTC) Posts: 1,960
Thanks: 91 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
|
1 user thanked MS Support for this useful post.
|
|
|
Rank: Member
Groups: Registered Users, Subscribers Joined: 2/7/2015(UTC) Posts: 15
Thanks: 9 times
|
Originally Posted by: MS Support 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.
|
|
|
|
Rank: Advanced Member
Groups: Moderators, Registered, Registered Users, Subscribers Joined: 10/8/2010(UTC) Posts: 1,960
Thanks: 91 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
|
|
|
|
Rank: Member
Groups: Registered Users, Subscribers Joined: 2/7/2015(UTC) Posts: 15
Thanks: 9 times
|
Originally Posted by: MS Support 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.
|
|
|
|
Rank: Advanced Member
Groups: Moderators, Registered, Registered Users, Subscribers Joined: 10/8/2010(UTC) Posts: 1,960
Thanks: 91 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.
|
|
|
|
Rank: Advanced Member
Groups: Moderators, Registered, Registered Users, Subscribers Joined: 10/8/2010(UTC) Posts: 1,960
Thanks: 91 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."
|
1 user thanked MS Support for this useful post.
|
|
|
Rank: Member
Groups: Registered Users, Subscribers Joined: 2/7/2015(UTC) Posts: 15
Thanks: 9 times
|
Originally Posted by: MS Support 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
|
|
|
|
Rank: Advanced Member
Groups: Moderators, Registered, Registered Users, Subscribers Joined: 10/8/2010(UTC) Posts: 1,960
Thanks: 91 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.
|
1 user thanked MS Support for this useful post.
|
|
|
Rank: Newbie
Groups: Registered Users, Subscribers Joined: 7/28/2016(UTC) Posts: 2
|
Where I can download software? I can`t find
|
|
|
|
Rank: Advanced Member
Groups: Moderators, Registered, Registered Users, Subscribers Joined: 10/8/2010(UTC) Posts: 1,960
Thanks: 91 times Was thanked: 155 time(s) in 150 post(s)
|
|
|
|
|
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
|
2 users thanked mstt for this useful post.
|
|
|
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
|
2 users thanked mstt for this useful post.
|
|
|
Rank: Member
Groups: Registered Users, Subscribers Joined: 2/7/2015(UTC) Posts: 15
Thanks: 9 times
|
Originally Posted by: mstt 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.
|
|
|
|
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.