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

Notification

Icon
Error

Options
Go to last post Go to first unread
lilly  
#1 Posted : Tuesday, July 10, 2012 12:22:23 AM(UTC)
lilly

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/27/2005(UTC)
Posts: 17

Hello,

I would like to calculate the average of an indicator on a basket of securitites.
For example, say that I wanted to know what the average RSI(14) on the list of the S&P500 constituents was.
Can you do this with an exploration or an indicator.
Your help is much appreciated

Lilly
mstt  
#2 Posted : Tuesday, July 10, 2012 2:38:04 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 Lilly

Yes, this is possible using global variables with the Explorer. The process requires two explorations, one to initialize two global variables, and the other to accumulate the total RSI and number of securities using those global variables. The the first exploration only needs to be run on one security - e.g. SPX. This presets both global variables to zero.

{Custom Reset}

{colA}
{Initialize global variables}
ExtFml("GV.SetVar","RSISum",0);
ExtFml("GV.SetVar","SecuritySum",0);

The second exploration reads the global variables for each security and then writes back an updated value. In my example the "Scan" exploration is split into three columns. This is not essential but is useful to to report the values being accumulated, particularly the number of securities. MetaStock doesn't necessarily process the securities in the expected order, so being able to sort the result by the the security count column makes it easy to identify final values.

{Custom Scan}

{colA}
{Accumulate RSI value of securities}
Value:=LastValue(ExtFml("GV.GetVar","RSISum"));
RS:=LastValue(RSI(14));
Value:=ExtFml("GV.SetVar","RSISum",Value+RS);
Value;

{colB}
{Accumulate number of securities}
Number:=LastValue(ExtFml("GV.GetVar","SecuritySum"));
Number:=ExtFml("GV.SetVar","SecuritySum",Number+1);
Number;

{colC}
Value:=LastValue(ExtFml("GV.GetVar","RSISum"));
Number:=LastValue(ExtFml("GV.GetVar","SecuritySum"));
Value/Number;

You will need the GV DLL to be installed before these exploration will run. I can send you a copy if necessary. If the posted code is corrupted you'll also need to email (private message) me for a copy.

Roy


lilly  
#3 Posted : Wednesday, July 18, 2012 2:01:05 AM(UTC)
lilly

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/27/2005(UTC)
Posts: 17

Thank you Roy

You're the best!
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.