Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Creating a New Bar Type

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

    Creating a New Bar Type

    I have an indicator that creates information within the "OnBarUpdate()" function that resides in the namespace "NinjaTrader.NinjaScript.Indicators". whose input comes from the Data Series of a security and is updated every tick.

    I would like to create a new bar type based on this information. However, bar types reside in the namespace "NinjaTrader.NinjaScript.BarsTypes" and are formed within the "OnDataPoint" override function. The "OnDataPoint" function is passed the standard hi lo open close data volume bid ask information of the data stream.

    How do I get my override "OnDataPoint" to access the information created in "OnBarUpdate" to create a new bar type ?

    #2
    Can I create a static class which can be accessed by the different namespaces ? Use that as a gobetween ?

    Can I create a namespace that has a static class which both "NinjaTrader.NinjaScript.Indicators" and "NinjaTrader.NinjaScript.BarsTypes" use ?

    Can I create a namespace "NinjaTrader,NinjaScript,MyStatic" of which the corresponding folder would be in the directory C:\Users\xxxx\Documents\NinjaTrader 8\bin\Custom\MyStatic. Then write the code of a static class residing in this namespace of which Indicators can access via OnBarUpdate and BarTypes can access via OnDataPoint ?
    Last edited by pvtrader; 03-26-2022, 10:49 AM.

    Comment


      #3
      Hello pvtrader,

      Unfortunately, bar types cannot call an indicator (or do anything that works with Series).

      Instead, all of the logic would need to be directly coded in the bar type script without calling any indicators.

      (This will be true of all addon scripts that are not Indicators and Strategies)
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Well, isn't that what I'm hinting at. Create a static class that resides in the AddOns folder. Have indicator write pertinent information to it. Then have BarsType read from it. Of course, there may be synchronization issues to be resolved. I've noticed (at least when loading historical data) that one indicator may get several chartbars ahead of another, before app transitions to realtime.

        Comment


          #5
          Hello pvtrader,

          I was not referring to a static class. I was referring to putting the logic directly in the bar type code (in OnDataPoint

          Using a static class would be outside of what is directly supported by the Scripting Support team, but this kind of custom C# coding may be possible.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            To create a new bar (or chart) style, I've always overridden OnRender() and drawn the chart directly. The declaration for doing this is:

            protected override void OnRender(ChartControl chartControl, ChartScale chartScale)

            Though it's a bit raw, this gives you ultimate flexibility in how your chart (bars or otherwise) looks. There are some indicators that come with NinjaTrader 8 that serve as good examples of how to do this.

            Good Luck.
            Day-Trading Earl
            NinjaTrader Ecosystem Vendor - Day-Trading Earl

            Comment


              #7
              Hi Earl, Thank you for the reply.


              Yes, that definitely is another way to go with "OnRender". I've seen this approach before. And it works nicely. The only drawback is I can't use the output of that type of indicator as input to another indicator. At least not as a bartype that has Hi Lo Open Close attributes.
              Attached Files

              Comment


                #8
                Hello pvtrader,

                This would be an indicator and not a bar type.

                An indicator that custom renders can also set plot values that can be read from hosting scripts.

                Below are scripts that custom render and set plot values.
                NinjaTrader 8 natively provides Heiken Ashi as a bar type for most common bar types (minute, tick, volume, second, day, week, month, year). This Heiken Ashi indicator is provided for the Range, Renko and any custom bar types that may be added. The indicator performs in the same manner as the NinjaTrader 7 version. 4-27-18 […]

                NYSE Advancing Issues/Declining Issues Uses historical tick data to calculate the ^ADV index minus the ^DECL index to give a simulation of the ^ADD index. Requires a data feed that supports indexes and provides data for the ^ADV (NYSE Advancing Issues) and ^DECL (NYSE Declining Issues). Update June 16th, 2020 – Corrected stroke attributes to […]

                This is a conversion of the Spread Indicator with Candlesticks. Please contact the original author for any questions or comments.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hi Chelsea,


                  Yes, which brings me back to my original problem. I would like to implement a new bar type. It will be painted using "OnRender". But it is not a simple task to critique the new bar type via 'other' indicator output. If I understand correctly, what Earl was hinting at, is to bypass a new bar type and just use "OnRender" within the new indicator to paint the bars. This will in effect allow for easy access to other indicator information to critique the newly drawn bars.

                  However, I lose the option of using a "new bar type" as input to other indicators.

                  Comment


                    #10
                    pvtrader, can you identify the indicator you want to feed this bar data into? There might be work-arounds that could accommodate an indicator instead of a bar type.
                    Day-Trading Earl
                    NinjaTrader Ecosystem Vendor - Day-Trading Earl

                    Comment


                      #11
                      Helllo pvtrader,

                      Where you have said:
                      "However, I lose the option of using a "new bar type" as input to other indicators."

                      This is incorrect. Series and Plots can be inputs to other indicators.
                      On a chart, you can select an indicator as input series for another indicator and select a plot.

                      A bar type is intended to create a bar from logic from incoming ticks to set the open, high, low, and close of a bar. The chart style is what would actually render the bars on the chart with OnRender().

                      However, why do you need a bar type specifically, instead of an indicator rendering bars over the existing bars on a chart?
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        Hi Earl and Chelsea,



                        Yes, with the sample indicator attached called "IndicadorCandleStick", it creates four output plots(H, L, O, C).
                        “AddPlot()” creates a “Series<double> object” that is synchronized to the primary data series of the provided NinjaScript.
                        Writing another custom indicator called "TestCustomeIndicator", can easily take the output of the "IndicadorCandleStick" as input:

                        PROOF OF CONCEPT
                        -----------------------------------
                        Sample indicator named "IndicadorCandleStick" outputs a plot named IndClose; Sample indicator named "TestCustomIndicator" reads that value:

                        Code Snippet from "TestCustomIndicator":
                        protected override void OnBarUpdate()
                        {
                        //Add your custom indicator logic here.
                        OutputPlot0[0] = IndicadorCandlestick(BarColorDown, BarColorUp, ShadowColor,ShadowWidth).IndClose[0];
                        .------------------------------------
                        (please see attached files)



                        So, we already established that, no need to go in circles.







                        The question is, does this break any existing models ? If I want to use the "IndicadorCandleStick" as input to an already existing standard set of indicators, a problem may arise.
                        What if the standard set of indicators expect a bar type “Input[]” with H,L,O,C attributes. "IndicadorCandleStick" does not provide this.



                        QUESTION: Instead of a plot output, can I write an indicator that has Series<T> as “output”, of which each element within the series has (H, L, O, C,timestamp,etc.) data? This somehow (and I don’t know how), can then be used as input to the existing basic set of indicators.



                        I think not. Unless you have an example you can upload to this thread that shows me how?


                        ---------------------------------------------------------------------------------------------------------------------
                        As to your comment “However, why do you need a bar type specifically, instead of an indicator rendering bars over the existing bars on a chart?”. Good question. The new bar type may not be compatible with price open high low close values. Depending on how the data is massaged, a new set of O,H,L,C may be created which is not scalable to the current price bar values. Additionally, My approach is to paint the new bar type on a new pane, not the existing price panel.
                        ---------------------------------------------------------------------------------------------------------------------
                        Attached Files
                        Last edited by pvtrader; 04-01-2022, 12:06 AM.

                        Comment


                          #13
                          Hello pvtrader,

                          We cannot make a plot of multiple data points, instead we would make multiple plots for each data points.

                          The NinjaScripts that reference High/Low would need to be modified to reference the High and Low plots of the indicator instead.

                          HeikenAshi 8 from post #8 can demonstrate how to draw over the visible bars and draw your own bars.

                          This may be easier than creating your own BarsType, but yes, you could create a BarsType that performs your own calculated OHLC. That logic would need to be implemented within the BarsType itself. If you compare HeikenAshi bars to the HeikenAshi indicator, you can get an idea for what would be involved there.

                          Comment


                            #14
                            Hi Jim.

                            Okay, just wanted to make sure I wasn't missing any ninjatrader magic.

                            If my objective is to create a new bar type that is dependent on "other" indicator logic, it may be easier for me to create it as a pseudo bar type, i.e. as an indicator which uses "OnRender" to paint the bars within a new pane on the chart. Any indicators I pass the pseudo bar type to will have to be customized.

                            The alternative is to create a genuine new bar type. But if my critique to create the bar type is dependent on "other" indicator logic, passing information from "OnBarUpdate" to "OnDataPoint" may be more complex than I am prepared to handle. The crux of the matter is, as you say, "That logic would need to be implemented within the BarsType itself."


                            P.S. You guys rock, do a great job, luv your product

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                            0 responses
                            648 views
                            0 likes
                            Last Post Geovanny Suaza  
                            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                            0 responses
                            369 views
                            1 like
                            Last Post Geovanny Suaza  
                            Started by Mindset, 02-09-2026, 11:44 AM
                            0 responses
                            108 views
                            0 likes
                            Last Post Mindset
                            by Mindset
                             
                            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                            0 responses
                            572 views
                            1 like
                            Last Post Geovanny Suaza  
                            Started by RFrosty, 01-28-2026, 06:49 PM
                            0 responses
                            573 views
                            1 like
                            Last Post RFrosty
                            by RFrosty
                             
                            Working...
                            X