Hi GJ
As yet there is no publicly-available variable ValueWhen() function for MetaStock. This might change when/if Wabbit updates the Forum DLL, but that's not a foregone conclusion at this point.
The +PREV-PREV option does work, at least in some situations. The following formula is just one example. From memory, with this formula at least, I think the PREV variable has to be an unnamed output variable. In other words you can't name the PREV variable and then use its name as an output or to feed other code lines. If you attempt to use the name of the PREV variable as an output you'll probably discover that it does plot, but only on the last bar. All other bars are N/A. At least that's what happens with the formula below. It's a PREV variable characteristic that I haven't figured out how to get around yet.
Try changing the last line if this formula by giving it a name and then outputting that name and you'll see what I mean. Keep your EOD chart to less than 1000 bars or you'll be waiting a while for it to plot.
If you're wondering what this formula does, The "I" variable is a descending counter that points back the appropriate number of weekly CLOSEs so that a weekly plot of CLOSE can be recreated (and right adjusted) on successive EOD bars.
Regards
Roy
MetaStock Tips & Tools
{Weekly Close Compression}
{2004 Roy Larsen, rlarsen@man.quik.co.nz}
{use on daily charts with Jose Silva's
"Calendar Week counter"}
F:=Input("End of Week, 5=Friday 6=Saturday 7=Sunday",5,7,5);
Q:=Input("Display Mode, 0=Static 1=Dynamic 2=Test",0,2,1);
{0=Display, update on Friday when possible}
{1=Display, update on each new bar}
{2=Backtest, update on first bar of new week}
G:=LastValue(Highest(Sum(DayOfWeek()=F,5))=5);
I:=Fml("Calendar Week counter");
I:=Abs(I-ValueWhen(2-G,1,I)); M:=G OR I>0;
F:=G OR (DayOfWeek()=F AND I=0);
A:=LastValue(Cum(1)-1)=Cum(1);
B:=ValueWhen(2,1,A);
J:=If(F,1,If(Alert(F,2)=0 AND M,2,0));
J:=If(A+LastValue(J)>2 OR B+(Q=1)=2,1,J);
J:=If(G,1,If(Q=2 OR Cum(J)<=1,M*2,J));
K:=ValueWhen(1,J,If(J=1,C,ValueWhen(2-G,1,C)));
K:=ValueWhen(1,K>0,K);
F:=LastValue(Cum(1))-Cum(1);
G:=LastValue(Cum(J>0))-Cum(J>0);
I:=1+F-G;
M:=LastValue(Cum(J>0));
I:=ValueWhen(1,F<=M,I);
ValueWhen(LastValue(I+PREV-PREV),J,K);