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

How do I determine if a bar closes at the top 25% of the bars range?

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

    #16
    Hey Darth,

    I noticed that when I change the candle bar "up color" on this indicator, it always switches back to the default color after I restart Ninja Trader. Can you fix this perhaps? Again, I really appreciate this.

    Comment


      #17
      Hi,

      When you have changed the colours to the ones you want right click on the properties window and select save as defualt. You could also do it with code but this is the easiest way. Hope that helps.

      Comment


        #18
        @GKonheiser

        Thanks but unfortunately that did not work. Would you happen to have the code for the fix?

        Comment


          #19
          So now for example if the close is in the top 25% of the bar, how does one color the space from the 75% line to the close?

          Comment


            #20
            Help

            This is a great indicator, however the color bars always default to the down color as Red and the up color as blank. I always have to choose the up and down colors. Even If I save as default on the indicator, it still reverts back to this.

            If anyone can please look at the code real quick and provide a fix I would appreciate it. I tried messing with it for 2 hours and have had no luck, but then again I am no coder. I'm sure it's a quick fix for the experienced.

            Comment


              #21
              Post the code

              Post your code I will take a look

              Comment


                #22
                Thanks GKonheiser, here you go:

                #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>
                /// Color coding a reversal bar to show possible entry point.
                /// </summary>
                [Description("Color coding a reversal bar to show possible entry point.")]
                public class aaScalpBar : Indicator
                {
                #region Variables
                // Wizard generated variables
                private double barPercent = 0.75; // default setting for bar range calculation
                private Color upColor = Color.Green; // default up color candle
                private Color dnColor = Color.Red; // default down color candle
                // 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()
                {
                //
                }


                /// <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.


                if(Close[0] >= Low[0] + barPercent*(High[0]-Low[0]))
                {BarColor = UpColor;}

                if(Close[0] <= High[0] - barPercent*(High[0]-Low[0]))
                {BarColor = DnColor;}
                }

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

                [Description("Percent range to color bars...a close above X percent will color up, a close below X % of the bar range will paint low.")]
                [GridCategory("Parameters")]
                public double BarPercent
                {
                get { return barPercent; }
                set { barPercent = Math.Max(0, value); }
                }
                [Description("Color for up painted bars")]
                [GridCategory("Parameters")]
                public Color UpColor
                {
                get { return upColor; }
                set { upColor = value; }
                }
                [XmlIgnore()]
                [Description("Color for down painted bars")]
                [GridCategory("Parameters")]
                public Color DnColor
                {
                get { return dnColor; }
                set { dnColor = 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 aaScalpBar[] cacheaaScalpBar = null;

                private static aaScalpBar checkaaScalpBar = new aaScalpBar();

                /// <summary>
                /// Color coding a reversal bar to show possible entry point.
                /// </summary>
                /// <returns></returns>
                public aaScalpBar aaScalpBar(double barPercent, Color dnColor, Color upColor)
                {
                return aaScalpBar(Input, barPercent, dnColor, upColor);
                }

                /// <summary>
                /// Color coding a reversal bar to show possible entry point.
                /// </summary>
                /// <returns></returns>
                public aaScalpBar aaScalpBar(Data.IDataSeries input, double barPercent, Color dnColor, Color upColor)
                {
                if (cacheaaScalpBar != null)
                for (int idx = 0; idx < cacheaaScalpBar.Length; idx++)
                if (Math.Abs(cacheaaScalpBar[idx].BarPercent - barPercent) <= double.Epsilon && cacheaaScalpBar[idx].DnColor == dnColor && cacheaaScalpBar[idx].UpColor == upColor && cacheaaScalpBar[idx].EqualsInput(input))
                return cacheaaScalpBar[idx];

                lock (checkaaScalpBar)
                {
                checkaaScalpBar.BarPercent = barPercent;
                barPercent = checkaaScalpBar.BarPercent;
                checkaaScalpBar.DnColor = dnColor;
                dnColor = checkaaScalpBar.DnColor;
                checkaaScalpBar.UpColor = upColor;
                upColor = checkaaScalpBar.UpColor;

                if (cacheaaScalpBar != null)
                for (int idx = 0; idx < cacheaaScalpBar.Length; idx++)
                if (Math.Abs(cacheaaScalpBar[idx].BarPercent - barPercent) <= double.Epsilon && cacheaaScalpBar[idx].DnColor == dnColor && cacheaaScalpBar[idx].UpColor == upColor && cacheaaScalpBar[idx].EqualsInput(input))
                return cacheaaScalpBar[idx];

                aaScalpBar indicator = new aaScalpBar();
                indicator.BarsRequired = BarsRequired;
                indicator.CalculateOnBarClose = CalculateOnBarClose;
                #if NT7
                indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                indicator.MaximumBarsLookBack = MaximumBarsLookBack;
                #endif
                indicator.Input = input;
                indicator.BarPercent = barPercent;
                indicator.DnColor = dnColor;
                indicator.UpColor = upColor;
                Indicators.Add(indicator);
                indicator.SetUp();

                aaScalpBar[] tmp = new aaScalpBar[cacheaaScalpBar == null ? 1 : cacheaaScalpBar.Length + 1];
                if (cacheaaScalpBar != null)
                cacheaaScalpBar.CopyTo(tmp, 0);
                tmp[tmp.Length - 1] = indicator;
                cacheaaScalpBar = 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>
                /// Color coding a reversal bar to show possible entry point.
                /// </summary>
                /// <returns></returns>
                [Gui.Design.WizardCondition("Indicator")]
                public Indicator.aaScalpBar aaScalpBar(double barPercent, Color dnColor, Color upColor)
                {
                return _indicator.aaScalpBar(Input, barPercent, dnColor, upColor);
                }

                /// <summary>
                /// Color coding a reversal bar to show possible entry point.
                /// </summary>
                /// <returns></returns>
                public Indicator.aaScalpBar aaScalpBar(Data.IDataSeries input, double barPercent, Color dnColor, Color upColor)
                {
                return _indicator.aaScalpBar(input, barPercent, dnColor, upColor);
                }
                }
                }

                // This namespace holds all strategies and is required. Do not change it.
                namespace NinjaTrader.Strategy
                {
                public partial class Strategy : StrategyBase
                {
                /// <summary>
                /// Color coding a reversal bar to show possible entry point.
                /// </summary>
                /// <returns></returns>
                [Gui.Design.WizardCondition("Indicator")]
                public Indicator.aaScalpBar aaScalpBar(double barPercent, Color dnColor, Color upColor)
                {
                return _indicator.aaScalpBar(Input, barPercent, dnColor, upColor);
                }

                /// <summary>
                /// Color coding a reversal bar to show possible entry point.
                /// </summary>
                /// <returns></returns>
                public Indicator.aaScalpBar aaScalpBar(Data.IDataSeries input, double barPercent, Color dnColor, Color upColor)
                {
                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.aaScalpBar(input, barPercent, dnColor, upColor);
                }
                }
                }
                #endregion

                Comment


                  #23
                  Color change

                  In the region variables change :-

                  Code:
                  private Color upColor = Color.Green; // default up color candle
                  private Color dnColor = Color.Red; // default down color candle
                  So for example if you want the down color to be blue:-

                  Code:
                  private Color dnColor = Color.Blue; // default down color candle
                  When you change it, delete the . after Color and then add it back and intelisence will give you all the color options.

                  Let me know if you need more help. ; )

                  Comment


                    #24
                    Hi GKonheiser,

                    So the interesting thing is that the default down bar color works fine, but the up color candle keeps defaulting to empty even though I choose a color from the list. Any ideas?

                    Comment


                      #25
                      did you change the code

                      private Color upColor = Color.Green; // default up color candle

                      Comment


                        #26
                        Yep, this is how the code is set but the up color bar still defaults to empty.

                        #region Variables
                        // Wizard generated variables
                        private double barPercent = 0.75; // default setting for bar range calculation
                        private Color upColor = Color.White; // default up color candle
                        private Color dnColor = Color.SteelBlue; // default down color candle
                        // User defined variables (add any user defined variables below)
                        #endregion

                        Comment


                          #27
                          Originally posted by Volcom View Post
                          Yep, this is how the code is set but the up color bar still defaults to empty.

                          #region Variables
                          // Wizard generated variables
                          private double barPercent = 0.75; // default setting for bar range calculation
                          private Color upColor = Color.White; // default up color candle
                          private Color dnColor = Color.SteelBlue; // default down color candle
                          // User defined variables (add any user defined variables below)
                          #endregion
                          You need to serialize the colors. Search the forum for "Serialize colors". Alternatively, there is code already available in the "Tips" section of the forum.

                          ref: http://ninjatrader.com/support/forum...ad.php?p=25038

                          Comment


                            #28
                            That seems a bit advanced and is completely foreign to me unfortunately.

                            Comment


                              #29
                              It's actually easier than it may sound. Open your code. Scroll down to the section "Properties". Where you see your line of code for the up Color you add (you may have to substitute "public" with "private"):

                              // Serialize our Color object
                              [Browsable(false)]
                              public string upColorSerialize
                              {
                              get { return NinjaTrader.Gui.Design.SerializableColor.ToString( upColor); }
                              set { upColor = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value);}
                              }

                              It should then look something like this:

                              // colors
                              [XmlIgnore()]
                              [Description("Color for Up")]
                              [GridCategory("Colors")]
                              public Color UpColor
                              {
                              get { return upColor; }
                              set { upColor = value; }
                              }

                              // Serialize our Color object
                              [Browsable(false)]
                              public string upColorSerialize
                              {
                              get { return NinjaTrader.Gui.Design.SerializableColor.ToString( upColor); }
                              set { upColor = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value); }
                              }

                              Then you repeat the same for your dn Color.

                              sandman

                              Comment


                                #30
                                Sandman...THANK YOU!!

                                I simply just changed the variable up and down color code to private instead of public and that did the trick! No additional coding required. You're the man! Thanks to everyone else as well for helping out.

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Mindset, 05-06-2023, 09:03 PM
                                9 responses
                                258 views
                                0 likes
                                Last Post ender_wiggum  
                                Started by Mizzouman1, Today, 07:35 AM
                                4 responses
                                18 views
                                0 likes
                                Last Post Mizzouman1  
                                Started by philmg, Today, 01:17 PM
                                1 response
                                6 views
                                0 likes
                                Last Post NinjaTrader_ChristopherJ  
                                Started by cre8able, Today, 01:01 PM
                                1 response
                                8 views
                                0 likes
                                Last Post NinjaTrader_ChelseaB  
                                Started by manitshah915, Today, 12:59 PM
                                1 response
                                5 views
                                0 likes
                                Last Post NinjaTrader_Erick  
                                Working...
                                X