Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Volume Based Indicator Help

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

    Volume Based Indicator Help

    Hello, this is a two part question. First off I am trying to make a simple indicator that takes uses the difference between BuyPressure and SellPressure in the BuySellPressure indicator and displays the output as NetPressure. Attached is a screen shot of the code I have, the issue is the line displayed just flatlines at zero.

    Part two of this question is about strategy development with these volume indicators, the ones that require tick replay to be enabled for them to work with back tests. I want, with tick replay enabled, for my strategy to asses the logic only at the close of each bar before it is applied. That way I can work with these volume indicators and not have them churn me through a dozen trades within the same bar. I'm just interested in what their value is at the END of the bar not during it. For example, when back testing, if I am using two minute candles my time in market should be at least two minutes for every trade. Knowing how to work with that end of bar data so I can use it in things like moving averages would be very helpful too. As of now, when I try to apply moving average functions to indicators like BuySellPressure in the strategy builder I think it is taking that average on a tick by tick basis instead of bar by bar because tick is the indicators data stream. I just want to be able to take the moving averages of the result of those calculations at the end of each bar and work with them on a bar by bar basis. Knowing how to do so is crucial for the conversion of a strategy I built in TD using thinkscript to Ninjatrader. If that is possible, and some custom code is required to achieve it, could you please tie it in with the answer to part one in regards to the NetPressure indicator? That is the indicator I am using for my strategy.

    Thank you so much, any help is greatly appreciated
    -StoneMan78
    Attached Files

    #2
    Hello StoneMan78,

    Use prints to understand behavior.

    Print the time of the bar, and print all of the values from the indicators to see what these are, and why the custom calculation is producing a 0.


    When using Calculate OnEachTick, use IsFirstTickOfBar in an unlocked script to trigger logic only when a bar has closed.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello ChelseaB,

      I have implemented some of your suggestions but am still having no luck getting the script to work. Here is what I have so far:


      protected override void OnBarUpdate()
      {
      if (IsFirstTickOfBar)
      {
      NetPressure[0] = BuySellPressure().BuyPressure[1] - BuySellPressure().SellPressure[1];
      //Add your custom indicator logic here.
      }

      }


      It really is a simple indicator I am trying to make here, I just want the difference between BuyPressure and SellPressure from the BuySellPressure indicator and be able to plot it as NetPressure. Unfortunately, I am totally new to ninja script and C# and really don't know what I am doing. Any more insights on how I could get this to work would be greatly appreciated. Thank you.

      Comment


        #4
        Hello StoneMan78,

        May I have the output from the prints to have further understanding of why the custom calculation is not what you are expecting?

        Please save this to a text file and include this with your next post.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hello ChelseaB,

          Here is my code update and its print.

          protected override void OnBarUpdate()
          {
          if (CurrentBar > 1)
          {
          if (IsFirstTickOfBar)
          {
          NetPressure[0] = BuySellPressure().BuyPressure[1] - BuySellPressure().SellPressure[1];
          //Print for debugging
          Print(string.Format("{0} | NetP[0]: {1} = BuyP[1]: {2} - SellP[1]: {3}", Time[0], NetPressure[0], BuySellPressure().BuyPressure[1], BuySellPressure().SellPressure[1]));

          }
          }
          }

          It appears the read from the BuySellPressure indicator does not appear to be working properly. Any idea how to remedy this?
          Thank you so much for all of your help. I am learning a lot from this.
          Attached Files

          Comment


            #6
            Hello StoneMan78,

            The BuySellPressure indicator is a real-time indicator.

            To confirm, when adding the indicator to the chart with AddChartIndicator(), the plot values on the chart do not match the values printed in the output?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              That is correct. I initialized the script with the setup wizard as shown in the first picture I posted. I have the BuySellPressure indicator running above this one and it works just fine. My custom indicator fails both in real-time and with tick replay. You are correct in that I never specify the use of BuySellPressure with the AddChartIndicator() function earlier in the script. I have attempted to add it as specified by the support guide but am getting an error on compilation. "The name 'AddChartIndicator' does not exist in the current context" it says. I'll attach a screen shot.
              Attached Files

              Comment


                #8
                Hello StoneMan78,

                Thank you for your reply.

                Ah I overlooked this is an indicator in the indicator section of the forums, and not a strategy, which can call AddChartIndicator.

                In that case, on a new chart, add this indicator first, then add the BuySellPressure second.

                Below is a link to a video that demonstrates, and shows the values I am producing on my end.


                That said, a note about the BuySellPressure, it overwrites the previous bars plot value after the bar is closed (on lines 88 and 89), this means you would want to see what the final updated bar value is after that bar is closed.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hello ChelseaB,

                  Using your example I have been able to get a signal that appears to be working properly except for a single bug. The early bars in the chart, like the first 10% of them, do not appear to be registering. Then the indicator just starts randomly working. A screenshot of the updated code, my chart, and output print file are attached. Thank you so much for all of the help, it is greatly appreciated.
                  Attached Files

                  Comment


                    #10
                    Hello StoneMan78,

                    Set BarsRequiredToPlot to 1.
                    https://ninjatrader.com/support/help...iredtoplot.htm

                    And be sure that is real-time data and not historical data that loads before real-time data.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Hello ChelseaB,

                      I added in the BarsRequiredToPlot command and the same lag before the indicator begins working is still present. Could you instruct me on how to ensure real-time data loads in first? Currently the OnStateChange() object appears to check State.Defaults (largely generated by the setup wizard) then State.DataLoaded. You can see this in the code screen shot of my last reply. Thank you for all of the help.

                      Comment


                        #12
                        Hello StoneMan78,

                        You can prevent the logic from evaluating historical data, to skip printing, with:

                        if (State == State.Historical)
                        return;

                        This allow the first prints to be for real-time data.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Ok. Thank you for showing me. I added that code between the check for State.Defaults and State.DataLoaded. An updated screen shot of my code is attached. The exact same lag before the indicator begins working still persists. I really don't have a clue as to why this would be happening as the BuySellPressure indicator, which is the custom indicators input, works just fine during this period. Help in squashing this final bug would be greatly appreciated, and thank you for everything you have done for me so far.
                          Attached Files

                          Comment


                            #14
                            Hello StoneMan78,

                            This would go in OnBarUpdate() above the logic you want to prevent from being evaluated in historical data.

                            Below is a link to the help guide on State which has an example 'Using State to only process real-time data'.
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              Hello ChelseaB,

                              I have implemented the changes you suggested and the problem is that the return statement takes away the ability to evaluate historical data at all as implemented . I have included a screen shot of the code update. Any idea on how I could make the code prioritize the real time data while still allowing me to evaluate the historical data after that check is complete? Thank you so much for the help.
                              Attached Files

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              599 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              344 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              103 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              558 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              557 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X