above the band want it to be twice the standard deviation but on top of the candle
the band center the moving average
and the band below minus two times the standard deviation but the minimum candle
it´s ok????
#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>
**** /// Bollinger Bands are plotted at standard deviation levels above and
/// Below a moving average. Since standard deviation is a measure of volatility,
/// The bands are self-adjusting: widening During volatile markets and contracting
/// During calmer periods.
**** /// </ Summary>
**** [Description ("Enter the description of your new custom indicator here")]
**** public class bollingerfelipe: Indicator
**** {
******** #region Variables
************ private double numStdDev = 2;
private int period = 14;
***
******** #endregion
******** /// <Summary>
******** /// This method is used to configure the indicator and is called eleven bar before any data is loaded.
******** /// </ Summary>
******** protected override void Initialize ()
******** {
************ Add (new Plot (Color.Orange, "Upper band"));
Add (new Plot (Color.Orange, "Middle band"));
Add (new Plot (Color.Orange, "Lower band"));
************ 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.
************ double smaValue = SMA (Period) [0];
double smaHIGH = SMA (High, Period) [0];
double smaLOW = SMA (Low, Period) [0];
double stdDevValue = StdDev (Period) [0];
Upper.Set (smaHIGH + NumStdDev * stdDevValue );
Middle.Set (smaValue);
Lower.Set (smaLOW - stdDevValue * NumStdDev );
}
******** #region Properties
******** [Browsable (false)] // Prevents line esta the data series from Being displayed in the indicator properties dialog, do not remove
******** [XmlIgnore ()] // esta line Ensures That the indicator can be saved / recovered as part of a chart template, do not remove
******** Lower public DataSeries
******** {
************ get {return Values [2]; }
******** }
/// <Summary>
/// Get the middle value.
/// </ Summary>
[Browsable (false)]
[XmlIgnore ()]
public DataSeries Middle
{
get {return Values [1]; }
}
/// <Summary>
/// </ Summary>
[Description ("Number of standard deviations")]
[GridCategory ("Parameters")]
[Gui.Design.DisplayNameAttribute ("# of std. Dev.")]
public double NumStdDev
{
numStdDev get {return; }
numStdDev = Math.Max set {(0, value); }
}
/// <Summary>
/// </ Summary>
[Description ("Numbers of bars used for calculations")]
[GridCategory ("Parameters")]
public int Period
{
get {return period; }
Math.Max set {period = (1, value); }
}
/// <Summary>
/// Get the upper value.
/// </ Summary>
[Browsable (false)]
[XmlIgnore ()]
Upper public DataSeries
{
get {return Values [0]; }
}
#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 bollingerfelipe[] cachebollingerfelipe = null;
private static bollingerfelipe checkbollingerfelipe = new bollingerfelipe();
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public bollingerfelipe bollingerfelipe(double numStdDev, int period)
{
return bollingerfelipe(Input, numStdDev, period);
}
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public bollingerfelipe bollingerfelipe(Data.IDataSeries input, double numStdDev, int period)
{
if (cachebollingerfelipe != null)
for (int idx = 0; idx < cachebollingerfelipe.Length; idx++)
if (Math.Abs(cachebollingerfelipe[idx].NumStdDev - numStdDev) <= double.Epsilon && cachebollingerfelipe[idx].Period == period && cachebollingerfelipe[idx].EqualsInput(input))
return cachebollingerfelipe[idx];
lock (checkbollingerfelipe)
{
checkbollingerfelipe.NumStdDev = numStdDev;
numStdDev = checkbollingerfelipe.NumStdDev;
checkbollingerfelipe.Period = period;
period = checkbollingerfelipe.Period;
if (cachebollingerfelipe != null)
for (int idx = 0; idx < cachebollingerfelipe.Length; idx++)
if (Math.Abs(cachebollingerfelipe[idx].NumStdDev - numStdDev) <= double.Epsilon && cachebollingerfelipe[idx].Period == period && cachebollingerfelipe[idx].EqualsInput(input))
return cachebollingerfelipe[idx];
bollingerfelipe indicator = new bollingerfelipe();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
indicator.Input = input;
indicator.NumStdDev = numStdDev;
indicator.Period = period;
Indicators.Add(indicator);
indicator.SetUp();
bollingerfelipe[] tmp = new bollingerfelipe[cachebollingerfelipe == null ? 1 : cachebollingerfelipe.Length + 1];
if (cachebollingerfelipe != null)
cachebollingerfelipe.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cachebollingerfelipe = 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.bollingerfelipe bollingerfelipe(double numStdDev, int period)
{
return _indicator.bollingerfelipe(Input, numStdDev, period);
}
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public Indicator.bollingerfelipe bollingerfelipe(Data.IDataSeries input, double numStdDev, int period)
{
return _indicator.bollingerfelipe(input, numStdDev, 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.bollingerfelipe bollingerfelipe(double numStdDev, int period)
{
return _indicator.bollingerfelipe(Input, numStdDev, period);
}
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public Indicator.bollingerfelipe bollingerfelipe(Data.IDataSeries input, double numStdDev, 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.bollingerfelipe(input, numStdDev, period);
}
}
}
#endregion
Comment