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

Notification

Icon
Error

Options
Go to last post Go to first unread
jjstein  
#1 Posted : Thursday, May 22, 2008 6:36:31 PM(UTC)
jjstein

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)

I'm trying to plot a simple moving average, centered properly. The following comes close:

Speed:= Input("MA",1,500,80);
Displacement:=Speed/2;
MA:=Mov(C,Speed,S);
Ref(MA,Displacement);

To do it properly, the period and displacement need to be an odd number, so I've coded an automatic adjustment:

Speed:= Input("MA",1,500,80);
Speed:=If(Mod(Speed,2)=0,Speed+1,Speed);
MA:=ExtFml("FORUM.Mov",C,Speed,S);
Displacement:=If(Mod(Speed,2)=0,Speed/2,(Speed+1)/2);
ExtFml("Forum.REF",MA,-Displacement);

However, the adjustment means that the FORUM.DLL needs to be used for both the Moving Average and the use of REF for a horizontal shift (like the built-in M.A.).

It "sort of" works, BUT the FORUM.DLL plot drops down to zero, instead of stopping!

Anyone have an idea on how to fix this?

wabbit  
#2 Posted : Thursday, May 22, 2008 6:54:24 PM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
jj,

The Forum functions allow the user to pass data arrays as arguments, but you only need to "convert" the user input speed as a variable to a "static" value for use in the normal moving average and ref functions.

Code:

Speed:=Input("MA",1,500,80);
Speed:=LastValue(If(Mod(Speed,2)=0,Speed+1,Speed));
Displacement:=Speed/2;

MA:=Mov(C,Speed,S);

{plot}
Ref(MA,-Displacement);



Hope this helps.

wabbit [:D]

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.