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

Simple Indicator

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

    Simple Indicator

    Hello

    I am trying to create a simple indicator that plots the difference Bollinger Band Top and price(High). Could someone help with the codes.

    Thanks

    #2
    Hi Ronin,

    To get started you can run the NinjaScript indicator wizard (Tools->New NinjaScript->Indicator). Make sure you have at least one plot when you go through the wizard pages. After you finish, press the "Generate" button to get the NinjaScript editor to open with your new indicator.

    If you look in the OnBarUpdate() section you will notice this line of code:
    Code:
    Plot0.Set(Close[0]);
    By default, the indicator will be plotting the close because that is what we set our plot to equal. In your case, you want Bollinger Band Top minus price high. This can be done with this code:
    Code:
    Plot0.Set(Bollinger(2, 14).Upper[0] - High[0]);
    Whatever you place in the parenthesis after .Set is what your Plot0 will take values from. What the code is doing is telling the plot to be set to the upper bollinger band's value (bollinger band has standard deviation of 2 and period of 14) minus the high price.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Hi Josh

      Thanks. The code is working great.

      Regards

      Comment


        #4
        In the case below I am trying to build an indicator to determine whether BB is sloping or not.

        The code is

        Plot0.Set(((Bollinger(2, 20).Upper[0] - Bollinger(2, 20).Upper[5])/Bollinger(2, 20).Upper[0]*100));

        Formula is
        Bollinger Upper Band -Bollinger upper band 5 period ago/Bollinger upper band *100

        But this code is not returning any value.

        Could someone please correct my code.

        Thanks
        Last edited by Ronin; 09-11-2007, 12:51 AM.

        Comment


          #5
          The problem can likely be resolved by reviewing this "Tip".

          RayNinjaTrader Customer Service

          Comment


            #6
            This partly sorted the problem. The code now plots the values. However there seems to be huge gaps in plotting the indicator.

            What I am actually trying to do is simply apply ROC indicator to Boll Band, SMA etc. I want to calculate rate of change of indicator value instead of price.

            Could you please guide me how to do this.

            Thanks much.


            Comment


              #7
              Tutotorial Level II covers applying indicator on indicator calculations, exactly what you are looking for.

              Its located here - http://www.ninjatrader-support.com/H...Indicator.html
              RayNinjaTrader Customer Service

              Comment


                #8
                Hello

                My code for calculating ROC on Bollinger band is returning a couple of errors. Could any programmer take a look and help me correct this or still better provide the correct code for this.
                Code:
                double robt = (ROC(Bollinger(2,20).Upper[0]));
                Plot0.Set(robt);


                Am not a programmer and therefore find this simple code a herculean task.

                Thanks

                Comment


                  #9
                  - it always helps if you paste the compiler error you experience
                  - on your code below I would try:
                  Plot0.Set(ROC(Bollinger(2,20).Upper, <whatever period your ROC has>)[0]);

                  Comment


                    #10
                    Hi Dierk

                    Thanks. This did the magic.

                    Comment


                      #11
                      ROC(Bollinger) Approximation

                      There is an approximation that could be done on this that is much simpler than what you've been attempting.

                      Since the Bollinger calculates the upper band value as the SMA plus a multiple of the StdDev, and the SMA will on the average be the same as the price, why not just go with calculating the rate of change of the StdDev, as follows:

                      Code:
                              protected override void Initialize()
                              {
                                  Add(new Plot(Color.Orange, "BollingerRoc"));
                      
                                  Overlay               = false;
                                  PriceTypeSupported    = true;
                              }
                      
                              protected override void OnBarUpdate()
                              {
                                  Values[0].Set( ROC( StdDev(Period), ROCPeriod )[0] );
                              }
                      That should be a good approximation of the rate of change of the upper bollinger band.

                      Best regards,

                      KBJ
                      Attached Files

                      Comment


                        #12
                        Hi KBJ

                        Thanks for the code.

                        Best Regards
                        Ronin

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by rtwave, 04-12-2024, 09:30 AM
                        4 responses
                        31 views
                        0 likes
                        Last Post rtwave
                        by rtwave
                         
                        Started by yertle, Yesterday, 08:38 AM
                        7 responses
                        29 views
                        0 likes
                        Last Post yertle
                        by yertle
                         
                        Started by bmartz, 03-12-2024, 06:12 AM
                        2 responses
                        22 views
                        0 likes
                        Last Post bmartz
                        by bmartz
                         
                        Started by funk10101, Today, 12:02 AM
                        0 responses
                        7 views
                        0 likes
                        Last Post funk10101  
                        Started by gravdigaz6, Yesterday, 11:40 PM
                        1 response
                        9 views
                        0 likes
                        Last Post NinjaTrader_Manfred  
                        Working...
                        X