• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.


No announcement yet.

Partner 728x90


Help. Adding custom bar type to strategy.

  • Filter
  • Time
  • Show
Clear All
new posts

    Help. Adding custom bar type to strategy.


    I am in the process of creating a strategy. I have a custom bar type that I had created based on Renko.

    When i want to use this custom bar type, how can i add it to my strategy?

    This is what i have:

    else if (State == State.Configure)
    AddDataSeries(BarsPeriodType.myCustomBarType, 4, 5, 11);

    I am trying to do this but it doesn't show my custom bar type listed and when i add it anyways, it complains with the following error message:

    "NinjaTrader.Data.BarsPeriodType' does not contain a definition for 'myCustomBarType'

    Hello priceisking,

    Thank you for your reply.

    You've got the incorrect syntax for adding a custom bars type to your strategy.

    You can add a custom BarsType which is installed on your system by casting the registered enum value for that BarsPeriodType. For example: AddDataSeries((BarsPeriodType)14,10);

    You'd first need to get the registered enum value. You can get that by using this indicator which is publicly available on our NinjaTrader Ecosystem website:Here is a basic guideline of how to import NinjaScript add-ons in NinjaTrader 8:

    Note — To import NinjaScripts you will need the original .zip file.

    To Import:
    1. Download the NinjaScripts to your desktop, keep them in the compressed .zip file.
    2. From the Control Center window select the menu Tools > Import > NinjaScript Add-on...
    3. Select the downloaded .zip file
    4. NinjaTrader will then confirm if the import has been successful.

    Critical - Specifically for some NinjaScripts, it will prompt that you are running newer versions of @SMA, @EMA, etc. and ask if you want to replace, press 'No'

    Once installed, you may add the indicator to a chart by:
    • Right click your chart > Indicators... > Select the Indicator from the 'Available' list on the left > Add > OK
    Once you know what the custom bar type's enum is, you can then use that when adding your data series:


    Make sure you use the actual value that you got for your bars type from the above indicator - adding data series dynamically is not supported, so you can't use a variable there.

    Here's a link to our help guide on the AddDataSeries() method:

    Note that the information I've given above is touched on in the Tips on that page.

    Please let me know if I can be of further assistance.

    The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.

    Kate W.NinjaTrader Customer Service


      Ok This is great information. Thank you. I did load it and this is what i show:

      BetterRenko - 17
      Day - 5
      Heiken Ashi - 9
      Kagi - 10
      Line Break - 13
      Minute - 4
      Month - 7
      myCustomBarType - 2018
      Point and Figure - 12
      Range - 2
      Renko - 11
      Second - 3
      Tick - 0
      Volume - 1
      Volumetric - 14
      Week - 6
      Year - 8

      I added the series as follows:


      Is this the correct way?

      Also, if I were to package this and provide it to our customer, would I have to code and grab the number from their installation and pass it on to the strategy?

      I'm assuming the custom bar type will have a different number in another computer right?


        Hello priceisking,

        Thank you for your reply.

        That looks correct for a Renko based bar type.

        The BarsPeriodType number is declared within the code of the Bar Type script. You should see a line like this in the script for the Bar Type:

        BarsPeriod = new BarsPeriod { BarsPeriodType = (BarsPeriodType) 2018, BarsPeriodTypeName = "UniRenko(2018)", Value = 1 };

        This will be the same on all computers unless the script is modified.

        Please let us know if we may be of further assistance to you.

        Kate W.NinjaTrader Customer Service


          Awesome! Thank you for the quick reply. Appreciate it. Got it to work!


            I am referring to post #4. How would I add UniRenkoBars to a strategy? The bar type comes with three parameters. AddDataSeries() only allows for specifying a single parameter - the brick size. There are no fields for the reversal size and the offset.

            In order to add UniRenko bars to a strategy I would need to create a specific method AddUniRenko() - such as AddRenko() - to be able to call the bars.

            Nota: UniRenko bars do not always produce correct highs and lows, volume is false and the time stamp is delayed, so in any case they cannot be correctly synchronized. But let us assume that I am going to modify them to work correctly. How would I add them to a strategy?


              Already found the solution to my question. The following line will add UniRenko (2,6,2) bars programmatically:

              AddDataSeries(new BarsPeriod(){BarsPeriodType = (BarsPeriodType) 501, Value = 2, Value2 = 6, BaseBarsPeriodValue = 2});

              Again I advise against the use of these bars, as they come with a few bugs (single tick highs and lows not detected, false volume, not backtestable).



                I did end up creating the custom bar types, now i have a small cosmetic challenge. How do I change the color of the bars? Which property settings can i add to change the up color to Dodger Blue and the down bar color to crimson red?

                I want to do this:
                Make color of up bar to Dodger Blue
                Make color of down bar to Crimson red
                Make the outline of the bars match that of the background.

                I can't seem to find the correct settings. I can do it manually when i load the custom bar chart type but i want it to load with specific colors when added to chart and not the default colors.


                  Hello priceisking,

                  Thank you for your post.

                  You can save these settings as the preset for this bar type. To do so, once you've manually set the colors you want, you should see a small notation that says "preset bartypename" in the bottom right hand corner of the window. Click this and you'll see "save" and "restore appear. Click "save" to save your presets. Next time you add this bar type to your chart you should see your presets load immediately.

                  Please let us know if we may be of further assistance to you.
                  Kate W.NinjaTrader Customer Service



                    Is there a way i can do this in code? I would ideally like this to be embedded in code so when i share this it shows up same on all users.


                      Hello priceisking,

                      Thank you for your reply.

                      To program the up and down bar colors your code will look something like the following snippet.

                      // Sets the color of the current bar to blue if trending upward, on bar close.
                      if (IsRising(Close[0])){
                      BarBrush = Brushes.DodgerBlue;


                      // Sets the color of the current bar to orange if trending downward, on bar close.
                      if (IsFalling(Close[0])){
                      BarBrush = Brushes.Crimson;

                      The following help guide documentation on working with brushes will go into further detail on how to choose specific colors.

                      Working With Brushes

                      Please let us know if we may be of further assistance to you.
                      Kate W.NinjaTrader Customer Service


                      Latest Posts


                      Topics Statistics Last Post
                      Started by madams212121, Today, 12:10 PM
                      3 responses
                      Last Post bltdavid  
                      Started by jvanelli, Today, 12:19 PM
                      1 response
                      Last Post NinjaTrader_BrendanC  
                      Started by raaxus, Today, 11:17 AM
                      2 responses
                      Last Post raaxus
                      by raaxus
                      Started by login_dejavu, Today, 02:22 AM
                      1 response
                      Last Post NinjaTrader_Jesse  
                      Started by Leeroy_Jenkins, Yesterday, 09:17 AM
                      1 response
                      Last Post NinjaTrader_Melissa