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
|