Lunar Cycle indicator for MetaStock

See previous post for charts.
This indicator is free to download from Jose Silva @ metastocktools.com
Extra infomation about the indicator is available from metastocktools.com

MetaStock -> Tools -> Indicator Builder -> New
-> copy & paste complete formula below.


============
Lunar cycles
============
---8<-----------------------------------------

{Full/New/Q1/Q3 Moon signals indicator Mk XV.

Plots:
+1 signal on Full Moon; -1 on New Moon;
+0.5 on first Quarter; -0.5 on last Quarter.
Accurate to within 2 hours every 19 years.

Signals that fall on holidays or weekends
are plotted on the next trading day.
Use the signal advance input to view
approaching signals.

Adj lunar signals to market's local Time Zone
(generally add 1hr for Daylight Saving Time):

New Zealand: +12hrs
Australia: +10
Japan: +9
SE Asia: +8
Thai/Indonesia: +7
India: +5.5
Dubai: +4
Moscow: +3
Europe: +1
UK & Portugal: 0
USA, NY: -5
Chicago: -6

http://www.travel.com.hk/region/timezone.htm

Copyright © 2001-2009 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 }
TZ:=Input("Market's local Time Zone? [-12hrs to +12hrs]",-12,12,-5);
shift:=Input("Advance signal by x calendar days",-30,30,0);
plot:=Input("Plot Q1 and Q3 (half) signals? [1]Yes, [0]No",0,1,0);

{ Lunar cycle length in days (synodic month) }
LunarMonth:=29.53059;
offset:=4.86;

{ Calendar engine }
y:=Year()-(Month()<3);
leap:=Int(y/4)-Int(y/100)+Int(y/400);
mth:=Int((2+153*(Month()-3+12*(Month()<3)))/5);
dayNr:=DayOfMonth()+mth+y*365+leap-657382
-offset-TZ/24+shift;

{ New/Q1/Full/Q3 Moon cycles }
NM:=Frac((DayNr+LunarMonth/2)/LunarMonth);
Q1:=Frac((DayNr+LunarMonth/4)/LunarMonth);
FM:=Frac(DayNr/LunarMonth);
Q3:=Frac((DayNr-LunarMonth/4)/LunarMonth);

{ Lunar cycle signals }
cycle:=FM-NM;
FM:=cycle<0>0,2);
NM:=-(cycle>0 AND Alert(cycle<0,2));
cycle:=Q1-Q3;
Q1:=(cycle<0>0,2))*.5;
Q3:=(cycle>0 AND Alert(cycle<0,2))*-.5;
signals:=If(plot=1,NM+Q1+FM+Q3,NM+FM);

{ Plot Lunar signals in own window }
signals

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

No comments:

Post a Comment

 
Design Credit Best Blogger Tips | Best Blogger Templates | Best Social Icons