Stock Portfolio Organizer

The ultimate porfolio management solution.

Shares, Margin, CFD's, Futures and Forex
EOD and Realtime
Dividends and Trust Distributions
And Much More ....
For Portfolio Manager Click Here

WiseTrader Toolbox

#1 Selling Amibroker Plugin featuring:

Advanced Adaptive Indicators
Advanced Pattern Exploration
Neural Networks
And Much More ....
Find Out More Here

Bollinger BandWidth Percent for NinjaTrader
meralim
almost 8 years ago
NinjaTrader

Rating:
5 / 5 (Votes 1)
Tags:
bands, ninjatrader

Bollinger Percent (%), like Bollinger Bandwidth, is based on the Bollinger Bands indicator, which was developed by John Bollinger. The Bollinger Bands indicator was developed to measure a stock’s volatility. Furthermore, both Bollinger Bandwidth and Bollinger Percent are used in technical analysis for the same purpose of volatility evaluation.

Similar Indicators / Formulas

Bill Williams Market Facilitation Index
Submitted by kaiji over 8 years ago

Indicator / Formula

Copy & Paste Friendly
#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 BollingerBandWidthPercent : Indicator
    {
        #region Variables
        // Wizard generated variables
            private int period = 14; // Default setting for Period
            private double stdDev = 2; // Default setting for StdDev
        // 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.Lime), PlotStyle.Line, "BBWidthPercent"));
            CalculateOnBarClose	= true;
            Overlay				= false;
            PriceTypeSupported	= true;
        }

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
			double upperValue= Bollinger(stdDev,period).Upper[0];
			double lowerValue= Bollinger(stdDev,period).Lower[0];
			double middleValue= Bollinger(stdDev,period).Middle[0];
			double bbwp= ((upperValue/lowerValue)-1)*100;
			BBWidthPercent.Set(bbwp);
        }

        #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 BBWidthPercent
        {
            get { return Values[0]; }
        }

        [Description("")]
        [Category("Parameters")]
        public int Period
        {
            get { return period; }
            set { period = Math.Max(1, value); }
        }

        [Description("")]
        [Category("Parameters")]
        public double StdDev
        {
            get { return stdDev; }
            set { stdDev = 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 BollingerBandWidthPercent[] cacheBollingerBandWidthPercent = null;

        private static BollingerBandWidthPercent checkBollingerBandWidthPercent = new BollingerBandWidthPercent();

        /// <summary>
        /// Enter the description of your new custom indicator here
        /// </summary>
        /// <returns></returns>
        public BollingerBandWidthPercent BollingerBandWidthPercent(int period, double stdDev)
        {
            return BollingerBandWidthPercent(Input, period, stdDev);
        }

        /// <summary>
        /// Enter the description of your new custom indicator here
        /// </summary>
        /// <returns></returns>
        public BollingerBandWidthPercent BollingerBandWidthPercent(Data.IDataSeries input, int period, double stdDev)
        {
            checkBollingerBandWidthPercent.Period = period;
            period = checkBollingerBandWidthPercent.Period;
            checkBollingerBandWidthPercent.StdDev = stdDev;
            stdDev = checkBollingerBandWidthPercent.StdDev;

            if (cacheBollingerBandWidthPercent != null)
                for (int idx = 0; idx < cacheBollingerBandWidthPercent.Length; idx++)
                    if (cacheBollingerBandWidthPercent[idx].Period == period && Math.Abs(cacheBollingerBandWidthPercent[idx].StdDev - stdDev) <= double.Epsilon && cacheBollingerBandWidthPercent[idx].EqualsInput(input))
                        return cacheBollingerBandWidthPercent[idx];

            BollingerBandWidthPercent indicator = new BollingerBandWidthPercent();
            indicator.BarsRequired = BarsRequired;
            indicator.CalculateOnBarClose = CalculateOnBarClose;
            indicator.Input = input;
            indicator.Period = period;
            indicator.StdDev = stdDev;
            indicator.SetUp();

            BollingerBandWidthPercent[] tmp = new BollingerBandWidthPercent[cacheBollingerBandWidthPercent == null ? 1 : cacheBollingerBandWidthPercent.Length + 1];
            if (cacheBollingerBandWidthPercent != null)
                cacheBollingerBandWidthPercent.CopyTo(tmp, 0);
            tmp[tmp.Length - 1] = indicator;
            cacheBollingerBandWidthPercent = 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>
        /// Enter the description of your new custom indicator here
        /// </summary>
        /// <returns></returns>
        [Gui.Design.WizardCondition("Indicator")]
        public Indicator.BollingerBandWidthPercent BollingerBandWidthPercent(int period, double stdDev)
        {
            return _indicator.BollingerBandWidthPercent(Input, period, stdDev);
        }

        /// <summary>
        /// Enter the description of your new custom indicator here
        /// </summary>
        /// <returns></returns>
        public Indicator.BollingerBandWidthPercent BollingerBandWidthPercent(Data.IDataSeries input, int period, double stdDev)
        {
            return _indicator.BollingerBandWidthPercent(input, period, stdDev);
        }

    }
}

// 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.BollingerBandWidthPercent BollingerBandWidthPercent(int period, double stdDev)
        {
            return _indicator.BollingerBandWidthPercent(Input, period, stdDev);
        }

        /// <summary>
        /// Enter the description of your new custom indicator here
        /// </summary>
        /// <returns></returns>
        public Indicator.BollingerBandWidthPercent BollingerBandWidthPercent(Data.IDataSeries input, int period, double stdDev)
        {
            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.BollingerBandWidthPercent(input, period, stdDev);
        }

    }
}
#endregion

4 comments

1. anandnst

NO FORMULA… Admin kindly check

2. administrator

Formula is for ninjatrader

3. kv_maligi

Hi,

Have look at this http://www.swingtradingfordummies.com/freestuff.htm

Can one develop this for amibroker?

THis code is for ninjatrader. Unfortumately, there are no data vendors in india for testing this.

Thanks
viswanath

4. santa

hello admin

how to paste this formula in ninjatrader 7
pls help me…

Leave Comment

Please login here to leave a comment.

Back