Rank: Advanced Member
Groups: Registered, Registered Users Joined: 3/19/2005(UTC) Posts: 2,995
Was thanked: 14 time(s) in 10 post(s)
|
Hey RCM-
Welcome to the forum!
I'm not the best person to answer this question, but maybe I can lead you to your own discovery. Right now, our search function on the forum is broken. It makes it hard to look up things that could be helpful. Indirectly, I believe that your question has been answered already. But where is that answer? IMO, Jose Silva has written your code, albeit in peices. Avail: http://www.metastocktools.com/;2)
=========================
---8<---------------------------
{ Week's true start & end of week (EOW) vPREVx2}
{ Confirms EOW signal at start of following
week, and signals EOW in retrospect.
Signals independent of any missing chart data.
For use with highly irregular & sporadic
(lots of missing data) daily & intraday
charts.
Use v2.0 signals for normal (liquid) charts.}
{ ©Copyright 2002~2005 Jose Silva
The grant of this license is for personal use
only - no resale or repackaging allowed.
All code remains the property of Jose Silva.}
{ http://www.metastocktools.com }
{ User input }
EOW:=Input("Final week's end: [1]True, [2]Current (dynamic)",1,2,1);
{ Calendar Week counter }
limit:=2000; {do not change limit year}
LimLeap:=Frac(limit/4)=0 AND Frac(limit/100)<>0
OR Frac(limit/400)=0;
NoCount:=limit*365+Int(limit/4)
-Int(limit/100)+Int(limit/400)-LimLeap;
leap:=Frac(Year()/4)=0 AND Frac(Year()/100)<>0
OR Frac(Year()/400)=0;
y:=Year()*365+Int(Year()/4)
-Int(Year()/100)+Int(Year()/400)-NoCount;
m:=
If(Month()=2,31-leap,
If(Month()=3,59,
If(Month()=4,90,
If(Month()=5,120,
If(Month()=6,151,
If(Month()=7,181,
If(Month()=8,212,
If(Month()=9,243,
If(Month()=10,273,
If(Month()=11,304,
If(Month()=12,334,
-leap)))))))))));
DayNr:=y+m+DayOfMonth();
WkCount:=Int((DayNr-1)/7)+(Year()>=limit);
{ Week's start signal }
WeekStart:=WkCount>Ref(WkCount,-1);
{ Choice of Static/Dynamic last EOW signal }
EOW:=If(EOW=2,Cum(1)=LastValue(Cum(1)),
Cum(1)=LastValue(Cum(1)) AND DayOfWeek()=5);
{ Week's end signal }
WeekEnd:=LastValue(Ref(WeekStart,1)+PREV-PREV)
OR EOW;
{ Plot signals in own window }
WeekStart;-WeekEnd
---8<--------------------------- [/code:1:a3ed08c323]
Code 2:
[code:1:a3ed08c323]===================
Weekly SMA of Close
===================
---8<---------------------------
{ True weekly Close Simple Moving Average v5.0 }
{ For daily/intraday charts }
{ Requires "Week's true Start & End" indicator }
{ Plot is independent of any missing chart data}
{ ©Copyright 2002~2005 Jose Silva
The grant of this license is for personal use
only - no resale or repackaging allowed.
All code remains the property of Jose Silva.
http://www.metastocktools.com }
{ User inputs }
pds:=Input("Weekly SMA periods",1,520,4);
shift:=1+Input("SMA vertical shift %",
-100,100,0)/100;
EOW:=Input("Final week's end: [1]True, [2]Current (dynamic)",1,2,2);
plot:=Input("plot: [1] SMA, [2] Crossover signals",1,2,1);
{ Choice of Static/Dynamic last EOW signal }
EOW:=If(EOW=2,Cum(1)=LastValue(Cum(1)),
Cum(1)=LastValue(Cum(1)) AND DayOfWeek()=5);
{ Reference EOW signals }
WkEnd:=EOW OR
FmlVar("Week's true Start & End","WEEKEND");
{ Week's Close }
WkCl:=ValueWhen(1,WkEnd,C);
WkCl:=ValueWhen(1,WkCl>0,WkCl);
{ Weekly SMA }
z:=Cum(WkEnd*WkCl);
WkSma:=(z-ValueWhen(pds+1,WkEnd,z))/pds;
{ Vertical shift }
WkSma:=WkSma*shift;
{ Crossover signals }
signals:=Cross(C,WkSma)-Cross(WkSma,C);
{ Plot on price chart }
If(plot=2,signals,WkSma)
---8<--------------------------- [/code:1:a3ed08c323]
Code 3:
[code:1:a3ed08c323]{ True, Reverse & MetaStock ATR v3.0 }{ ©Copyright 2004 Jose Silva }{ josesilva22@yahoo.com }
{ Reverse True Range is the the *smallest* of the following for each period:
* The distance from today's High to today's Low;
* The distance from yesterday's Close to today's High;
* The distance from yesterday's Close to today's Low.}
{ user input }
plot:=Input("[1]True ATR, [2]Reverse ATR, [3]Both, [4]MS-ATR",1,4,1);
pds:=Input("Average True Range periods",1,252,10);
pdsN:=Input("normalizing periods (1=none)",1,2520,1);
smooth:=Input("Sine-weighted smoothing? [1]Yes, [0]No",0,1,0);
{ define True Range }
x1:=ValueWhen(2,1,C);
TrueRange:=Max(H-L,Max(Abs(x1-H),Abs(x1-L)));
RevTrueRange:=Min(H-L,Min(Abs(x1-H),Abs(x1-L)));
{ average True Range }
ATRtrue:=Mov(TrueRange,pds,E);
ATRrev:=Mov(RevTrueRange,pds,E);
ATRmeta:=Mov(TrueRange,pds*2-1,E);
{ normalize ATR }
ATRraw:=If(plot=1,ATRtrue,If(plot=2,ATRrev,If(plot=4,ATRmeta,ATRtrue)));
ATRnorm:=100*(ATRraw-LLV(ATRraw,pdsN))/(HHV(ATRraw,pdsN)-LLV(ATRraw,pdsN)+.000001);
ATRplot:=If(pdsN<2,ATRraw,ATRnorm);
rATRnorm:=100*(ATRrev-LLV(ATRrev,pdsN))/(HHV(ATRrev,pdsN)-LLV(ATRrev,pdsN)+.000001);
rATRplot:=If(pdsN<2,RevTrueRange,rATRnorm);
{ optional sine-weighted smoothing }
ATRplot:=If(smooth=1,(Sin(30)*ATRplot
+Sin(60)*Ref(ATRplot,-1)
+Sin(90)*Ref(ATRplot,-2)
+Sin(60)*Ref(ATRplot,-3)
+Sin(30)*Ref(ATRplot,-4))
/(Sin(30)*2+Sin(60)*2+Sin(90)),ATRplot);
rATRplot:=If(smooth=1,(Sin(30)*rATRplot
+Sin(60)*Ref(rATRplot,-1)
+Sin(90)*Ref(rATRplot,-2)
+Sin(60)*Ref(rATRplot,-3)
+Sin(30)*Ref(rATRplot,-4))
/(Sin(30)*2+Sin(60)*2+Sin(90)),rATRplot);
{ plot ATR }
If(plot=3,rATRplot,ATRplot);
ATRplot[/code:1:a3ed08c323]
|