Welcome Features News Download Registration Support FAQ Wish list Links
Advanced stock charting and analysis program

AFL Library

This is read-only version of AFL library entry. Ability to add user formulas and comment is only available from members-only area.

Details:

Formula name: LunarPhase
Author/Uploader: Marcelin Tudor - marcelint [at] gmail.com
Date/Time added: 2006-09-03 10:02:09
Origin:
Keywords:
Level: basic
Flags: exploration

DISCLAIMER: Most formulas present in AFL on-line library are submitted by the users and are provided here on an "as is" and "as available" basis. AmiBroker.com makes no representations or warranties of any kind to the contents or the operation of material presented here. We do not maintain nor provide technical support for 3rd party formulas.
Description:

Plot Full Moon and New Moon on your chart. Simply and easy.

Formula:

// Input your local time zone
TZ=Param("Your local Time Zone? [-12 to +12hrs]",2, -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 in own window }

SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g,
Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle |
ParamStyle("Style") | GetPriceStyle() ); 

SetChartBkGradientFill( ParamColor("BgTop", colorWhite),ParamColor("BgBottom",
colorLightYellow));

shape =
IIf(FullMoon,shapeCircle+shapePositionAbove,IIf(NewMoon,shapeCircle+shapePositionAbove,Null));

PlotShapes(shape,IIf(FullMoon,colorYellow,colorBlack),0,H);

Comments:

Jean-Claude Mongeau
jmongeau [at] telusplanet.net
2006-09-03 13:31:27
Hi, would love to be able to use your formula but I get an error on ln:41 col:23 error 30, syntax error
line starts with SetChartBkGradientFill
thank you...keep up the good work
Lal

2006-09-03 13:59:27
Jean-Claude, your Amibroker version is probably pre-4.83. If that is case, SetChartBkGradientFill will not work. Just comment out the lines of code that use the function and you should be fine.
Jean-Claude
jmongeau [at] telusplanet.net
2006-09-03 15:32:23
Thank you Lal, it works...
Lal

2006-09-03 18:19:11
Jean-Claude, your Amibroker version is probably pre-4.83. If that is case, SetChartBkGradientFill will not work. Just comment out the lines of code that use the function and you should be fine.
dixit

2006-09-06 05:04:51
Hi Marcelin, is possibile to implement for plotting Waxing Cresent and Waxing Gibbous phases ?
Thanks.
Marcelin
marcelint [at] gmail.com
2006-09-06 07:47:34
Yes, it's possible, but Amibroker has not symbols for these phases to plot on chart.
dixit

2006-09-07 12:54:01
You are right.
Passing over, but still about Moon, would you consider to use the "shapeUpTriangle" for the First Quarter Moon (the fraction of the Moon's disk that is illuminated is increasing), and the "shapeDownTriangle" for the Last Quarter Moon (the fraction of the Moon's disk that is illuminated is decreasing).

Thanks.
Paul
paulradge [at] optusnet.com.au
2006-10-07 06:29:28
Hi Lal,
i'm an absolute newbie,could you please tell which part of this line i change to -10 hours,

TZ=Param("Your local Time Zone? [-12 to +12hrs]",2, -12,12,1);

please,
kj
jeromekj [at] msn.com
2007-02-10 00:39:14
Lal I am new to Ami and really new to writing any thing that looks like code. I have been teaching myself for a few months in what will be an entertaining challenge for a long time. A few questions if you have the time, First would be... how does the offset work and where or how did you arrive @ that, Second, do you have a reference to a "first" moon date and then the rest of the formula calcs time frame * date / lunar cycle or is there something I’m missing as in "a" "lunar" function?

Thanks!
kj
jeromekj [at] msn.com
2007-02-10 00:39:42
Lal I am new to Ami and really new to writing any thing that looks like code. I have been teaching myself for a few months in what will be an entertaining challenge for a long time. A few questions if you have the time, First would be... how does the offset work and where or how did you arrive @ that, Second, do you have a reference to a "first" moon date and then the rest of the formula calcs time frame * date / lunar cycle or is there something I’m missing as in "a" "lunar" function?

Thanks!
kj
jeromekj [at] msn.com
2007-02-10 00:51:21
I have no idea what those characters are. I ment to say "is there something Im missing as in "a" "lunar" function?"

Oh my mistake question was for Marcelin but Lal your welcome to answer:)

Thanks Again Marcelin nice work


About | Privacy | Terms of Use | Contact information
Copyright © 2001 AMIBROKER.COM