#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>
/// Enter the description of your new custom indicator here
/// </summary>
[Description("Enter the description of your new custom indicator here")]
public class ATRText : Indicator
{
#region Variables
// Wizard generated variables
private int period = 14; // Default setting for Period
// 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()
{
Overlay = true;
}
/// <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.
if(CurrentBar>Period)
{
string text = string.Format("ATR({0}): {1}",Period,Math.Round(ATR(Period)[0],5));
DrawTextFixed("Nebraska", text , TextPosition.BottomRight);
}
}
#region Properties
[Description("Length of ATR")]
[GridCategory("Parameters")]
public int Period
{
get { return period; }
set { period = 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 ATRText[] cacheATRText = null;
private static ATRText checkATRText = new ATRText();
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public ATRText ATRText(int period)
{
return ATRText(Input, period);
}
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public ATRText ATRText(Data.IDataSeries input, int period)
{
if (cacheATRText != null)
for (int idx = 0; idx < cacheATRText.Length; idx++)
if (cacheATRText[idx].Period == period && cacheATRText[idx].EqualsInput(input))
return cacheATRText[idx];
lock (checkATRText)
{
checkATRText.Period = period;
period = checkATRText.Period;
if (cacheATRText != null)
for (int idx = 0; idx < cacheATRText.Length; idx++)
if (cacheATRText[idx].Period == period && cacheATRText[idx].EqualsInput(input))
return cacheATRText[idx];
ATRText indicator = new ATRText();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
indicator.Input = input;
indicator.Period = period;
Indicators.Add(indicator);
indicator.SetUp();
ATRText[] tmp = new ATRText[cacheATRText == null ? 1 : cacheATRText.Length + 1];
if (cacheATRText != null)
cacheATRText.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheATRText = 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>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.ATRText ATRText(int period)
{
return _indicator.ATRText(Input, period);
}
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public Indicator.ATRText ATRText(Data.IDataSeries input, int period)
{
return _indicator.ATRText(input, period);
}
}
}
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.ATRText ATRText(int period)
{
return _indicator.ATRText(Input, period);
}
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public Indicator.ATRText ATRText(Data.IDataSeries input, int period)
{
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.ATRText(input, period);
}
}
}
#endregion
Comment