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

Notification

Icon
Error

Options
Go to last post Go to first unread
Ljhardwell  
#1 Posted : Friday, May 3, 2013 6:13:08 PM(UTC)
Ljhardwell

Rank: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 5/3/2013(UTC)
Posts: 2

ex. days when the close is greater than the open
mstt  
#2 Posted : Friday, May 3, 2013 11:11:19 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 LJ

I haven't thought too much about doing it with standard MS functions but it is definitely possible using the Forum DLL where relevant functions allow variable Parameter values.

Typically for an SMA you would need to create a lookback range to span N events, then use Forum.Sum with event values to sum events across the range, and lastly divide the summed result by N (events).

An EMA would be managed differently in that the lookback range is not relevant but the first essential element is the ratio of new data added (same as old data discarded). This is controlled by N periods. The second essential element is to allow the EMA value to change only on "certain days", i.e. when your condition is TRUE. Inhibiting a change is managed by switch the N parameter for a much larger number when the condition for averaging is not met. Pwr(10,10) works well in this regard. If you're using Wabbits MSTT DLL the N parameter can be switched to a negative number to prevent a value from an unwanted bar being included in the EMA.

See how you go and come back if you cannot figure it out.

Roy

mstt  
#3 Posted : Sunday, May 5, 2013 3:52:57 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 Eddie

I gave an incomplete answer to LJ to encourage him to think for himself. Help that costs nothing is often treated as if it's worth nothing, whereas help that costs time, effort or money is more likely to be appreciated and of greater benefit to the recipient in the long run. However, there was no intended suggestion by me that LJ would have to pay for a more complete answer in the event that he couldn't get any further without further help.

I don't agree with your advice to "do only what you know because this is what comes easy". If this works for you then by all means stick with it. In my experience, however, there's little in life that comes easy without serious effort along the way.

Why you should be opposed to me charging for some of my MetaStock skills is a mystery, but if it's something that's bugging you then perhaps you should talk to me about it directly rather than through this forum.

LJ

Here's some code for basic event-based simple and exponential moving averages. Hopefully this adds some substance to my initial post. You will need to define the event you have in mind so that a TRUE signals a valid sample value and a FALSE inhibits value sampling.

Code:

 {Event-based Simple Moving Average}
 {Roy Larsen, 6/5/2013}
N:=Input("Event-based SMA Periods",1,99,10);
 {Define the event to control price smoothing}
Event:= C>Ref(C,-1);
 {Event-based SMA}
Z:=Cum(1); A:=Cum(Event);
Z:=Z-ValueWhen(N+1,Event,Z);
Z:=ExtFml("Forum.Sum",Event*C,Z);
ValueWhen(1,Event,Z)/N;
 {Event-based Exponential Moving Average}
 {Roy Larsen, 6/5/2013}
N:=Input("Event-based EMA Periods",1,99,10);
 {Define event to control price smoothing}
Event:= C>Ref(C,-1);
 {Event-based EMA}
R:=If(Event,N,Pwr(10,10));
ExtFml("Forum.Mov",C,R,E);
Roy
mstt  
#4 Posted : Sunday, May 5, 2013 4:12:20 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 LJ

Here's a modified version of the SMA formula that eliminates distortion when the SMA plot uses the same scale as the price.

Roy

Code:

 {Event-based Simple Moving Average}
 {Roy Larsen, 6/5/2013}
N:=Input("Event-based SMA Periods",1,99,10);
 {Define event to control price smoothing}
Event:= C>Ref(C,-1);
 {Event-based SMA}
Z:=Cum(1); A:=Cum(Event);
Z:=Z-ValueWhen(N+1,Event,Z);
Z:=ExtFml("Forum.Sum",Event*C,Z);
ValueWhen(1,Event,Z)/Min(N,Cum(Event));
Ljhardwell  
#5 Posted : Wednesday, May 8, 2013 3:07:26 PM(UTC)
Ljhardwell

Rank: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 5/3/2013(UTC)
Posts: 2

I was curious if there is a way using just the standard metastock formula language because I couldn't put it together in my head how exactly you would go about it. If we are in agreement that there probably isn't a way to do it that way then I will probably experiment with what you've provided.

I appreciate the effort!

mstt  
#6 Posted : Thursday, May 9, 2013 3:34:45 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 MJ

If there's a way to do it with just MFL it will involve the PREV function and its related execution-speed issues. Going down that road could take a lot of work but with a rather slim chance of a workable result.

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.