Fasi Lunari (Moon Phases)
Forums › ProRealTime forum Italiano › Supporto ProBuilder › Fasi Lunari (Moon Phases)
- This topic has 10 replies, 3 voices, and was last updated 4 years ago by
giadelo.
-
-
03/19/2019 at 9:44 AM #9399803/19/2019 at 10:25 AM #9401003/19/2019 at 10:54 AM #94014
ho trovato questi, ma non so dirti di più
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950var Moon = {phase: function (year, month, day) {var c = e = jd = b = 0;if (month < 3) {year--;month += 12;}++month;c = 365.25 * year;e = 30.6 * month;jd = c + e + day - 694039.09; // jd is total days elapsedjd /= 29.5305882; // divide by the moon cycleb = parseInt(jd); // int(jd) -> b, take integer part of jdjd -= b; // subtract integer part to leave fractional part of original jdb = Math.round(jd * 8); // scale fraction from 0-8 and roundif (b >= 8) b = 0; // 0 and 8 are the same so turn 8 into 0switch (b) {case 0:return 'new-moon';break;case 1:return 'waxing-crescent-moon';break;case 2:return 'quarter-moon';break;case 3:return 'waxing-gibbous-moon';break;case 4:return 'full-moon';break;case 5:return 'waning-gibbous-moon';break;case 6:return 'last-quarter-moon';break;case 7:return 'waning-crescent-moon';break;}}};// Moon.phase('2018', '01', '19');1234567891011121314151617181920212223242526272829I modified your script to not have a bloaty switch case, and actually return an object containing both the name and the number of the phase ;)// Original Snippet: https://gist.github.com/endel/dfe6bb2fbe679781948cvar Moon = {phases: ['new-moon', 'waxing-crescent-moon', 'quarter-moon', 'waxing-gibbous-moon', 'full-moon', 'waning-gibbous-moon', 'last-quarter-moon', 'waning-crescent-moon'],phase: function (year, month, day) {let c = e = jd = b = 0;if (month < 3) {year--;month += 12;}++month;c = 365.25 * year;e = 30.6 * month;jd = c + e + day - 694039.09; // jd is total days elapsedjd /= 29.5305882; // divide by the moon cycleb = parseInt(jd); // int(jd) -> b, take integer part of jdjd -= b; // subtract integer part to leave fractional part of original jdb = Math.round(jd * 8); // scale fraction from 0-8 and roundif (b >= 8) b = 0; // 0 and 8 are the same so turn 8 into 0return {phase: b, name: Moon.phases[b]};}};// Moon.phase('2018', '01', '19');03/19/2019 at 11:34 AM #9401703/19/2019 at 12:32 PM #94019Penso di essergli vicino … Le nuove lune sono cerchi e la luna piena sono quadrati
1234567891011121314151617181920212223242526272829303132333435//moon phasesiday=opendayimonth=openmonthiyear=openyearif imonth<3 theniyear=iyear-1imonth=imonth+12endifimonth=imonth+1c = 365.25 * iyeare = 30.6 * imonthjd = c + e + iday - 694039.09 // jd is total days elapsedjd = jd/29.5305882 // divide by the moon cycledecimal=(round(jd)-jd)if decimal>0 thendecimal=1-decimalendifb = jd-abs(decimal) // take integer part of jdjd = jd-b // subtract integer part to leave fractional part of original jdb = round(jd * 8) // scale fraction from 0-8 and rounddecay=0atr=AverageTrueRange[14](close)if b[decay]=0 and b[decay+1]<>0 then //new moondrawvline(barindex) coloured(200,0,0)drawtext("●",barindex,min(low-atr,lowest[20](low)),dialog,bold,30)endifif b[decay]=4 and b[decay+1]<>4 then //full moondrawvline(barindex) coloured(0,0,200)drawtext("",barindex,max(high+atr,highest[20](high)),dialog,bold,30)endifreturn2 users thanked author for this post.
03/19/2019 at 5:12 PM #9404903/19/2019 at 5:43 PM #94052Non ho il codice di tradingview, vero? Ho tradotto il codice JavaScript che mi hai dato. Ho fatto un paragone con questo sito per la fase lunare: https://www.timeanddate.com/moon/phases/e sembra piuttosto buono.
Assicurati di aver attivato i dati del weekend per il calcolo da calcolare correttamente.03/19/2019 at 5:49 PM #94053Ho invertito la luna piena e il simbolo della luna nuova su e giù, questo nuovo codice è migliore:
1234567891011121314151617181920212223242526272829303132333435//moon phasesiday=opendayimonth=openmonthiyear=openyearif imonth<3 theniyear=iyear-1imonth=imonth+12endifimonth=imonth+1c = 365.25 * iyeare = 30.6 * imonthjd = c + e + iday - 694039.09 // jd is total days elapsedjd = jd/29.5305882 // divide by the moon cycledecimal=(round(jd)-jd)if decimal>0 thendecimal=1-decimalendifb = jd-abs(decimal) // take integer part of jdjd = jd-b // subtract integer part to leave fractional part of original jdb = round(jd * 8) // scale fraction from 0-8 and rounddecay=0atr=AverageTrueRange[14](close)if b[decay]=0 and b[decay+1]<>0 then //new moondrawvline(barindex) coloured(0,0,200)drawtext("",barindex,max(high+atr,highest[20](high)),dialog,bold,30)endifif b[decay]=4 and b[decay+1]<>4 then //full moondrawvline(barindex) coloured(200,0,0)drawtext("",barindex,min(low-atr,lowest[20](low)),dialog,bold,30)endifreturn1 user thanked author for this post.
03/19/2019 at 6:05 PM #94055Bravo e grazie Nicolas!
Sembra quasi identico a quello di tradingview
Nel frattempo avevo trovato l’indicatore per ninja trader, ho chiesto la demo e ho installato l’indicatore
Ti allego lo script e il grafico
Avevo trovato anche questo sito che indica esattamente le fasi lunari
https://www.calendar-365.com/moon/moon-phases.html
Moon Phases123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257#region Using declarationsusing System;using System.ComponentModel;using System.Diagnostics;using System.Drawing;using System.Drawing.Drawing2D;using System.Xml.Serialization;using NinjaTrader.Cbi;using NinjaTrader.Data;using NinjaTrader.Gui.Chart;#endregion// This namespace holds all indicators and is required. Do not change it.namespace NinjaTrader.Indicator{/// <summary>////// Print the moon phase in a daily chart/// version beta 0.02, to be debugged, need more options for text offset/// November 30, 2009 by sam028 (http://forum.bigmiketrading.com)/// </summary>[Description("Print the moon phase in a daily chart")]public class MoonPhase : Indicator{#region Variablesprivate bool found;private Font textFont = new Font("Arial", 8, FontStyle.Regular);private Color textColor = Color.Blue;private float offset = 0;private bool debug=false;#endregion/// <summary>/// This method is used to configure the indicator and is called once before any bar data is loaded./// </summary>protected override void Initialize(){CalculateOnBarClose = true;Overlay = false;PriceTypeSupported = false;}/// <summary>/// Called on each bar update event (incoming tick)/// </summary>protected override void OnBarUpdate(){int m=moon_calc(Time[0].Year,Time[0].Month, Time[0].Day);if (m==0){if (found == false){if (debug)Print("New moon on "+Time[0].Month+" "+Time[0].Day);DrawText("New"+CurrentBar,true, "New moon",0, High[0]+20 * TickSize,0,textColor, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);found = true;}}else {if (m==4){if (found == false){if (debug)Print("Full moon on "+Time[0].Month+" "+Time[0].Day);DrawText("Full"+CurrentBar,true,"Full moon",0,Low[0] - 20 * TickSize,0, textColor, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);found = true;}}else {found=false;}}}protected int moon_calc(int year, int month, int day){int g, e;if (month == 1){--day;}else {if (month == 2) {day += 30;}else {day += 28 + (month-2)*3059/100;if ((year & 3)==0)++day;if ((year%100) == 0)--day;}}g = (year-1900)%19 + 1;e = (11*g + 18) % 30;if ((e == 25 && g > 11) || e == 24)e++;return ((((e + day)*6+11)%177)/22 & 7);}#region Properties[Description("Fonts.")][Category("Fonts")][XmlIgnore()]public Font TextFont{get { return textFont; }set { textFont = value; }}[Browsable(false)]public string TextFontSerialize{get { return NinjaTrader.Gui.Design.SerializableFont.ToString(textFont); }set { textFont = NinjaTrader.Gui.Design.SerializableFont.FromString(value); }}[XmlIgnore()][Description("TextColor")][Category("Colors")]public Color TextColor{get { return textColor; }set { textColor = value; }}[Browsable(false)]public string TextColorSerialize{get { return NinjaTrader.Gui.Design.SerializableColor.ToString(textColor); }set { textColor = NinjaTrader.Gui.Design.SerializableColor.FromString(value); }}[Description("Offset for text.")][Category("Display")]public float Offset{get { return offset; }set { offset = value; }}#endregion}}#region NinjaScript generated code. Neither change nor remove.// This namespace holds all indicators and is required. Do not change it.namespace NinjaTrader.Indicator{public partial class Indicator : IndicatorBase{private MoonPhase[] cacheMoonPhase = null;private static MoonPhase checkMoonPhase = new MoonPhase();/// <summary>/// Print the moon phase in a daily chart/// </summary>/// <returns></returns>public MoonPhase MoonPhase(){return MoonPhase(Input);}/// <summary>/// Print the moon phase in a daily chart/// </summary>/// <returns></returns>public MoonPhase MoonPhase(Data.IDataSeries input){if (cacheMoonPhase != null)for (int idx = 0; idx < cacheMoonPhase.Length; idx++)if (cacheMoonPhase[idx].EqualsInput(input))return cacheMoonPhase[idx];lock (checkMoonPhase){if (cacheMoonPhase != null)for (int idx = 0; idx < cacheMoonPhase.Length; idx++)if (cacheMoonPhase[idx].EqualsInput(input))return cacheMoonPhase[idx];MoonPhase indicator = new MoonPhase();indicator.BarsRequired = BarsRequired;indicator.CalculateOnBarClose = CalculateOnBarClose;#if NT7indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;indicator.MaximumBarsLookBack = MaximumBarsLookBack;#endifindicator.Input = input;Indicators.Add(indicator);indicator.SetUp();MoonPhase[] tmp = new MoonPhase[cacheMoonPhase == null ? 1 : cacheMoonPhase.Length + 1];if (cacheMoonPhase != null)cacheMoonPhase.CopyTo(tmp, 0);tmp[tmp.Length - 1] = indicator;cacheMoonPhase = tmp;return indicator;}}}}// This namespace holds all market analyzer column definitions and is required. Do not change it.namespace NinjaTrader.MarketAnalyzer{public partial class Column : ColumnBase{/// <summary>/// Print the moon phase in a daily chart/// </summary>/// <returns></returns>[Gui.Design.WizardCondition("Indicator")]public Indicator.MoonPhase MoonPhase(){return _indicator.MoonPhase(Input);}/// <summary>/// Print the moon phase in a daily chart/// </summary>/// <returns></returns>public Indicator.MoonPhase MoonPhase(Data.IDataSeries input){return _indicator.MoonPhase(input);}}}// This namespace holds all strategies and is required. Do not change it.namespace NinjaTrader.Strategy{public partial class Strategy : StrategyBase{/// <summary>/// Print the moon phase in a daily chart/// </summary>/// <returns></returns>[Gui.Design.WizardCondition("Indicator")]public Indicator.MoonPhase MoonPhase(){return _indicator.MoonPhase(Input);}/// <summary>/// Print the moon phase in a daily chart/// </summary>/// <returns></returns>public Indicator.MoonPhase MoonPhase(Data.IDataSeries input){if (InInitialize && input == null)throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");return _indicator.MoonPhase(input);}}}#endregion03/19/2019 at 6:24 PM #94058Indicazioni su come utilizzarlo nel trading
11/11/2020 at 7:24 PM #150177 -
AuthorPosts