Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Modifying how price is calculated (Bollinger bands)

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

    Modifying how price is calculated (Bollinger bands)

    Hi,

    I created modified bollinger bands using vwma instead of sma. Is there a way to change how price is calculated and also allow the changing of moving average used to calculate?

    For example having the price calculated by (O+H+L+C)/4 or (H+L+C)/3

    Then having the option to toggle between either using ema, sma, vwma, vwap (with a drop down)

    For my long term investing I have something like this with TOS but it would be great if I can figure out away to accomplish the same on NT without having another chart open.

    Thanks!

    #2
    Hello RoIsTrading,

    Thanks for your post and welcome to the NinjaTrader forums!

    For the (H+L+C)/3 you can use the price series of "Typical" https://ninjatrader.com/support/help...8/?typical.htm

    For the other data series, I wonder if you mean a weighted series which would be (H+L+C+C) / 4, is so then you could use weighted: https://ninjatrader.com/support/help.../?weighted.htm

    If you don't mean a weighted series, then you would need to create your own data series and perform the math as you wish: https://ninjatrader.com/support/help...8/?seriest.htm

    You can create dropdowns by creating an enum, please see an example here: https://ninjatrader.com/support/help...ned_parame.htm

    Comment


      #3
      Hello RolsTrading,
      I shared something similar earlier, you can find the post here. You can download the script & play around with it.
      It has options for diff moving averages you just need to add your price series & calculate based on it. Just in case you need any help, come back here.
      Hope it helps!

      Comment


        #4
        Originally posted by s.kinra View Post
        Hello RolsTrading,
        I shared something similar earlier, you can find the post here. You can download the script & play around with it.
        It has options for diff moving averages you just need to add your price series & calculate based on it. Just in case you need any help, come back here.
        Hope it helps!
        Thanks, I see what you did for the adjustment on moving average choice. That was exactly what I was looking for as far as changing the moving average. Excellent work!

        I'll see if I can figure out how to change how the price is calculated. I attached screenshots of what I'd like to do for clarity if you have any tips.

        Click image for larger version  Name:	bbands3.jpg Views:	0 Size:	56.7 KB ID:	1149458


        Click image for larger version  Name:	bbands2.jpg Views:	0 Size:	54.7 KB ID:	1149454Click image for larger version  Name:	Bbands1.jpg Views:	0 Size:	54.7 KB ID:	1149455
        Attached Files
        Last edited by RoIsTrading; 03-31-2021, 12:34 PM.

        Comment


          #5
          Originally posted by NinjaTrader_PaulH View Post
          Hello RoIsTrading,

          Thanks for your post and welcome to the NinjaTrader forums!

          For the (H+L+C)/3 you can use the price series of "Typical" https://ninjatrader.com/support/help...8/?typical.htm

          For the other data series, I wonder if you mean a weighted series which would be (H+L+C+C) / 4, is so then you could use weighted: https://ninjatrader.com/support/help.../?weighted.htm

          If you don't mean a weighted series, then you would need to create your own data series and perform the math as you wish: https://ninjatrader.com/support/help...8/?seriest.htm

          You can create dropdowns by creating an enum, please see an example here: https://ninjatrader.com/support/help...ned_parame.htm
          Thanks I see the typical as you showed but not sure how to input that into the code. When I review the bollinger band source code, i don't see a variable for price. I was able to change the moving average by substituting sma for vwma in all places in the code. I was looking to do something similar for price even if I dont get to the drop down portion yet.. thanks!

          Comment


            #6
            Hello RolsTrading,

            Please see below for valid input for System indicator methods. We can provide a PriceSeries like "Close" or "Typical" or you can provide a Series<double> for the first parameter which will be the input series.

            A Series<double> would be a series that you create that holds your own custom values. The Series<double> would be instantiated in State.DataLoaded, and values would be assigned in OnBarUpdate. The Series<double> could then be provided as the input series when calling your indicator methods.

            Valid input for system indicator methods - https://ninjatrader.com/support/help..._indicator.htm

            Let us know if there is anything else we can do to help.

            Comment


              #7
              Originally posted by NinjaTrader_Jim View Post
              Hello RolsTrading,

              Please see below for valid input for System indicator methods. We can provide a PriceSeries like "Close" or "Typical" or you can provide a Series<double> for the first parameter which will be the input series.

              A Series<double> would be a series that you create that holds your own custom values. The Series<double> would be instantiated in State.DataLoaded, and values would be assigned in OnBarUpdate. The Series<double> could then be provided as the input series when calling your indicator methods.

              Valid input for system indicator methods - https://ninjatrader.com/support/help..._indicator.htm

              Let us know if there is anything else we can do to help.
              I believe I follow. If I'm looking at the source code, I made changes under the onbarUpdate function below. Originally the double was vwma, so by removing and substituting for BarTypicalPrice, It should give the desired outcome. So far it complied without errors but I dont see a difference from the VWMA based bollinger version I created. I'll keep at it but please let me know if I'm in the right spot. Thanks!
              Click image for larger version

