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

Re: [Metastockusers] Re: WEEKLY INDICATOR



PureBytes Links

Trading Reference Links

Hi Norman

I've taken the liberty of rewriting the "x1" and "x2" variables to eliminate all those
nested If() functions. They make the logic harder to follow, and they make
MetaStock work harder too. Oh, and commas used as separators on each side
of ">" or "<" can be confusing too. Better to just leave an open space if you
don't want to run one expression into another. Overdoing the brackets can make
formulas look more complicated than they really are, but too few or putting them
in the wrong place is not good. I guess it comes down to personal preference,
but the fewer If() functions used the better, for sure. 

x1:=Ref(H,-2)>=Ref(C,-7) OR Ref(H,-2)>=Ref(C,-8) OR
  H>=Ref(L,-5) OR H>=Ref(L,-6);
x2:=Ref(L,-2)<=Ref(C,-7) OR Ref(L,-2)<=Ref(C,-8) OR
  L<=Ref(H,-5) OR L<=Ref(H,- 6);
SubValues:=x1*x2*(H-Ref(H,-2)) + x1*x2*(L-Ref(L,-2));
AbsDailyVal:=Abs(H-Ref(H,-2)) + Abs(L-Ref(L,-2));
Sum((SubValues),8)/Sum((AbsDailyVal),8);

"x1" could also be written this way, again without the use of If().

x1:=(Ref(H,-2)<Ref(C,-7) AND Ref(H,-2)<Ref(C,-8) AND
  H<Ref(L,-5) AND H<Ref(L,-6))=FALSE;

I've reworked the weekly formula and used equivalent variable names where
I could. I noticed that in "x1" and "x2" you used "Cw>0" where you should have
used "J" or "J>0". "J>0" is the more correct, but since MetaStock recognises
any value other than zero as a logical TRUE, "J" works as well as "J>0" in that
context.

Sum() is one of the many functions that has to be reconstructed when plotting
weekly values on EOD charts. This is done by using Cum() to sum every weekly
value for the entire chart, then subtracting the the cumulative total as at x+1
weeks ago. This process is also used to construct a weekly simple moving
average, and the difference between the two cumulative values is divided by
the number of weeks in the SMA.

You'll notice that I've also removed spurious brackets and spaces form the
reworked code below. Hope this helps.

Regards

Roy

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:=LastValue(Cum(1))=Cum(1);
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));
Hw:=HighestSince(1,M,H);
Hw:=ValueWhen(1,J,If(J=1,Hw,ValueWhen(2-G,1,Hw)));
Lw:=LowestSince(1,M,L);
Lw:=ValueWhen(1,J,If(J=1,Lw,ValueWhen(2-G,1,Lw)));
Cw:=ValueWhen(1,J,If(J=1,C,ValueWhen(2-G,1,C)));
Hw:=ValueWhen(1,Hw>0,Hw);
Lw:=ValueWhen(1,Lw>0,Lw);
x1:=ValueWhen(3,J,Hw)>=ValueWhen(8,J,Cw) OR
  ValueWhen(3,J,Hw)>=ValueWhen(9,J,Cw) OR
  Hw>=ValueWhen(6,J,Lw) OR Hw>=ValueWhen(7,J,Lw);
x2:=ValueWhen(3,J,Lw)<=ValueWhen(8,J,Cw) OR
  ValueWhen(3,J,Lw)<=ValueWhen(9,J,Cw) OR
  Lw<=ValueWhen(6,J,Hw) OR Lw<=ValueWhen(7,J,Hw);
SubValues:=x1*x2*(Hw-ValueWhen(3,J,Hw))
  + x1*x2*(Lw-ValueWhen(3,J,Lw));
AbsDailyVal:=Abs(Hw-ValueWhen(3,J,Hw))
  + Abs(Lw-ValueWhen(3,J,Lw));
A:=Cum(SubValues*(J>0));
SumSubVal:=A-ValueWhen(9,J,A);
B:=Cum(AbsDailyVal*(J>0));
SumAbsVal:=B-ValueWhen(9,J,B);
SumSubVal/SumAbsVal;



------------------------ Yahoo! Groups Sponsor --------------------~--> 
Has someone you know been affected by illness or disease?
Network for Good is THE place to support health awareness efforts!
http://us.click.yahoo.com/Rcy2bD/UOnJAA/cosFAA/zMEolB/TM
--------------------------------------------------------------------~-> 

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/Metastockusers/

<*> To unsubscribe from this group, send an email to:
    Metastockusers-unsubscribe@xxxxxxxxxxxxxxx

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