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

[EquisMetaStock Group] Weekly EMA & SMA for daily & intraday charts



PureBytes Links

Trading Reference Links

And here are weekly EMA & SMA indicators for daily & intraday charts, 
based on the new weekly signals code:


===================
Weekly EMA of Close
===================
---8<---------------------------

{ True weekly Close Exponential Mov Avg 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 EMA periods",1,520,4);
shift:=1+Input("EMA vertical shift %",
 -100,100,0)/100;
EOW:=Input("Final week's end:  [1]True,  [2]Current (dynamic)",1,2,2);
plot:=Input("plot:  [1] EMA,  [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);

{ Reduce periodicity if insufficient periods }
pds:=If(pds>Cum(WkEnd),Cum(WkEnd),pds);

{ Weekly EMA }
WkEma:=ValueWhen(1,WkEnd,PREV)
 *(1-2/(pds+1))+WkCl*2/(pds+1);

{ Vertical shift }
WkEma:=WkEma*shift;

{ Crossover signals }
signals:=Cross(C,WkEma)-Cross(WkEma,C);

{ Plot on price chart }
If(plot=2,signals,WkEma)

---8<---------------------------



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


jose '-)
http://www.metastocktools.com




--- In equismetastock@xxxxxxxxxxxxxxx, "Jose Silva" <josesilva22@xxxx>
> wrote:
> 
> Programming code to signal the true start of a trading week is 
> relatively easy in MetaStock.
> However, code that signals the true last day of the trading week (or 
> EOW), has been one of MetaStock's Holy Grail.
> 
> The difficulty lies in detecting that last trading day of the week 
> when we all start our weekend a day or more early.
> DayOfWeek()=5 (Friday) does not work when the last day of the week 
> falls on a Thursday, Wednesday (or even Monday & Tuesday with some 
> illiquid securities).
> 
> How is it possible for MetaStock to know about these irregular EOW 
> signals?  Well, with a little hindsight.
> Correct start & end of week signals for daily/intraday charts, 
> independent of any missing chart data:
> 
> 
> MetaStock -> Tools -> Indicator Builder -> New
> -> Copy and paste formula below.
> 
> 
> =======================
> Week's true Start & End
> =======================
> ---8<---------------------------
> 
> { Week's true start & end of week (EOW) v2.0 }
> { Confirms EOW signal at start of following
>    week, and signals EOW in retrospect.}
> { Signals independent of any missing chart data}
> { For daily & intraday 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);
> 
> { Week's end signal }
> 
> { Choice of Static/Dynamic last EOW signal }
> EOW:=If(EOW=2,Cum(1)=LastValue(Cum(1)),
>  Cum(1)=LastValue(Cum(1)) AND DayOfWeek()=5);
> 
> { Detect other than daily/intraday charts }
> detect:=LastValue(Cum(
>  WkCount=ValueWhen(2,1,WkCount)))=0;
> 
> { Make EOW signal visible for weekly+ charts }
> WeekEnd:=PeakBars(1,-(If(detect=0,
>   WeekStart OR Cum(IsDefined(WeekStart))=1,
>   Cum(1)/2=Int(Cum(1)/2))),1)=0
>  OR EOW;
> WeekEnd:=If(detect=0,WeekEnd,1);
> 
> { Plot signals in own window }
> WeekStart;-WeekEnd
> 
> ---8<---------------------------
> 
> 
> 
> Now, what's so important about needing to plot accurate start/end of 
> week signals?
> This becomes essential when building weekly indicators for daily & 
> intraday charts - they require accurate start & end-of-week signals.
> The above basic indicator can be easily referenced by other
> MetaStock formulae, making the process of designing weekly
> indicators a lot easier.
> 
> Here is another basic example, weekly Open/High/Low/Close for daily
> & intraday charts:
> 
> 
> ===========
> Weekly OHLC
> ===========
> ---8<---------------------------
> 
> { Weekly OHLC for daily/intraday charts v2.0 }
> { Requires "Week's true start & end" indicator }
> 
> { ©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.
>   josesilva22@xxxx }
> 
> { User inputs }
> pds:=Input("Week's OHLC:  [1]Current,  [2]Previous",1,2,1);
> EOW:=Input("Final week's end:  [1]True,  [2]Current (dynamic)",1,2,
2);
> 
> { Week's true Start }
> WkStart:=
>  FmlVar("Week's true start & end","WEEKSTART");
> 
> { 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 true End (EOW) }
> WkEnd:=EOW OR
>  FmlVar("Week's true start & end","WEEKEND");
> 
> { Week's Open }
> wkOp:=ValueWhen(pds,WkStart,O);
> wkOp:=ValueWhen(1,wkOp>0,wkOp);
> 
> { Week's High }
> Hi:=HighestSince(1,WkStart,H);
> wkHi:=If(pds=1,Hi,
>  ValueWhen(1,WkStart,Ref(Hi,-1)));
> wkHi:=ValueWhen(1,wkHi>0,wkHi);
> 
> { Week's Low }
> Lo:=LowestSince(1,WkStart,L);
> wkLo:=If(pds=1,Lo,
>  ValueWhen(1,WkStart,Ref(Lo,-1)));
> wkLo:=ValueWhen(1,wkLo>0,wkLo);
> 
> { Week's Close }
> wkCl:=ValueWhen(pds,WkEnd,C);
> wkCl:=ValueWhen(1,wkCl>0,wkCl);
> 
> { Plot on price chart }
> wkOp;wkHi;wkLo;wkCl
> 
> ---8<---------------------------
> 
> Note that with the weekly OHLC indicator, the High/Low of the week
> are always dynamic in the current week, since their values cannot be 
> known until the end of the trading week without cheating Father
> Time...
> 
> 
> With these two basic code components as reference for other code,
> just about any true weekly indicator can be coded in MetaStock (no
> requests please).  :)
> 
> 
> jose '-)
> http://www.metastocktools.com




------------------------ Yahoo! Groups Sponsor --------------------~--> 
Try Online Currency Trading with GFT. Free 50K Demo. Trade 
24 Hours. Commission-Free. 
http://us.click.yahoo.com/RvFikB/9M2KAA/U1CZAA/BefplB/TM
--------------------------------------------------------------------~-> 

 
Yahoo! Groups Links

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

<*> 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/