• 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

Question about Market analyzer

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

    Question about Market analyzer

    NT team,
    I want to scan a instrument list and see if any instrument closed outside the bollinger band, meaning close price is>upper band or <lower band. How can I do that? Or do I need some programming work to achieve that? Thanks.

    #2
    Hello ljiangd,

    Thanks for your post.

    Yes, this would be possible however it would require custom programming of an indicator to detect the condition and then for the indicator to provide an output that the market analyzer can utilize.

    You then add the indicator to the market analyzer by using the indicator column and setting the cell conditions in the market analyzer for that column that reflect the output of the indicator.

    You may want to observe this thread for an example: http://ninjatrader.com/support/forum...762#post453762
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Sweet. I think I got it. Thanks a lot for your help.

      Comment


        #4
        Hi Paul,
        Based on your video, I made this indicator. But got errors when try to compile. Can you please take a look? Thanks.

        //
        // Copyright (C) 2016, NinjaTrader LLC <www.ninjatrader.com>.
        // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
        //
        #region Using declarations
        using System;
        using System.Collections.Generic;
        using System.ComponentModel;
        using System.ComponentModel.DataAnnotations;
        using System.Linq;
        using System.Text;
        using System.Threading.Tasks;
        using System.Windows;
        using System.Windows.Input;
        using System.Windows.Media;
        using System.Xml.Serialization;
        using NinjaTrader.Cbi;
        using NinjaTrader.Gui;
        using NinjaTrader.Gui.Chart;
        using NinjaTrader.Gui.SuperDom;
        using NinjaTrader.Data;
        using NinjaTrader.NinjaScript;
        using NinjaTrader.Core.FloatingPoint;
        using NinjaTrader.NinjaScript.DrawingTools;
        #endregion

        // This namespace holds indicators in this folder and is required. Do not change it.
        namespace NinjaTrader.NinjaScript.Indicators
        {
        /// <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>
        public class BBtest : Indicator
        {
        private SMA sma;
        private StdDev stdDev;

        protected override void OnStateChange()
        {
        if (State == State.SetDefaults)
        {
        Description = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDe scriptionBollinger;
        Name = BBtest;
        IsOverlay = true;
        IsSuspendedWhileInactive = true;
        NumStdDev = 2;
        Period = 14;

        AddPlot(Brushes.Goldenrod, "Upper band");
        AddPlot(Brushes.Goldenrod, "Middle band");
        AddPlot(Brushes.Goldenrod, "Lower band");
        AddPlot(Brushes.Transparent, "MAout");

        }
        else if (State == State.Configure)
        {
        sma = SMA(Period);
        stdDev = StdDev(Period);
        }
        }

        protected override void OnBarUpdate()
        {
        double sma0 = sma[0];
        double stdDev0 = stdDev[0];

        Upper[0] = sma0 + NumStdDev * stdDev0;
        Middle[0] = sma0;
        Lower[0] = sma0 - NumStdDev * stdDev0;

        if (Close[0]>Upper[0])
        {
        MAout[0]=1;
        }
        else if (Close[0]<lower[0])
        {
        MAout[0]=-1;
        }
        else
        MAout[0]=0;
        }
        }

        #region Properties
        [Browsable(false)]
        [XmlIgnore()]
        public Series<double> MAout
        {
        get { return Values[3]; }
        }
        public Series<double> Lower
        {
        get { return Values[2]; }
        }

        [Browsable(false)]
        [XmlIgnore()]
        public Series<double> Middle
        {
        get { return Values[1]; }
        }

        [Range(0, int.MaxValue), NinjaScriptProperty]
        [Display(ResourceType = typeof(Custom.Resource), Name = "NumStdDev", GroupName = "NinjaScriptParameters", Order = 0)]
        public double NumStdDev
        { get; set; }

        [Range(1, int.MaxValue), NinjaScriptProperty]
        [Display(ResourceType = typeof(Custom.Resource), Name = "Period", GroupName = "NinjaScriptParameters", Order = 1)]
        public int Period
        { get; set; }

        [Browsable(false)]
        [XmlIgnore()]
        public Series<double> Upper
        {
        get { return Values[0]; }
        }
        #endregion
        }
        }

        #region NinjaScript generated code. Neither change nor remove.

        namespace NinjaTrader.NinjaScript.Indicators
        {
        public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
        {
        private BBtest[] cacheBBtest;
        public BBtest BBtest(double numStdDev, int period)
        {
        return BBtest(Input, numStdDev, period);
        }

        public BBtest BBtest(ISeries<double> input, double numStdDev, int period)
        {
        if (cacheBBtest != null)
        for (int idx = 0; idx < cacheBBtest.Length; idx++)
        if (cacheBBtest[idx] != null && cacheBBtest[idx].NumStdDev == numStdDev && cacheBBtest[idx].Period == period && cacheBBtest[idx].EqualsInput(input))
        return cacheBBtest[idx];
        return CacheIndicator<BBtest>(new BBtest(){ NumStdDev = numStdDev, Period = period }, input, ref cacheBBtest);
        }
        }
        }

        namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
        {
        public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
        {
        public Indicators.BBtest BBtest(double numStdDev, int period)
        {
        return indicator.BBtest(Input, numStdDev, period);
        }

        public Indicators.BBtest BBtest(ISeries<double> input , double numStdDev, int period)
        {
        return indicator.BBtest(input, numStdDev, period);
        }
        }
        }

        namespace NinjaTrader.NinjaScript.Strategies
        {
        public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
        {
        public Indicators.BBtest BBtest(double numStdDev, int period)
        {
        return indicator.BBtest(Input, numStdDev, period);
        }

        public Indicators.BBtest BBtest(ISeries<double> input , double numStdDev, int period)
        {
        return indicator.BBtest(input, numStdDev, period);
        }
        }
        }

        #endregion

        Comment


          #5
          Hello ljiangd,

          Thanks for your post.

          It looks like on this line: else if (Close[0]<lower[0]) you would need to change lower to Lower. C# is case sensitive.
          Paul H.NinjaTrader Customer Service

          Comment


            #6
            Hi Paul,
            I made the change as you suggested and it still can't be compiled. Can you share the bbtest indicator you made so I can compare the code? Thanks.

            Comment


              #7
              Hello ljiangd,

              Thanks for your post.

              I've attached your code which compiles and runs here. I did observe that I needed to add [Browsable(false)] & [XmlIgnore()] to the Lower plot in the regions properties. This did not prevent compilation on my end but did expose the property in the UI which was not needed. I commented the lines I added.
              Attached Files
              Paul H.NinjaTrader Customer Service

              Comment


                #8
                It is working now. Thanks for the opportunity to learn from you.

                Comment


                  #9
                  helo

                  Thank you also to my perlajaran maybe I'll better understand the

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Yandychang, Today, 02:16 PM
                  0 responses
                  2 views
                  0 likes
                  Last Post Yandychang  
                  Started by priceisking, Today, 01:16 PM
                  1 response
                  4 views
                  0 likes
                  Last Post NinjaTrader_PaulH  
                  Started by kashyapjdave, 03-23-2017, 12:12 AM
                  11 responses
                  1,956 views
                  0 likes
                  Last Post forextrader2003  
                  Started by Gav_G, 07-26-2018, 04:29 PM
                  5 responses
                  422 views
                  0 likes
                  Last Post NinjaTrader_PaulH  
                  Started by spikeruk, Today, 01:49 PM
                  0 responses
                  5 views
                  0 likes
                  Last Post spikeruk  
                  Working...
                  X