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

[Metastockusers] A good piece of code for FirstValue Roy and Jose



PureBytes Links

Trading Reference Links

I posted a little piece of code for your code library written by 
Jose, and then Roy sent in his suggestion. Add it to your library.

>
> {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

I'm sure Jose won't mind me showing an alternative. In theory it 
should give
the same result. Roy

{First Value}
x:=C; {any valid data array}
FirstValue:=ValueWhen(1,Cum(1)=1,x);
FirstValue;


> 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/zMEolB/TM
---------------------------------------------------------------------~->

To unsubscribe from this group, send an email to:
Metastockusers-unsubscribe@xxxxxxxxxxx

 

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