• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

bollinger bands modification

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    bollinger bands modification

    hello, not much to programming and I am developing a modification of bollinger bands.
    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

    #2
    r68cervera, looks good to me. However you would need to keep in mind the StdDev calculation still uses the Close here as input series then.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      thank you very much Bertrand, though he thought that

      Upper.Set (* stdDevValue NumStdDev smaHIGH +);
      Middle.Set (smaValue);
      Lower.Set (smaLOW - NumStdDev stdDevValue *);

      was correct, but I know that something is wrong because another platform the result is different.

      I'll look to see if I can find where it is exactly the error

      thanks

      Comment


        #4
        i´m sorry

        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 - NumStdDev * stdDevValue);

        Comment


          #5
          r68cervera, right my point here was that your standard deviation value uses no specific input series (in contrast to the SMAs), thus the calcs using the Close prices still (I'm not sure if desired this way or not). So this could be one potential difference, although probably minor in the final value. You would need to compare.
          BertrandNinjaTrader Customer Service

          Comment


            #6
            Hi Bertrand, Thanks for your reply and for your interest
            I look for the following
            for the upper band is calculated with maximum candle
            for the middle band is calculated with the closing price
            for calculating lower band is the minimum candle

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by mohdhm, Today, 04:09 PM
            0 responses
            1 view
            0 likes
            Last Post mohdhm
            by mohdhm
             
            Started by BGWTEX, Today, 03:30 PM
            1 response
            3 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by marekflys, Today, 03:07 PM
            0 responses
            5 views
            0 likes
            Last Post marekflys  
            Started by GregoryBaskin, Today, 02:51 PM
            1 response
            4 views
            0 likes
            Last Post NinjaTrader_Tyler  
            Started by swcooke, Today, 12:33 PM
            1 response
            10 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Working...
            X