AstroLibLibrary "AstroLib", or Astro Library, is a collection of public Pinescript functions & calculations for use in astrology & astronomy indicators. Unless noted otherwise, this library was written jointly by @badsector666 and @BarefootJoey.
Library "AstroLib"
t_(txt)
Parameters:
txt (string)
JDNv2(t, withFraction)
Parameters:
t (float)
withFraction (bool)
J2K(t)
Parameters:
t (float)
J2KtoUnix(TimeInJDN)
Parameters:
TimeInJDN (float)
atan2(y, x)
Parameters:
y (float)
x (float)
DegSin(x)
Parameters:
x (float)
DegCos(x)
Parameters:
x (float)
DegTan(x)
Parameters:
x (float)
DegArcsin(x)
Parameters:
x (float)
DegArccos(x)
Parameters:
x (float)
DegArctan(x)
Parameters:
x (float)
DegAtan2(y, x)
Parameters:
y (float)
x (float)
range2pi(x)
Parameters:
x (float)
range360(x)
Parameters:
x (float)
gst(days)
Parameters:
days (float)
DegDecimal(Degrees, Minutes, Seconds)
Parameters:
Degrees (float)
Minutes (float)
Seconds (float)
Rectangular(R, theta, phi, Index)
Parameters:
R (float)
theta (float)
phi (float)
Index (float)
rLength(x, y, z)
Parameters:
x (float)
y (float)
z (float)
spherical(x, y, z, Index)
Parameters:
x (float)
y (float)
z (float)
Index (float)
obliquity(d)
Parameters:
d (float)
requatorial(x, y, z, d, Index)
Parameters:
x (float)
y (float)
z (float)
d (float)
Index (float)
recliptic(x, y, z, d, Index)
Parameters:
x (float)
y (float)
z (float)
d (float)
Index (float)
sequatorial(R, theta, phi, d, Index)
Parameters:
R (float)
theta (float)
phi (float)
d (float)
Index (float)
secliptic(R, theta, phi, d, Index)
Parameters:
R (float)
theta (float)
phi (float)
d (float)
Index (float)
precess(d1, d2, DEC, RA, Index, ddec, dra)
Parameters:
d1 (float)
d2 (float)
DEC (float)
RA (float)
Index (float)
ddec (float)
dra (float)
riset(J2000, DEC, RA, GLat, GLong, Index)
Parameters:
J2000 (float)
DEC (float)
RA (float)
GLat (float)
GLong (float)
Index (float)
ssun(d, Index)
Parameters:
d (float)
Index (float)
rsun(d, Index)
Parameters:
d (float)
Index (float)
sun(d, Index)
Parameters:
d (float)
Index (float)
SunLongitude(d, Index)
Parameters:
d (float)
Index (float)
Sunrise(J2000, GLat, GLong, Index, altitudex)
Parameters:
J2000 (float)
GLat (float)
GLong (float)
Index (float)
altitudex (float)
smoon(dx, Index)
Parameters:
dx (float)
Index (float)
rmoon(d, Index)
Parameters:
d (float)
Index (float)
tmoon(d, GLat, GLong, Index)
Parameters:
d (float)
GLat (float)
GLong (float)
Index (float)
moon(d, Index)
Parameters:
d (float)
Index (float)
Element(d, pnum)
Parameters:
d (float)
pnum (int)
kepler(m, ecc, eps)
Parameters:
m (float)
ecc (float)
eps (float)
rplanet(d, pnumber, Index)
Parameters:
d (float)
pnumber (int)
Index (float)
planet(d, pnumber, Index)
Parameters:
d (float)
pnumber (int)
Index (float)
altaz(d, DEC, RA, GLat, GLong, Index)
Parameters:
d (float)
DEC (float)
RA (float)
GLat (float)
GLong (float)
Index (float)
prise(d, P, GLat, GLong, Index)
Parameters:
d (float)
P (int)
GLat (float)
GLong (float)
Index (float)
MoonSize(d)
Parameters:
d (float)
Refraction(Temperature_C, Atmospheric_Pressure_mBar, Altitude_Deg)
Parameters:
Temperature_C (float)
Atmospheric_Pressure_mBar (float)
Altitude_Deg (float)
MoonRise(d, Longitude, Latitude, Index)
Parameters:
d (float)
Longitude (float)
Latitude (float)
Index (float)
f_to_sec(dec)
Parameters:
dec (float)
f_to_time(sec)
Parameters:
sec (float)
deg_to_time(deg)
Parameters:
deg (float)
toDMS(coordinate)
Parameters:
coordinate (float)
convertDMS(lat, lng)
Parameters:
lat (float)
lng (float)
convlatdec(deg)
Parameters:
deg (float)
PlanetName(pnum)
Parameters:
pnum (int)
PlanetNameV(pnum)
Parameters:
pnum (int)
PlanetSign(pnum)
Parameters:
pnum (int)
PlanetColor(pnum)
Parameters:
pnum (int)
zodiaccolor(deg)
Parameters:
deg (float)
degsign(deg)
Parameters:
deg (float)
degsignf(deg)
Parameters:
deg (float)
degnash(deg)
Parameters:
deg (float)
degname(deg)
Parameters:
deg (float)
retrogradesym(deg)
Parameters:
deg (float)
degaspsign(deg)
Parameters:
deg (float)
degaspname(deg)
Parameters:
deg (float)
degaspfull(deg)
Parameters:
deg (float)
degaspfullV2(deg)
Parameters:
deg (float)
degaspnameV2(deg)
Parameters:
deg (float)
degtolowest180(deg)
Parameters:
deg (float)
degaspfullapproach(deg)
Parameters:
deg (float)
virinchiaspectcol(deg, bull_col, bear_col)
Parameters:
deg (float)
bull_col (color)
bear_col (color)
virinchiaspectemo(deg, bull_emo, bear_emo)
Parameters:
deg (float)
bull_emo (string)
bear_emo (string)
aspectfastsigndeg(deg)
Parameters:
deg (float)
aspectfastfull(deg)
Parameters:
deg (float)
aspectslowfull(deg)
Parameters:
deg (float)
aspectslowsigndeg(deg)
Parameters:
deg (float)
aspectslowsign(deg)
Parameters:
deg (float)
aspectsignprecision(deg, precision)
Parameters:
deg (float)
precision (int)
aspectsignprecisionV2(deg, precision)
Parameters:
deg (float)
precision (float)
aspectsignprecisionV2ext(deg, precision)
Parameters:
deg (float)
precision (float)
IPaspectsignprecision(planet1, planet2, precision)
Parameters:
planet1 (float)
planet2 (float)
precision (float)
IPaspectsignprecisionFull(planet1, planet2, precision)
Parameters:
planet1 (float)
planet2 (float)
precision (float)
IPaspectlineprecision(planet1, planet2, precision, style, width)
Parameters:
planet1 (float)
planet2 (float)
precision (float)
style (string)
width (int)
rDeg(deg)
Parameters:
deg (float)
AngToCirc(angle)
Parameters:
angle (float)
AngToCirc180(angle)
Parameters:
angle (float)
sidereal(deg, sidereal)
Parameters:
deg (float)
sidereal (bool)
J2000(JDN)
Parameters:
JDN (float)
JDN(t, d, tz)
Parameters:
t (float)
d (float)
tz (float)
getsun(index, day, dayr, latitude, longitude, tz)
Parameters:
index (int)
day (float)
dayr (float)
latitude (float)
longitude (float)
tz (float)
getmoon(index, day, dayr, latitude, longitude)
Parameters:
index (int)
day (float)
dayr (float)
latitude (float)
longitude (float)
getplanet(planet, index, day, dayr, latitude, longitude, tz)
Parameters:
planet (int)
index (int)
day (float)
dayr (float)
latitude (float)
longitude (float)
tz (float)
Cycle
DominantCycleCollection of Dominant Cycle estimators. Length adaptation used in the Adaptive Moving Averages and the Adaptive Oscillators try to follow price movements and accelerate/decelerate accordingly (usually quite rapidly with a huge range). Cycle estimators, on the other hand, try to measure the cycle period of the current market, which does not reflect price movement or the rate of change (the rate of change may also differ depending on the cycle phase, but the cycle period itself usually changes slowly). This collection may become encyclopaedic, so if you have any working cycle estimator, drop me a line in the comments below. Suggestions are welcome. Currently included estimators are based on the work of John F. Ehlers
mamaPeriod(src, dynLow, dynHigh) MESA Adaptation - MAMA Cycle
Parameters:
src : Series to use
dynLow : Lower bound for the dynamic length
dynHigh : Upper bound for the dynamic length
Returns: Calculated period
Based on MESA Adaptive Moving Average by John F. Ehlers
Performs Hilbert Transform Homodyne Discriminator cycle measurement
Unlike MAMA Alpha function (in LengthAdaptation library), this does not compute phase rate of change
Introduced in the September 2001 issue of Stocks and Commodities
Inspired by the @everget implementation:
Inspired by the @anoojpatel implementation:
paPeriod(src, dynLow, dynHigh, preHP, preSS, preHP) Pearson Autocorrelation
Parameters:
src : Series to use
dynLow : Lower bound for the dynamic length
dynHigh : Upper bound for the dynamic length
preHP : Use High Pass prefilter (default)
preSS : Use Super Smoother prefilter (default)
preHP : Use Hann Windowing prefilter
Returns: Calculated period
Based on Pearson Autocorrelation Periodogram by John F. Ehlers
Introduced in the September 2016 issue of Stocks and Commodities
Inspired by the @blackcat1402 implementation:
Inspired by the @rumpypumpydumpy implementation:
Corrected many errors, and made small speed optimizations, so this could be the best implementation to date (still slow, though, so may revisit in future)
High Pass and Super Smoother prefilters are used in the original implementation
dftPeriod(src, dynLow, dynHigh, preHP, preSS, preHP) Discrete Fourier Transform
Parameters:
src : Series to use
dynLow : Lower bound for the dynamic length
dynHigh : Upper bound for the dynamic length
preHP : Use High Pass prefilter (default)
preSS : Use Super Smoother prefilter (default)
preHP : Use Hann Windowing prefilter
Returns: Calculated period
Based on Spectrum from Discrete Fourier Transform by John F. Ehlers
Inspired by the @blackcat1402 implementation:
High Pass, Super Smoother and Hann Windowing prefilters are used in the original implementation
phasePeriod(src, dynLow, dynHigh, preHP, preSS, preHP) Phase Accumulation
Parameters:
src : Series to use
dynLow : Lower bound for the dynamic length
dynHigh : Upper bound for the dynamic length
preHP : Use High Pass prefilter (default)
preSS : Use Super Smoother prefilter (default)
preHP : Use Hamm Windowing prefilter
Returns: Calculated period
Based on Dominant Cycle from Phase Accumulation by John F. Ehlers
High Pass and Super Smoother prefilters are used in the original implementation
doAdapt(type, src, len, dynLow, dynHigh, chandeSDLen, chandeSmooth, chandePower, preHP, preSS, preHP) Execute a particular Length Adaptation or Dominant Cycle Estimator from the list
Parameters:
type : Length Adaptation or Dominant Cycle Estimator type to use
src : Series to use
len : Reference lookback length
dynLow : Lower bound for the dynamic length
dynHigh : Upper bound for the dynamic length
chandeSDLen : Lookback length of Standard deviation for Chande's Dynamic Length
chandeSmooth : Smoothing length of Standard deviation for Chande's Dynamic Length
chandePower : Exponent of the length adaptation for Chande's Dynamic Length (lower is smaller variation)
preHP : Use High Pass prefilter for the Estimators that support it (default)
preSS : Use Super Smoother prefilter for the Estimators that support it (default)
preHP : Use Hann Windowing prefilter for the Estimators that support it
Returns: Calculated period (float, not limited)
doEstimate(type, src, dynLow, dynHigh, preHP, preSS, preHP) Execute a particular Dominant Cycle Estimator from the list
Parameters:
type : Dominant Cycle Estimator type to use
src : Series to use
dynLow : Lower bound for the dynamic length
dynHigh : Upper bound for the dynamic length
preHP : Use High Pass prefilter for the Estimators that support it (default)
preSS : Use Super Smoother prefilter for the Estimators that support it (default)
preHP : Use Hann Windowing prefilter for the Estimators that support it
Returns: Calculated period (float, not limited)