NinjaScript
#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>
/// Volatilité mesurée par l'ET et max/min sur N périodes
/// </summary>
[Description("Volatilité mesurée par l'ET et max/min sur N périodes")]
public class VolatET : Indicator
{
#region Variables
// Wizard generated variables
private int periodeMAX = 150; // Default setting for PeriodeMAX
private int periodeET = 20; // Default setting for PeriodeET
// User defined variables (add any user defined variables below)
#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()
{
Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "Max"));
Add(new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Line, "Min"));
Add(new Plot(Color.FromKnownColor(KnownColor.MediumBlue), PlotStyle.Line, "ET"));
CalculateOnBarClose = true;
Overlay = false;
PriceTypeSupported = false;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Use this method for calculating your indicator values. Assign a value to each
// plot below by replacing 'Close[0]' with your own formula.
Max.Set(MAX(StdDev(Close,PeriodeET),PeriodeMAX)[0]);
Min.Set(MIN(StdDev(Close,PeriodeET),PeriodeMAX)[0]);
ET.Set(StdDev(Close,PeriodeET)[0]);
}
#region Properties
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries Max
{
get { return Values[0]; }
}
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries Min
{
get { return Values[1]; }
}
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries ET
{
get { return Values[2]; }
}
[Description("")]
[Category("Parameters")]
public int PeriodeMAX
{
get { return periodeMAX; }
set { periodeMAX = Math.Max(1, value); }
}
[Description("")]
[Category("Parameters")]
public int PeriodeET
{
get { return periodeET; }
set { periodeET = Math.Max(1, 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 VolatET[] cacheVolatET = null;
private static VolatET checkVolatET = new VolatET();
/// <summary>
/// Volatilité mesurée par l'ET et max/min sur N périodes
/// </summary>
/// <returns></returns>
public VolatET VolatET(int periodeET, int periodeMAX)
{
return VolatET(Input, periodeET, periodeMAX);
}
/// <summary>
/// Volatilité mesurée par l'ET et max/min sur N périodes
/// </summary>
/// <returns></returns>
public VolatET VolatET(Data.IDataSeries input, int periodeET, int periodeMAX)
{
checkVolatET.PeriodeET = periodeET;
periodeET = checkVolatET.PeriodeET;
checkVolatET.PeriodeMAX = periodeMAX;
periodeMAX = checkVolatET.PeriodeMAX;
if (cacheVolatET != null)
for (int idx = 0; idx < cacheVolatET.Length; idx++)
if (cacheVolatET[idx].PeriodeET == periodeET && cacheVolatET[idx].PeriodeMAX == periodeMAX && cacheVolatET[idx].EqualsInput(input))
return cacheVolatET[idx];
VolatET indicator = new VolatET();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
indicator.Input = input;
indicator.PeriodeET = periodeET;
indicator.PeriodeMAX = periodeMAX;
indicator.SetUp();
VolatET[] tmp = new VolatET[cacheVolatET == null ? 1 : cacheVolatET.Length + 1];
if (cacheVolatET != null)
cacheVolatET.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheVolatET = tmp;
Indicators.Add(indicator);
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>
/// Volatilité mesurée par l'ET et max/min sur N périodes
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.VolatET VolatET(int periodeET, int periodeMAX)
{
return _indicator.VolatET(Input, periodeET, periodeMAX);
}
/// <summary>
/// Volatilité mesurée par l'ET et max/min sur N périodes
/// </summary>
/// <returns></returns>
public Indicator.VolatET VolatET(Data.IDataSeries input, int periodeET, int periodeMAX)
{
return _indicator.VolatET(input, periodeET, periodeMAX);
}
}
}
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
/// <summary>
/// Volatilité mesurée par l'ET et max/min sur N périodes
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.VolatET VolatET(int periodeET, int periodeMAX)
{
return _indicator.VolatET(Input, periodeET, periodeMAX);
}
/// <summary>
/// Volatilité mesurée par l'ET et max/min sur N périodes
/// </summary>
/// <returns></returns>
public Indicator.VolatET VolatET(Data.IDataSeries input, int periodeET, int periodeMAX)
{
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.VolatET(input, periodeET, periodeMAX);
}
}
}
#endregion