Bravo 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
#region Using declarations
using 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 Variables
private 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 NT7
indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
indicator.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);
}
}
}
#endregion