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

Passing Bars Objects as Input to an Indicator

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

    Passing Bars Objects as Input to an Indicator

    Referring to the comment here at,


    In NinjaTrader 7, let's presume I make a call in OnBarUpdate like this,

    Code:
    int BarsAgo = Swing(BarsArray[1], 5).SwingHighBar(0, 1, CurrentBars[1]);
    this should return the BarsAgo index of the most recent Swing High on the Bars object represented by BarsArray[1].

    This is a case of passing a Bars object as indicator input (rather than another indicator, per the link above).

    Note that @Swing.cs does not reference the "Input" series, but uses the normal "High" and "Low" data series inside
    OnBarUpdate.

    Question #1 is fundamental -- how does the Swing indicator access the High & Low series of the input Bars object?

    [Presumably, a Bars object passed as input to an indicator causes the references to Open/High/Low/Close to be
    remapped to those of the input Bars object, rather than the primary bar series. Is this correct?]

    Question #2 is multi-part -- what other things get mapped to the input Bars object?

    [For ex, do these also get mapped to reference the input Bars object?
    Volume series?
    Weighted series?
    Typical series?
    Median series?
    CurrentBar property?]

    Where is this "mapping to the input Bars object" documented in the NT7 help guide?

    [The section "Using Bars Objects as Input to Indicator Methods" located here at,

    does not mention this under-the-hood "mapping" to the input Bars object.]

    Thanks

    #2
    Hello bltdavid

    Yes, for NinjaTrader 7, the High, Low, Open, and Close specifically are mapped from the Input series when the input is an indicator.
    No other series are mapped this way.

    This is not documented and was deprecated in NinjaTrader 8. So I would no recommend relying on this.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Yes, for NinjaTrader 7, the High, Low, Open, and Close specifically are mapped from the Input series when the input is an indicator.
      No other series are mapped this way.

      This is not documented and was deprecated in NinjaTrader 8. So I would no recommend relying on this.
      https://ninjatrader.com/support/foru...05#post1038005
      Thanks, but doesn't answer my question.

      I'm asking about when the input is a Bars object.

      Comment


        #4
        Hello bltdavid,

        When a Bars object from the series of another script is passed, this is the same as if you were calling the indicator without using an input series (where it defaults to the Bars object of the current BarsInProgress).

        You get the default behavior and that bars object is what is used for all price series in the hosted indicator.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_ChelseaB View Post
          Hello bltdavid,

          When a Bars object from the series of another script is passed, this is the same as if you were calling the indicator without using an input series (where it defaults to the Bars object of the current BarsInProgress).

          You get the default behavior and that bars object is what is used for all price series in the hosted indicator.
          Thanks, but could you quantify further what you mean by "another script"?

          [Sorry, I thought it was implied, but my example also should have shown you a secondary
          bar series added during Initialize, for ex, like this,

          Code:
            Add(PeriodType.Minute, 5);
          Since this is the only secondary bar series being added, this Bars object has index of 1.
          Does that detail help?]

          Perhaps I am confused, so please explain ...
          What is this "another script" you're referring to?
          And what does it have to do with an input Bars object created from my own script?

          Comment


            #6
            Originally posted by NinjaTrader_ChelseaB View Post
            Hello bltdavid

            Yes, for NinjaTrader 7, the High, Low, Open, and Close specifically are mapped from the Input series when the input is an indicator.
            No other series are mapped this way.

            This is not documented and was deprecated in NinjaTrader 8. So I would no recommend relying on this.
            https://ninjatrader.com/support/foru...05#post1038005
            Since this is about NinjaTrader 7, and the entire NinjaScript Framework of NT7 assumes and relies
            upon this feature, I think I will very much rely upon this feature as well. This feature is absolutely not
            going anywhere for NT7, and is absolutely 100% reliable for NT7. Do you agree?

            [Yes, I know, NT8 breaks this assumption, but I'm only asking about NT7.]

            Comment


              #7
              Hello bltdavid,

              I'm talking about a host script calling a hosted script with an added series.

              In Initialize():

              Add(PeriodType.Minute, 5); is added to the host script.

              Then we can call another script in OnBarUpdate():

              if (BarsInProgress == 1)
              {
              Print(SMA(14)[0]);
              }

              which would be the same as if we were supplying BarsArray[1] to the other indicator call as the input series in OnStartUp().

              private SMA mySMA;

              protected override void OnStartUp()
              {
              mySMA = SMA(BarsArray[1], 14);
              }

              In OnBarUpdate():
              if (CurrentBars[1] > 0)
              {
              Print(mySMA[0]);
              }

              Yes, this is the normal use of BarsArray.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Originally posted by NinjaTrader_ChelseaB View Post
                Hello bltdavid,

                When a Bars object from the series of another script is passed, this is the same as if you were calling the indicator without using an input series (where it defaults to the Bars object of the current BarsInProgress).

                You get the default behavior and that bars object is what is used for all price series in the hosted indicator.
                CurrentBar is not a price series, so is it also adjusted to reflect the input Bars object?

                Hmm, perhaps ...
                Are you saying the "BarsInProgress context" is mapped to the input Bars object?

                That expression is important, I've seen it used by NT support and docs. It appears
                to be the name given to the "map everything to a Bars object" concept. For example,
                setting up the "BarsInProgress context" is an essential step in the internal preparations
                made just before calling OnBarUpdate, right?

                Comment


                  #9
                  Originally posted by NinjaTrader_ChelseaB View Post
                  Hello bltdavid,

                  I'm talking about a host script calling a hosted script with an added series.

                  In Initialize():

                  Add(PeriodType.Minute, 5); is added to the host script.

                  Then we can call another script in OnBarUpdate():

                  if (BarsInProgress == 1)
                  {
                  Print(SMA(14)[0]);
                  }

                  which would be the same as if we were supplying BarsArray[1] to the other indicator call as the input series in OnStartUp().

                  private SMA mySMA;

                  protected override void OnStartUp()
                  {
                  mySMA = SMA(BarsArray[1], 14);
                  }

                  In OnBarUpdate():
                  if (CurrentBars[1] > 0)
                  {
                  Print(mySMA[0]);
                  }

                  Yes, this is the normal use of BarsArray.
                  https://ninjatrader.com/support/help.../barsarray.htm
                  Ah, you're using them short fancy words to mean "code".

                  To me, the first thing I think of when you say "script" is a file with extension ".cs"
                  that fully encapsulates an Indicator or Strategy plugin.

                  You're confusing my 30 years of software engineering experience with a somewhat
                  overly-broad usage of this non-specific common term "script".

                  My experience says,
                  "script" != "lines of code"
                  "script" == "a file of code"

                  But, I think I understand you now. Thanks.

                  Comment


                    #10
                    Hello bltdavid,

                    Yes, when there are multiple series, the BarsInProgress lets you know which Bars series is being used for indicators and price series.

                    Below is a link to the help guide. Please see the section 'Accessing the Price Data in a Multi-Bars NinjaScript'.
                    Chelsea B.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by kujista, Today, 05:44 AM
                    0 responses
                    5 views
                    0 likes
                    Last Post kujista
                    by kujista
                     
                    Started by ZenCortexCLICK, Today, 04:58 AM
                    0 responses
                    5 views
                    0 likes
                    Last Post ZenCortexCLICK  
                    Started by sidlercom80, 10-28-2023, 08:49 AM
                    172 responses
                    2,281 views
                    0 likes
                    Last Post sidlercom80  
                    Started by Irukandji, Yesterday, 02:53 AM
                    2 responses
                    18 views
                    0 likes
                    Last Post Irukandji  
                    Started by adeelshahzad, Today, 03:54 AM
                    0 responses
                    8 views
                    0 likes
                    Last Post adeelshahzad  
                    Working...
                    X