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

Notification

Icon
Error

Options
Go to last post Go to first unread
HolyGrail  
#1 Posted : Saturday, May 29, 2010 3:28:53 PM(UTC)
HolyGrail

Rank: Member

Groups: Registered, Registered Users
Joined: 5/27/2010(UTC)
Posts: 13
Location: Norton, Ohio

Folks, This is a simple formula which I wrote to test my understanding about what Ref() does.
z := 0; {initialize z so that MS won't complain about it not being recognized}
y := Ref(z, -1); {pickup yesterday's z value}
z := y + 1; {increment y, store it to z}
z; {plot z; expectation is that it is an upsloping line}
{REALITY is that z stays constant at 1, and this means Ref() doesn't do what I thought it did}
I have a indicator I wrote for Trade Station that I am trying to convert, and it looks like this: The code test above simulates this, and Ref() isn't working to get the FINAL value as the manual says it does. Anyone see what I am doing wrong in the test formula?
johnl  
#2 Posted : Saturday, May 29, 2010 7:07:08 PM(UTC)
johnl

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 11/7/2005(UTC)
Posts: 602

You don't initialize or increment anything in Metastock like you do in C++ say.
The functions are designed so that you don't have to be a heavy duty programmer
to get around in the language.
HolyGrail  
#3 Posted : Sunday, May 30, 2010 2:13:24 AM(UTC)
HolyGrail

Rank: Member

Groups: Registered, Registered Users
Joined: 5/27/2010(UTC)
Posts: 13
Location: Norton, Ohio

MS requires the initialization or else it complains that the variable is not recognized. That is the only reason z is initialized in my example. Why doesn't Ref(z, -1) get the previous day's value of z?
johnl  
#4 Posted : Sunday, May 30, 2010 7:43:32 PM(UTC)
johnl

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 11/7/2005(UTC)
Posts: 602

Maybe thinking that Metastock plots your function based on the same formula for every point of time in the chart will help. So if you set z:=0; every daily calculation is going to start with z:=0;

mstt  
#5 Posted : Sunday, May 30, 2010 8:18:11 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 HG

Did you get my email?

Roy

HolyGrail  
#6 Posted : Sunday, May 30, 2010 11:22:01 PM(UTC)
HolyGrail

Rank: Member

Groups: Registered, Registered Users
Joined: 5/27/2010(UTC)
Posts: 13
Location: Norton, Ohio

Hello Roy, Yes, I got it and I've had a breakthrough THANK GOODNESS. I was pulling my hair out (still am on one note). PREV is working for me now, but I had to completely throw out my TradeStation code and rewrite instead of attempting a "convert". It has to be rebuilt from the ground up using this seemingly crazy logic structure. But this thread is about why Ref() doesn't pick up the last value of the day, something I do not understand. My code above presents a conumdrum. So there can only be ONE declaration of a variable per day?
vienna  
#7 Posted : Monday, May 31, 2010 1:54:59 AM(UTC)
vienna

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 12/14/2009(UTC)
Posts: 140
Location: Austria

Hi,
I try to explain how metastocks work in my point of view.

MS is handling Ref (like every function which has no PREV included) like an vector. This means if you have a vector of Close values (e.g. C=10,20,30,15,8,13,17) than the Ref-function is only shifting the complete vector (not recursively).

e.g.
C; {C=10,20,30,15,8,13,17}
x:=Ref(C,-1); {shift whole vector - result x=0,10,20,30,15,8,13}

e.g.
z:=0; { z=0,0,0,0,0,0,0}
y:=ref(z,-1); { y=0,0,0,0,0,0,0}
z := y + 1; {z=1,1,1,1,1,1,1}

as you can see every line of code is handled on its own line per line afterwards.

But using an Prev Function in some line of Code will change everything. Because MS will handle it recursivly.

e.g.
z:=0; { z=0,0,0,0,0,0,0}
z := PREV + 1;
{ recursively looping over the vector:
z[1]=z[0]+1=1
z[2]=z[1]+1=2
z[3]=z[2]+1=3
z[4]=z[3]+1=4
z[5]=z[4]+1=5
z[ 6]=z[5]+1=6
z[7]=z[ 6]+1=7
}
{result z=1,2,3,4,5,6,7}
y:=ref(z,-1); { y=NA,1,2,3,4,5,6}

MS is still working line per line but now ms will handle the 2nd line recursively this means it won't calculate the whole vector in one step - but its looping over this vector and calculating step by step every value with the previous value as input...
therefore MS will calculate very slow if you are using a lot of PREV Functions ... because its calculation these lines of code recursively step by step.

and additional the trick using "+PREV-PREV+0" in a line of code will MS force to calculate something recursively like it's needed in this thread: http://forum.equis.com/forums/thread/32667.aspx

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.