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

Re: [amibroker] Re: Moon Phase Indicator



PureBytes Links

Trading Reference Links

Here is another one, Converted to AFL.

_SECTION_BEGIN("LunaPhase");
// Luna Phase Calculator.
// Code converted from: http://home.att.net/~srschmitt/lunarphasecalc.html
// OzFalconAB

// Get Day/Month/Year in number format (NOT array).
Y = SelectedValue(Year()); M = SelectedValue(Month()); D = 
SelectedValue(Day());


// 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";}


_N(Title = "Date = " + Y + "/" + M + "/" +D + "\n" +
    "Age: " + AG + "     Phase: " + Phase + "\n" +
    "distance: " + DI + " earth radii\n" +
    "ecliptic\n" +
    " latitude  = " + LA + "°\n" +
    " longitude = " + LO + "°\n" +
    "constellation = " + Zodiac+ "\n" +
    "IP: " + IP1);


Color = IIf(O > C, colorBlack, colorYellow);
Plot( Close, "Price", color, styleCandle | styleOwnScale );
_SECTION_END();










thorstef2003 wrote:
>
> Thanks again, to all who helped with special thanks to Dave and
> raintree.
>
> --- In amibroker@xxxxxxxxxxxxxxx <mailto:amibroker%40yahoogroups.com>, 
> e <e.winters1@xxx> wrote:
> >
> > TZ == Time Zone in relation to GMT.
> > -10 Hawaii
> > -5 NY
> > +3 Baghdad
> > etc.
> >
> > thorstef2003 wrote:
> > > Thank you, raintree!
> > > TZ = Param("Time Zone",-5,-12,12);
> > > Can you provide an example of "Time Zone"? If a number then is it
> with
> > > reference to GMT?
> > >
> > > --- In amibroker@xxxxxxxxxxxxxxx 
> <mailto:amibroker%40yahoogroups.com>, e <e.winters1@> wrote:
> > >> Translated:
> > >> // Full/New Moon signals indicator
> > >> // Accurate to within 1 Minute per 69 years }
> > >>
> > >> // Plots +1 Signal on Full Moon; -1 on New Moon
> > >> // if FM/NM falls on a holiday OR weekend,
> > >> // Signal is plotted on the nearest trading Day }
> > >> // Warning: will NOT Plot last FM/NM Signal
> > >> // until it is confirmed on next trade Day }
> > >>
> > >> // Input your world time zone
> > >> TZ = Param("Time Zone",-5,-12,12);
> > >>
> > >> // Lunar cycle
> > >> LunarMonth = 29.530589;
> > >> Offset = 7.254621;
> > >>
> > >> // Calendar
> > >> // leap = frac(Year()/4)=0 AND frac(Year()/100)<0 OR frac(Year()/
> > > 400)=0;
> > >> leap1 = IIf(frac(Year()/4)==0,1,0);
> > >> leap2 = IIf(frac(Year()/100)<0,1,0);
> > >> leap3 = IIf(frac(Year()/400)==0,1,0);
> > >> leap = Leap1 AND Leap2 AND Leap3;
> > >>
> > >> 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/New Moon }
> > >> FM = frac(CurrentDay/LunarMonth);
> > >> NM = frac(FM+0.5);
> > >>
> > >> // Plot in own window below chart }
> > >> Plot(fm,"Full Moon",colorBlue,styleLine);
> > >> Plot(nm,"New Moon",colorRed,styleLine);
> > >> // (PeakBars(1,FM,.01)=0)-(PeakBars(1,NM,.01)=0)
> > >> Filter=1;
> > >>
> > >> thorstef2003 wrote:
> > >>> Thank you, Dave.
> > >>> Was hoping someone had the AFL, but this link is a good step
> > > forward.
> > >>> Very surprising, that after so many years of AB, nobody
> programmed
> > > a
> > >>> moon phase AFL!?
> > >>>
> > >>>>>> { Full/New Moon signals indicator MkVI }
> > >>>>>> { Accurate to within 1 minute per 69 years }
> > >>>>>> { ©Copyright 2002-2004 jose silva }
> > >>>>>> { For personal use only }
> > >>>>>> { josesilva22@xxxx }
> > >>>>>>
> > >>>>>> { Plots +1 signal on Full Moon; -1 on New Moon }
> > >>>>>> { If FM/NM falls on a holiday or weekend,
> > >>>>>> signal is plotted on the nearest trading day }
> > >>>>>> { Warning: will not plot last FM/NM signal
> > >>>>>> until it is confirmed on next trade day }
> > >>>>>>
> > >>>>>> { Input your world time zone }
> > >>>>>> TZ:=Input("Your Time Zone? (-12 to +12hrs)",
> > >>>>>> -12,12,10);
> > >>>>>>
> > >>>>>> { 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:=
> > >>>>>> 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)))))))))));
> > >>>>>> CurrentDay:=y+m+DayOfMonth()-TZ/24-Offset;
> > >>>>>>
> > >>>>>> { Full/New Moon }
> > >>>>>> FM:=Frac(CurrentDay/LunarMonth);
> > >>>>>> NM:=Frac(FM+0.5);
> > >>>>>>
> > >>>>>> { Plot in own window below chart }
> > >>>>>> (PeakBars(1,FM,.01)=0)-(PeakBars(1,NM,.01)=0)
> > >>>>>>
> > >>> Anyone able to translate this?
> > >>>
> > >>> --- In amibroker@xxxxxxxxxxxxxxx 
> <mailto:amibroker%40yahoogroups.com>, "MarketMonk777" <dlittner@>
> > >>> wrote:
> > >>>> Hi Stef,
> > >>>>
> > >>>> Check out this link:
> > >>>> http://www.purebytes.com/archives/metastock/2004/msg05973.html 
> <http://www.purebytes.com/archives/metastock/2004/msg05973.html>
> > >>>>
> > >>>> The code is for MetaStock but am fairly certain it can be
> > > converted.
> > >>>> And here is a long winded conversation about planet's and the
> > >>> markets:
> > >>>> http://www.purebytes.com/archives/omega/2003/msg05801.html 
> <http://www.purebytes.com/archives/omega/2003/msg05801.html>
> > >>>>
> > >>>> And finally, code for Omega Tradestation, which is a little bit
> > >>> tougher in
> > >>>> some cases to convert:
> > >>>> http://www.purebytes.com/archives/omega/2002/msg00476.html 
> <http://www.purebytes.com/archives/omega/2002/msg00476.html>
> > >>>>
> > >>>> Regards,
> > >>>>
> > >>>> Dave
> > >>>> MarketMonk
> > >>>>
> > >>>> -----Original Message-----
> > >>>> From: amibroker@xxxxxxxxxxxxxxx 
> <mailto:amibroker%40yahoogroups.com> [mailto:amibroker@xxxxxxxxxxx.
> > > com]
> > >>> On Behalf
> > >>>> Of thorstef2003
> > >>>> Sent: Sunday, July 09, 2006 9:31 AM
> > >>>> To: amibroker@xxxxxxxxxxxxxxx <mailto:amibroker%40yahoogroups.com>
> > >>>> Subject: [amibroker] Moon Phase Indicator
> > >>>>
> > >>>> Hi,
> > >>>> I've gone through all the archives and nobody seems to have
> > >>> programmed an
> > >>>> indicator to overlay moon pases on the price charts.
> > >>>> Can somebody please provide a link or the AFL of a moon phase
> > >>> indicator?
> > >>>> Thanks.
> > >>>> Stef
> > >>>>
> > >>>>
> > >>>>
> > >>>>
> > >>>>
> > >>>> Please note that this group is for discussion between users
> only.
> > >>>>
> > >>>> To get support from AmiBroker please send an e-mail directly to
> > >>> SUPPORT {at}
> > >>>> amibroker.com
> > >>>>
> > >>>> For other support material please check also:
> > >>>> http://www.amibroker.com/support.html 
> <http://www.amibroker.com/support.html>
> > >>>>
> > >>>>
> > >>>> Yahoo! Groups Links
> > >>>>
> > >>>
> > >>>
> > >>>
> > >>>
> > >>>
> > >>>
> > >>> Please note that this group is for discussion between users
> only.
> > >>>
> > >>> To get support from AmiBroker please send an e-mail directly to
> > >>> SUPPORT {at} amibroker.com
> > >>>
> > >>> For other support material please check also:
> > >>> http://www.amibroker.com/support.html 
> <http://www.amibroker.com/support.html>
> > >>>
> > >>>
> > >>> Yahoo! Groups Links
> > >>>
> > >>>
> > >>>
> > >>>
> > >>>
> > >>>
> > >>>
> > >>>
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > Please note that this group is for discussion between users only.
> > >
> > > To get support from AmiBroker please send an e-mail directly to
> > > SUPPORT {at} amibroker.com
> > >
> > > For other support material please check also:
> > > http://www.amibroker.com/support.html 
> <http://www.amibroker.com/support.html>
> > >
> > >
> > > Yahoo! Groups Links
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> >
>
>