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

Indicator code placement

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

    Indicator code placement

    I am trying to add bar brushes to an indicator.
    Where, at what number line would I place the brush code? Click image for larger version

Name:	SR code 2.jpg
Views:	371
Size:	61.0 KB
ID:	1149675Click image for larger version

Name:	SR code.jpg
Views:	350
Size:	134.1 KB
ID:	1149676

    Picture on left, bar brush is what I want to add to indicator on right. Any info would be helpful. Thx

    #2
    Bottom picture is the indicator and top is the bar brush i want to add to it.

    Comment


      #3
      I probabally needed to put this question in indicator development not strategies.

      Comment


        #4
        Hello JTizz,

        Thank you for your post.

        I have moved this thread to Indicator Developement.

        Where you use BarBrush in your code would depend on what you are trying to accomplish. If you would like to change the BarBrush color when a certain condition happens, you would need to create that condition followed by calling BarBrush.

        See the attached example script which demonstrates using BarBrush to change the color of a bar when a certain condition happens.

        Also, see this help guide link for more information.
        BarBrush - https://ninjatrader.com/support/help...8/barbrush.htm

        Let us know if we may assist further.
        Attached Files
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          I looked at the links you have provided...Thx Here is what I want to add to the above indicator. Where would it be added to the indicator? What line number?
          Attached Files

          Comment


            #6
            Hello JTizz,

            Our role is not really to advise on "copy this code and paste it here" so much as it is to support our product and provide direction for accomplishing your tasks.

            Changing the BarBrush property will require that you understand how the BarBrush property can be used and a will also involve basic understanding of C# syntax. You will need to know what exactly you will want to check to create your condition to then set BarBrush.

            Basic Programming Concepts - https://ninjatrader.com/support/help...g_concepts.htm

            Please observe that in the strategy code, the indicator plots are referenced as DynamicSR.Resistance[0] and DynamicSR.Support[0]. Within the indicator, you would not reference those plots as DynamicSR.Resistance[0] and DynamicSR.Support[0], because you are already in the indicator. You could just reference Support[0] and Resistance[0] after they have been set.

            We look forward to assisting.
            JimNinjaTrader Customer Service

            Comment


              #7
              This code is in strategy builder strategy. How can I convert code from Strat builder srtategy to an custom indicator?

              Comment


                #8
                I am trying to have the Dynamic SR indicator that you created, paint the bars above the upper band the upper band color, bars below the lower band the lower band color and bars inbetween the bands a neutral color.

                Comment


                  #9
                  Click image for larger version

Name:	trader Jim.jpg
Views:	319
Size:	61.8 KB
ID:	1149839

                  Comment


                    #10
                    Hello JTizz,

                    Thank you for your note.

                    If you are wanting to create a modified version of the DynamicSR indicator, you could download and import the DynamicSR indicator followed by modifying the indicator in a New > NinjaScript Editor window. To do so, you would open a New > NinjaScript Editor window, double-click the Indicators folder, then select the DynamicSR indicator. Right-click in the indicator's code and click 'Save as' to create a copy of the DynamicSR indicator.

                    After creating a copy of the DynamicSR indicator, you would create conditions in your script that check if the current Close[0] is greater than or less than the Support[0]/Resistance[0] plot and call BarBrush to change the color of a bar when that condition becomes true.

                    Let us know if we may assist further.
                    Brandon H.NinjaTrader Customer Service

                    Comment


                      #11
                      Yes i have that info see attached pic, I want to know where to add it in the code. When I add it i get errors that i cannot resolve.

                      Comment


                        #12
                        Hello JTizz,

                        Thank you for your note.

                        As stated by my colleague Jim, our role is not really to advise on "copy this code and paste it here" so much as it is to support our product and provide direction for accomplishing your tasks.

                        Changing the BarBrush property will require that you understand how the BarBrush property could be used and will also involve a basic understanding of C# syntax. You will need to know what exactly you will want to check to create your condition to then set BarBrush.

                        Basic Programming Concepts - https://ninjatrader.com/support/help...g_concepts.htm

                        That being said, you would create your conditions in the OnBarUpdate() method of the script. Something you could do is check if the current Close[0] is greater than the Resistance[0] plot and call BarBrush to change the color of the bar to blue. The code would look something like this.

                        Code:
                        protected override void OnBarUpdate()
                        {
                            if (Close[0] > Resistance[0])
                                BarBrush = Brushes.Blue;
                        }
                        This would also need to be done for the Support[0] plot to change the bar color to magenta when the current Close[0] is less than the Support[0] plot.

                        Let us know if we may assist further.

                        Brandon H.NinjaTrader Customer Service

                        Comment


                          #13
                          I added the code as you described and everything compiled but as an indicator it does not plot on my chart. Any suggestions would be helpful. thhx

                          Comment


                            #14
                            Hello JTizz,

                            I would suggest starting with a simple indicator that changes BarBrush to get acquainted using this property.

                            For example, you can start with the following in a new indicator.

                            Code:
                            protected override void OnBarUpdate()
                            {
                                if (Close[0] > Open[0])
                                    BarBrush = Brushes.Orange;
                                else if (Close[0] < Open[0])
                                    BarBrush = Brushes.Purple;
                            }
                            After you are familiar using that code implement it in the custom indicator you want to modify and make sure it still sets the bar color.

                            Then, instead of checking Open vs. Close, use the Support and Resistance Series and compare that with the close price of the bar.

                            Debugging prints may be used to print out the values used in the conditions so you may see why the condition is/is not becoming true and allowing BarBrush to bet set. The prints may be viewed in a NinjaScript Output Window.

                            Debugging Tips - https://ninjatrader.com/support/help...script_cod.htm
                            JimNinjaTrader Customer Service

                            Comment


                              #15
                              I have the bar brush down it just wont show up on chart. Click image for larger version

Name:	barbrush.jpg
Views:	298
Size:	36.9 KB
ID:	1152489

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by algospoke, Yesterday, 06:40 PM
                              2 responses
                              19 views
                              0 likes
                              Last Post algospoke  
                              Started by ghoul, Today, 06:02 PM
                              3 responses
                              14 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by jeronymite, 04-12-2024, 04:26 PM
                              3 responses
                              45 views
                              0 likes
                              Last Post jeronymite  
                              Started by Barry Milan, Yesterday, 10:35 PM
                              7 responses
                              20 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by AttiM, 02-14-2024, 05:20 PM
                              10 responses
                              181 views
                              0 likes
                              Last Post jeronymite  
                              Working...
                              X