[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[EquisMetaStock Group] A good piece of code for FirstValue



PureBytes Links

Trading Reference Links

Here's a little piece of code I ran across from Jose. You can put it 
away in your code library. It might come in handy.

{The MetaStock language has many frustrating limitations. A major 
headache is not being able to load an entire data array with the 
first calculated value of the specified data array, such as the first 
Close in all the loaded data. 

Here is a FirstValue() function or equivalent, which I believe didn't 
exist... until now:}

x:=C; {or any other valid data array}
FirstValue:=LastValue(Ref(x,-(LastValue(Cum(1))-1)));
FirstValue

{But, what if we now need the first value of a conditional 
expression, which doesn't happen to coincide with the first period in 
the loaded data array? 
If we use the FirstValue formula above, the value found will always 
be zero. Not good. 
To get this value:}

x:=C; {or any other price field such as next day's close Ref(C,1)}
y:=Cross(C,Mov(C,21,E)); {sample condition}
FirstCond:=LastValue(ValueWhen(LastValue(Cum(y)),y=1,x));
FirstCond

Jack





------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for Your HP, Epson, Canon or Lexmark
Printer at Myinks.com. Free s/h on orders $50 or more to the US & Canada. http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/l.m7sD/LIdGAA/qnsNAA/BefplB/TM
---------------------------------------------------------------------~->

To unsubscribe from this group, send an email to:
equismetastock-unsubscribe@xxxxxxxxxxxxxxx

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/