Name:	ninjaband.jpg
Views:	432
Size:	25.6 KB
ID:	1149500

              Comment


                #8
                Hello RolsTrading,
                You need a double series as Jim is suggesting & use it as you wish to. Just in case you're stuck let me know so I can do it when free, its fairly simple.

                Comment


                  #9
                  Hello RolsTrading,
                  I've updated it for your needs, now you can choose to use ohlc4 price series. Hope it helps!
                  Attached Files

                  Comment


                    #10
                    Hello RoIsTrading,

                    Thanks for your reply.

                    "I believe I follow. If I'm looking at the source code, I made changes under the onbarUpdate function below. Originally the double was vwma, so by removing and substituting for BarTypicalPrice, It should give the desired outcome. So far it complied without errors but I dont see a difference from the VWMA based bollinger version I created. I'll keep at it but please let me know if I'm in the right spot. Thanks!"
                    You would need to provide the price type as an input to the moving average you are using. If you look at the original Bollinger code, in State.DataLoaded you have:
                    sma = SMA(Period);
                    stdDev = StdDev(Period);

                    For your understanding, the SMA (and StdDev, and most other methods) will default to the "close" price type when a price type or input series is not specified. If you look at the methods in the help guide you would see the method syntax of:
                    SMA(ISeries<double> input, int period) and StdDev(ISeries<double> input, int period)
                    References:



                    Since Typicals is a price series you would need to have that set in the State.DataLoaded if you wanted to keep the OnBarUpdate() code as is, like this:

                    sma = SMA(Typical, Period);
                    stdDev = StdDev(Typical, Period);

                    Comment


                      #11
                      Originally posted by NinjaTrader_PaulH View Post
                      Hello RoIsTrading,

                      Thanks for your reply.



                      You would need to provide the price type as an input to the moving average you are using. If you look at the original Bollinger code, in State.DataLoaded you have:
                      sma = SMA(Period);
                      stdDev = StdDev(Period);

                      For your understanding, the SMA (and StdDev, and most other methods) will default to the "close" price type when a price type or input series is not specified. If you look at the methods in the help guide you would see the method syntax of:
                      SMA(ISeries<double> input, int period) and StdDev(ISeries<double> input, int period)
                      References:



                      Since Typicals is a price series you would need to have that set in the State.DataLoaded if you wanted to keep the OnBarUpdate() code as is, like this:

                      sma = SMA(Typical, Period);
                      stdDev = StdDev(Typical, Period);
                      Thanks I was able to get this earlier form traderjim and substituted the sma for vwma to get what I needed. working on the dropdown to cycle through both price and moving averages based on what s.kinra suggested. All your help is greatly appreciated!

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                      0 responses
                      636 views
                      0 likes
                      Last Post Geovanny Suaza  
                      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                      0 responses
                      366 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by Mindset, 02-09-2026, 11:44 AM
                      0 responses
                      107 views
                      0 likes
                      Last Post Mindset
                      by Mindset
                       
                      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                      0 responses
                      569 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by RFrosty, 01-28-2026, 06:49 PM
                      0 responses
                      571 views
                      1 like
                      Last Post RFrosty
                      by RFrosty
                       
                      Working...
                      X