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

How can I read custom bars for a additional data series

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

    How can I read custom bars for a additional data series

    I want to be able to compare EMAs for 2 different "time" series using custom bars.

    The custom bars were programmed by someone else.

    I can put both "2" and "3" data series on the same chart. Then I can put my EMA indicator on the chart twice, once for each of the data series. Then I see the EMAs for each data series on my chart (I have the EMA50 and the EMA200). see image below.

    I want to programmatically compare the EMAs between the 2 different series.

    But when I try to add a 2nd data series to an indicator, I don't know how to choose the "custom" bars that are on the chart.

    Is that possible?

    Below is image of what I'm trying to achieve, but without loading the 2nd data series.

    Or is it possible to possible to compare the EMAs across 2 different data series?



    Click image for larger version

Name:	image.png
Views:	131
Size:	109.4 KB
ID:	1262140



    #2
    Hello cre8able,

    Use AddDataSeries() with the barsType ID to add the custom series.

    From the help guide in the Tips section:
    "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);"


    Then supply the BarsArray[barsInProgressIndex] as the input series to the second instance of the indicator.

    myEMA2 = EMA(BarsArray[1], 7);

    Then you can compare these in OnBarUpdate().

    if (myEMA[0] > myEMA2[0])
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      thanks ChelseaB

      I think the rest is pretty simple, but:

      "2. 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);"

      I googled and searched the forum for some guidance but was unable to find any.

      it was unclear in my search what the 14, and 10 were for.

      I assume the 14 is the enum of the custom bar type. I found that the built in bars have enums up to 14. But how do I find the enum of the custom bars?

      I assume the 10 is the period for the custom bar. Is that correct?

      Sorry for my cluelessness. Doing the best I can with limited skills

      Comment


        #4
        Hello cre8able,

        Apologies, I should have provided that information in my last post.

        With custom bar types and with custom chart styles a unique ID must be chosen. If two scripts use the same ID, only one of them will show in the 'Type' list.

        The first 14 IDs for BarsPeriodType are reserved by NinjaTrader.
        The first 11 ChartStyle IDs are reserved by NinjaTrader.

        Example from the help guide:
        BarsPeriod = new BarsPeriod { BarsPeriodType = (BarsPeriodType)123456, BarsPeriodTypeName = "MyCustomBars", Value = 1 };
        https://ninjatrader.com/support/help...barsperiod.htm

        Below is a link to helpful script that lists the IDs for each bar type.
        https://ninjatraderecosystem.com/use...pe-identifier/
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Perfect, ChelseaB

          whatever they are paying you, they should double it

          thank you

          Comment


            #6
            oops. One more question

            I got the plot I wanted.

            When I plot the EMA using a secondary series attached to the chart, I get a smooth line. When I plot it using a secondary series in the indicator, I get a choppy line.

            Is these a way to smooth the choppy line when I'm using the secondary series in the indicator?




            Click image for larger version  Name:	image.png Views:	0 Size:	89.7 KB ID:	1262177
            Last edited by cre8able; 07-28-2023, 04:42 PM.

            Comment


              #7
              Hello cre8able,

              Is the secondary series a higher time frame (or have less bars than the primary series)?

              I would guess that it's choppy because there are bar values set to the previous bar value which can appear as a flat line. You would need fancy logic to calculate some value between.

              For example if on a 1 minute chart there is a plot being set every 5 minutes, and the value is 100 at 3:00 PM and is 110 at 3:05 PM, you would want some calculation to plot 102 at 3:01 PM, 104 at 3:02 PM, 106 at 3:03 PM etc.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                I have another challenge with using custom bars as an additional data series. I know the ID for them is 12345. From the BarTypeIdentifier indicator I got

                Click image for larger version

Name:	image.png
Views:	35
Size:	2.4 KB
ID:	1293250


                But there are 2 inputs. ​

                Click image for larger version

Name:	image.png
Views:	45
Size:	27.5 KB
ID:	1293249

                i tried this
                PHP Code:
                            else if (State == State.Configure)
                            {
                            
                AddDataSeries((BarsPeriodType)12345,4020);
                            }
                &
                #8203; 


                but that didn't work

                How do I feed 2 parameters to the custom bar type?

                Comment


                  #9
                  Hello cre8able,

                  You may need to contact the author of the custom bar type to find out which properties were renamed.

                  Below is a link to all of the default properties that may have been renamed.


                  Using the properties would appear like the help guide tip:
                  "3. You can specify optional BarsPeriod values (such as Value2) of a custom BarsType in the BarsPeriod object initializer. For example: AddDataSeries(new BarsPeriod() { BarsPeriodType = (BarsPeriodType)12345, Value = 10, Value2 = 20 });"


                  If the author renamed Value to Brick Size, and Values2 to Trend Threshold, the example above would be assigning Brick Size a value of 10 and Trend Threshold a value of 20.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    that worked
                    thank you

                    Comment


                      #11
                      I thought I had it, but it's not behaving exactly as I expected. I've added code for the secondary series, which is working

                      PHP Code:
                                  else if (State == State.Configure)
                                  {
                                  
                      AddDataSeries(new BarsPeriod() { BarsPeriodType = (BarsPeriodType)12345Value 40Value2 20 });
                                  }
                      &
                      #8203; 


                      I know that all the code is run on the chart data series as well as the secondary series.

                      But how do I differentiate the output of each. For example, I have some series that I use to hold values

                      PHP Code:
                                      greenBarCount            = new Series<int>(thisMaximumBarsLookBack.Infinite);
                                      
                      redBarCount                = new Series<int>(thisMaximumBarsLookBack.Infinite);
                                          
                                      
                      isBullEntryBar            = new Series<bool>(thisMaximumBarsLookBack.Infinite);
                                      
                      isBearEntryBar            = new Series<bool>(thisMaximumBarsLookBack.Infinite);

                      &
                      #8203; 
                      I thought the way to access each independently was to use isBullEntryBar[0][0] for the chart series and isBullEntryBar[1][0] for the secondary series.

                      But when I try to use isBullEntryBar[0][0] I get an error saying I can't apply indexing with [] to an expression of type bool.

                      What do I need to change?
                      Attached Files

                      Comment


                        #12
                        a series can only have 1 indexer [0]
                        if you want a second series for the 2nd data set (bars), create a new series and name it appropriately, and feed it the 2nd data set for the alt bars.

                        Comment


                          #13
                          got it

                          thanks

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Haiasi, 04-25-2024, 06:53 PM
                          2 responses
                          16 views
                          0 likes
                          Last Post Massinisa  
                          Started by Creamers, Today, 05:32 AM
                          0 responses
                          4 views
                          0 likes
                          Last Post Creamers  
                          Started by Segwin, 05-07-2018, 02:15 PM
                          12 responses
                          1,785 views
                          0 likes
                          Last Post Leafcutter  
                          Started by poplagelu, Today, 05:00 AM
                          0 responses
                          3 views
                          0 likes
                          Last Post poplagelu  
                          Started by fx.practic, 10-15-2013, 12:53 AM
                          5 responses
                          5,407 views
                          0 likes
                          Last Post Bidder
                          by Bidder
                           
                          Working...
                          X