Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 bortz, 11-06-2023, 08:04 AM
                  47 responses
                  1,610 views
                  0 likes
                  Last Post aligator  
                  Started by jaybedreamin, Today, 05:56 PM
                  0 responses
                  9 views
                  0 likes
                  Last Post jaybedreamin  
                  Started by DJ888, 04-16-2024, 06:09 PM
                  6 responses
                  19 views
                  0 likes
                  Last Post DJ888
                  by DJ888
                   
                  Started by Jon17, Today, 04:33 PM
                  0 responses
                  6 views
                  0 likes
                  Last Post Jon17
                  by Jon17
                   
                  Started by Javierw.ok, Today, 04:12 PM
                  0 responses
                  16 views
                  0 likes
                  Last Post Javierw.ok  
                  Working...
                  X