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

Indicator in Indicator - OnBarUpdate

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

    Indicator in Indicator - OnBarUpdate

    NT Forum,

    In the below scenario, please advise whether the code "IndicatorB.Update()" is required (I was of the understanding it should not bet, however I may be missing something):
    - you have two indicators, IndicatorA and IndicatorB,
    - IndicatorA hosts an instance of IndicatorB, and
    - IndicatorB OnBarUpdate must trigger with each BarUpdate.

    Within IndicatorA....
    Code:
    private IndicatorB _indicatorB;
    
    protected override void OnStateChange()
    {
      if (State == State.Configure)
      {
        var isCalledFrom = Name;
        var period = 8;
        _indicatorB = IndicatorB(isCalledFrom, period);
     }
    }
    
    protected override void OnBarUpdate()
    {
      // _indicatorB OnBarUpdate only appears to be triggered with the 
      //  inclusion of the below line.
      _indicatorB.Update();
    }
    As always, thanks
    Shannon

    #2
    Hello Shansen,

    Thank you for your note.

    From what is shown here, I would not expect you to need to call Update.

    This is only needed when you have custom property that isn't update with the bar and you need this to be updated before you return the value.

    In your script you are not returning any values, and if you were, you would only need to update if you have a custom property that needs to perform some logic before returning a value.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Chelsea,

      Thanks for your response.

      To clarify, a value is returned from IndicatorB (via method), but only every "x" bars (e.g. 100 bars). For IndicatorB to calculate correctly it must calculate every bar.

      Am I correct in the below possible solutions
      - use _indicatorB.Update(),
      - simply call the above mentioned value (via method) every bar as opposed to every "x" bars,
      - convert the method to a property and call the property every bar, or
      - generally call an exposed variable of _indicatorB in _indicatorA.

      Words of wisdom are welcome.
      Again, thanks

      Comment


        #4
        Hello Shannon,

        If you are calling a custom method, likely yes you would need to call update first.

        Below is a link to an example in the help guide.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Chelsea,

          From the help guide, where Update() is contained within the public property (below) (or method), the OnBarUpdate() method is called so that indicator values are updated to the current bar.

          Code:
          public double TripleValue
          {
            get
            {
              //call OnBarUpdate before returning tripleValue
             Update();
             return tripleValue;
            }
          }
          Please clarify, where the public property (or method) is called not every bar but only every "x" bars, will the Update() trigger all prior "unprocessed" OnBarUpdates before returning the value, or alternatively only trigger the latest OnBarUpdate (thus missing x-1 OnBarUpdates)?

          I ask because where only the latest OnBarUpdate is triggered, I will have to ensure Update() is called every bar.

          Again, thanks
          Shannon

          Comment


            #6
            Hello Shansen,

            Thanks for your additional question.

            Let's look at a section of the help guide article together:
            Forces the OnBarUpdate() method to be called so that indicator values are updated to the current bar. If the values are already up to date, the Update() method will not be run.
            The intention for the method is to make sure the indicators values are up to date for it's own data series when you are referencing a custom method of that script from another script on another data series. It does not synchronize the indicator with a separate data series' bars. As such, it would not have to be called more than once to make sure the values are up to date.

            If you have any additional questions, please don't hesitate to ask.
            JimNinjaTrader Customer Service

            Comment


              #7
              Jim,

              Thank you for your response.
              The intention for the method is to make sure the indicators values are up to date for it's own data series when you are referencing a custom method of that script from another script on another data series.
              As proof of concept, in the attached NinjaScript, Indicator A hosts IndicatorB. IndicatorA "evaluates" IndicatorB each new cycle (i.e. 100 bars). IndicatorB OnBarUpdate occurs 100 times so as to be up to date.

              Perfect. Thanks again for your assistance.
              Attached Files

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by DJ888, 04-16-2024, 06:09 PM
              4 responses
              12 views
              0 likes
              Last Post DJ888
              by DJ888
               
              Started by terofs, Today, 04:18 PM
              0 responses
              7 views
              0 likes
              Last Post terofs
              by terofs
               
              Started by nandhumca, Today, 03:41 PM
              0 responses
              6 views
              0 likes
              Last Post nandhumca  
              Started by The_Sec, Today, 03:37 PM
              0 responses
              3 views
              0 likes
              Last Post The_Sec
              by The_Sec
               
              Started by GwFutures1988, Today, 02:48 PM
              1 response
              9 views
              0 likes
              Last Post NinjaTrader_Clayton  
              Working...
              X