Moon Cycles:
If it can be useful to someone, I insert here the formulas: in Easylanguage (for Tradestation and Multicharts), for Amibroker and Metastock.
----------------------------------------------------------------------------
Lunar Cycles for Tradestation and Multicharts:
for Full Moon Cycles, obviously changing the dates, you can insert also the New Moon Cycles.
LUNARCYCLE: Plots a dot every 27 days, so if you type a full moon date as the input, it will continue to show you full moon days.
Note: Date should be entered as YYMMDD.
---------------------------------------------------------------------------
Function: LUNARCICLE
[LegacyColorValue = true];
Input: MOON1(Numeric);
LUNARCICLE = INTPORTION((DATETOJULIAN(DATE) - DATETOJULIAN(MOON1)) / 27)
-----------------------------------------------------------------------------
Indicator:
[LegacyColorValue = true];
INPUT:VALUE(960305);
VALUE1 = LUNARCICLE(VALUE);
IF VALUE1 > VALUE1[1] THEN
PLOT1(H,"FULLMOON");
----------------------------------------------------------------------------------
To be included in the: ShowMe:
{Full_Moon}
Vars:AstroJul(0),Phase(0);
AstroJul =DateToJulian(Date)+ 2415019 ;
Print("Date",Date);
Phase = (AstroJul+4.867) / 29.53059 ;
Phase = FracPortion(Phase);
Print("Phase",Phase);
If Phase >= 0.90 then print("Full Moon");
If Phase >= 0.5 and phase <= 0.90 then print("Waxing Moon");
If Phase >= 0.47 and phase <= 0.5 then print( "New Moon");
If Phase <= 0.5 and Phase >= 0.2 then print("Waning Moon");
If Phase >=0.90 then Plot1(High,"SHOWME");
-----------------------------------------------------------
{New_Moon}
Vars:AstroJul(0),Phase(0);
AstroJul =DateToJulian(Date)+ 2415019 ;
Print("Date",Date);
Phase = (AstroJul+4.867) / 29.53059 ;
Phase = FracPortion(Phase);
Print("Phase",Phase);
If Phase >= 0.90 then print("Full Moon");
If Phase >= 0.5 and phase <= 0.90 then print("Waxing Moon");
If Phase >= 0.47 and phase <= 0.5 then print( "New Moon");
If Phase <= 0.5 and Phase >= 0.2 then print("Waning Moon");
If Phase >=0.45 and phase <= 0.52 then Plot1(High,"SHOWME");
======================================================================================
Lunar Cycles for AmiBroker:
_SECTION_BEGIN( "Price Chart" );
SetChartOptions( 0, chartShowArrows | chartShowDates );
//GraphXSpace = 5;
Y = SelectedValue(Year());
M = SelectedValue(Month());
D = SelectedValue(Day());
Hr = SelectedValue(Hour());
Mn = SelectedValue(Minute());
// normalize values to range 0...1
function normalize( Val )
{
Val = Val - floor( Val );
if (Val < 0) {Val = Val + 1;}
return Val;
}
// Set Pi.
PI = 3.1415926535897932385;
// calculate the Julian Date at 12H UT
YY = Y - floor( ( 12 - M ) / 10 );
MM = M + 9;
if (MM >= 12) {MM = MM - 12;}
K1 = floor( 365.25 * ( YY + 4712 ) );
K2 = floor( 30.6 * MM + 0.5 );
K3 = floor( floor( ( YY / 100 ) + 49 ) * 0.75 ) - 38;
JD = K1 + K2 + D + 59; // for dates in Julian calendar
if (JD > 2299160) {JD = JD - K3;} // for Gregorian calendar
// calculate moon's age in days
IP = normalize( ( JD - 2451550.1 ) / 29.530588853 );
AG = IP*29.53;
Phase = "NEW";
if (AG < 27.68493) {Phase = "Waning crescent";S1=4;S2=8;}
if (AG < 23.99361) {Phase = "Last quarter";S1=4;S2=12;}
if (AG < 20.30228) {Phase = "Waning gibbous";S1=6;S2=14;}
if (AG < 16.61096) {Phase = "FULL";S1=6;S2=15;}
if (AG < 12.91963) {Phase = "Waxing gibbous";S1=6;S2=7;}
if (AG < 9.22831) {Phase = "First quarter";S1=2;S2=3;}
if (AG < 5.53699) {Phase = "Waxing crescent";S1=2;S2=1;}
if (AG < 1.84566) {Phase = "NEW";S1=0;S2=0;}
IP1 = IP;
IP = IP*2*PI; // Convert phase to radians
// calculate moon's distance
DP = 2*PI*normalize( ( JD - 2451562.2 ) / 27.55454988 );
DI = 60.4 - 3.3*cos( DP ) - 0.6*cos( 2*IP - DP ) - 0.5*cos( 2*IP );
// calculate moon's ecliptic latitude
NP = 2*PI*normalize( ( JD - 2451565.2 ) / 27.212220817 );
LA = 5.1*sin( NP );
// calculate moon's ecliptic longitude
RP = normalize( ( JD - 2451555.8 ) / 27.321582241 );
LO = 360*RP + 6.3*sin( DP ) + 1.3*sin( 2*IP - DP ) + 0.7*sin( 2*IP );
Zodiac = "Pisces";
if (LO < 348.58) {Zodiac = "Aquarius";}
if (LO < 311.72) {Zodiac = "Capricorn";}
if (LO < 302.49) {Zodiac = "Sagittarius";}
if (LO < 271.26) {Zodiac = "Scorpio";}
if (LO < 242.57) {Zodiac = "Libra";}
if (LO < 224.17) {Zodiac = "Virgo";}
if (LO < 173.34) {Zodiac = "Leo";}
if (LO < 135.30) {Zodiac = "Cancer";}
if (LO < 119.48) {Zodiac = "Gemini";}
if (LO < 93.44) {Zodiac = "Taurus";}
if (LO < 51.16) {Zodiac = "Aries";}
if (LO < 33.18) {Zodiac = "Pisces";}
Plot( C, "Close", colorBrightGreen, styleNoTitle | ParamStyle( "Style" ) | GetPriceStyle() );
_N(Title = Name() + " - " + Date() + " Open " + C + " High " + H + " Low " + L + " Close " + C + "\n" +
"Age: " + AG + " Phase: " + Phase + "\n" +
"Distance: " + DI + " earth radii ecliptic\n" +
"Latitude = " + LA + "°\n" +
"Longitude = " + LO + "°\n" +
"Constellation = " + Zodiac+ "\n" +
"IP: " + IP1);
_SECTION_END();
_SECTION_BEGIN("Lunar Cycle");
// Input your local time zone
TZ=Param("Your local Time Zone? [-12 to +12hrs]",5.5, -12,12,1);
// Lunar cycle
LunarMonth=29.530589;
Offset=7.254621;
// Calendar }
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);
m=
IIf(Month()==2,31-leap,
IIf(Month()==3,59,
IIf(Month()==4,90,
IIf(Month()==5,120,
IIf(Month()==6,151,
IIf(Month()==7,181,
IIf(Month()==8,212,
IIf(Month()==9,243,
IIf(Month()==10,273,
IIf(Month()==11,304,
IIf(Month()==12,334, -leap))))))) ))));
CurrentDay=y+ m+Day()-TZ/ 24-Offset;
// Full Moon }
FM=frac(CurrentDay/ LunarMonth) ;
FM=PeakBars( FM, 1, 1)==0;
// New Moon }
NM=frac((CurrentDay +LunarMonth/ 2)/LunarMonth) ;
NM=PeakBars( NM, 1,1)==0;
FullMoon=FM-NM==1;
NewMoon=FM-NM==-1;
//Plot Moon Phase on main chart
MC = ParamToggle("Moon Cycle","Show|Hide",0);
shape = IIf(FullMoon,shapeCircle+shapePositionAbove,IIf(NewMoon,shapeCircle+shapePositionAbove,Null));
if(MC==1) PlotShapes(shape,IIf(FullMoon,colorWhite,colorYellow),0,H);
_SECTION_END();
==============================================================================================================
Lunar Cycles for Metastock:
{Lunar cycles - by Jose Silva}
{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.}
{ 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 AND Alert(cycle>0,2);
NM:=-(cycle>0 AND Alert(cycle<0,2));
cycle:=Q1-Q3;
Q1:=(cycle<0 AND Alert(cycle>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
------------------------------------------------------------------------------------