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

Add DeltaBars dataseries

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

    Add DeltaBars dataseries

    Is it possible to add a secondary data series using DeltaBars bar type?

    #2
    Hello Bradyw,

    Welcome to the NinjaTrader forums!

    To add a data series to a script using a custom bar type, the BarsPeriod ID will need to be used in the AddDataSeries() call.

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

    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)14, Value = 10, Value2 = 20 });"
    https://ninjatrader.com/support/help...dataseries.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


      #3
      Hi,

      I have DeltaBars defined as "DeltaBarsType".
      I can load it in a normal chart.

      In an Indicator, I want to select them, but as they are not predefined, I get an error (not compiling but when selecting the "DeltaBarsType" in the chart:
      Error on calling 'OnStateChange' method: Requested value 'DeltaBarsType' was not found.
      The rest of the predefined BarTypes give no error.
      This is how I use it:

      public enum MultiTFPeriodTypesIndic
      {
      Tick, Volume, Second, Minute, Day, Week, Range, DeltaBarsType
      }

      What should I write there, in order to get my defined BarTypes correctly selected?

      As an alternative, I could do an If ssentence in the State == State.Configure, but I don't know how to "compare" the selected MultiTFPeriodTypesIndic.

      I have in Properties:

      [NinjaScriptProperty] [Display(Name = "Multi TF Data Series Type 1", Order = 100, GroupName = "Data Series")] public MultiTFPeriodTypesIndic MultiTFType1 { get; set; }

      How can I do in State == State.Configur to check it properly?

      if(MultiTFType1 == "DeltaBarsType") =>> error

      How could I make to be able to select a personal BarType?

      Thanks!!

      Comment


        #4
        Hello artson,

        You will need to use the barsType Id and cast as a BarsPeriodType as suggested in post # 2.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          So, is it not possible to select the DeltaBarsType?

          With my:

          public enum MultiTFPeriodTypesIndic
          {
          Tick, Volume, Second, Minute, Day, Week, Range, DeltaBarsType
          }​

          [NinjaScriptProperty] [Display(Name = "Multi TF Data Series Type 1", Order = 100, GroupName = "Data Series")] public MultiTFPeriodTypesIndic MultiTFType1 { get; set; }


          else if (State == State.Configure)
          {
          if(MultiTFPeriod1 > 0)
          AddDataSeries(GetBarType(MultiTFType1), MultiTFPeriod1);
          }

          I can select the BarsType as Volume, Minute or Range i.e. give the Period I want, and I get the DataSeries added with these selected parameters instead of havint them harcoded.
          It has worked till now without problems.

          But I cannot select the DeltaBarsType.
          How can I add the DeltaBarsType to the AddDataSeries?

          Comment


            #6
            Maybe also another question,

            How can I know with an "if" sentence, that I have selected the "DeltaBarsType"?

            public enum MultiTFPeriodTypesIndic
            {
            Tick, Volume, Second, Minute, Day, Week, Range, DeltaBarsType
            }​

            [NinjaScriptProperty] [Display(Name = "Multi TF Data Series Type 1", Order = 100, GroupName = "Data Series")] public MultiTFPeriodTypesIndic MultiTFType1 { get; set; }​


            if(MultiTFType1 == "DeltaBarsType") =>> error

            How should I code the "if" sentence?

            Comment


              #7
              Hello artson,

              Not by, name but yes by the barsId.

              if (BarsArray[0].BarsPeriodType == (BarsPeriodType)14) // your barsType id would replace the 14.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Thanks, but this is not what I mean,

                I mean: I select "DeltaBarsType" in th properties in the chart,
                then I will load Data Series as you mention in Post 2:
                AddDataSeries(new BarsPeriod() { BarsPeriodType = (BarsPeriodType)14, Value = 10, Value2 = 20 });​

                If I select another predefined BarsType It works with
                AddDataSeries(GetBarType(MultiTFType1), MultiTFPeriod1);


                The problem I have is, that I cannot get correctly the if sentence to know when the "DeltaBarsType" has been selected
                I don't know how to write this if:

                if( ?????? == DeltaBarsType ????) AddDataSeries(new BarsPeriod() { BarsPeriodType = (BarsPeriodType)14, Value = 10, Value2 = 20 });​​

                Comment


                  #9
                  Hello artson,

                  What I was suggesting in post # 4 and # 7 is how to know when the custom bar type is selected on the chart. Is this not what you are trying to do?
                  The if I suggested says if the bar type is custom bar type 14. Your custom bar type will have a different ID.

                  Note, it is not supported to dynamically call AddDataSeries from an if statement logic block.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Thanks Chelsea,

                    "Note, it is not supported to dynamically call AddDataSeries from an if statement logic block."
                    But it works with the instructions I wrote...

                    In any case, I change my question: how would you write an if sentence, to know if the selected option is DeltaBarsType in:



                    public enum MultiTFPeriodTypesIndic
                    {
                    Tick, Volume, Second, Minute, Day, Week, Range, DeltaBarsType
                    }​

                    [NinjaScriptProperty] [Display(Name = "Multi TF Data Series Type 1", Order = 100, GroupName = "Data Series")] public MultiTFPeriodTypesIndic MultiTFType1 { get; set; }​

                    Comment


                      #11
                      Hello artson,

                      Your enum isn't associated with a bar type.

                      But if you want to know the value of your enum variable it would be

                      if (MultiTFPeriodTypesIndic == MultiTFPeriodTypesIndic.DeltaBarsType)

                      However, you shouldn't have an enum declared with the same name as a variable or any other type, as this would be ambiguous.

                      If you want to know if the custom bar type is selected on a chart see post # 4 and post # 7.
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        "However, you shouldn't have an enum declared with the same name as a variable or any other type, as this would be ambiguous."
                        bufffffff, I do really have more than one

                        I really have:

                        public enum MultiTFPeriodTypesIndic
                        {
                        Tick, Volume, Second, Minute, Day, Week, Range, DeltaBarsType
                        }​

                        [NinjaScriptProperty] [Display(Name = "Multi TF Data Series Type 1", Order = 100, GroupName = "Data Series")] public MultiTFPeriodTypesIndic MultiTFType1 { get; set; }​​
                        [NinjaScriptProperty] [Display(Name = "Multi TF Data Series Type 2", Order = 120, GroupName = "Data Series")] public MultiTFPeriodTypesIndic MultiTFType2 { get; set; }​​
                        [NinjaScriptProperty] [Display(Name = "Multi TF Data Series Type 3", Order = 110, GroupName = "Data Series")] public MultiTFPeriodTypesIndic MultiTFType3 { get; set; }​​

                        and it works till now....

                        In this case, how should I write your:
                        if (MultiTFPeriodTypesIndic == MultiTFPeriodTypesIndic.DeltaBarsType)

                        Thanks a lot Chelsea!!

                        Comment


                          #13
                          Hello artson,

                          Below is how you would check the value of an enum variable.

                          if (MultiTFType1 == MultiTFPeriodTypesIndic.DeltaBarsType)
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            Perfect!!

                            This is what I needed!

                            You have helped me a lot!!

                            Comment


                              #15
                              Incredible!

                              The solution works in the indicator I was working with.

                              As it worked, I copied the same text into another indicator and then, it compiles right, but when selecting DeltaBarsType in the chart it crashes with the error:

                              Indicator 'aInaRotPiv': Error on calling 'OnStateChange' method: Requested value 'DeltaBarsType' was not found.

                              I've checked everything and it is the same as in the indicator working....
                              What could it be?
                              A kind of bug from NT?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by burtoninlondon, Today, 12:38 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post burtoninlondon  
                              Started by AaronKoRn, Yesterday, 09:49 PM
                              0 responses
                              14 views
                              0 likes
                              Last Post AaronKoRn  
                              Started by carnitron, Yesterday, 08:42 PM
                              0 responses
                              11 views
                              0 likes
                              Last Post carnitron  
                              Started by strategist007, Yesterday, 07:51 PM
                              0 responses
                              13 views
                              0 likes
                              Last Post strategist007  
                              Started by StockTrader88, 03-06-2021, 08:58 AM
                              44 responses
                              3,982 views
                              3 likes
                              Last Post jhudas88  
                              Working...
                              X