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

Update()

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

    Update()

    Hello,

    I know update() can be used in the way like indicator.update() and was instructed by Jim to use it in one strategy. But I can't find any documented instructions. Could anyone give more details on how to use it.

    I am looking for a way to force indicator to call previous OBU. Is this the right method? Does it update from first bar or just current bar? When I try it on historical, NT seems consider everything is updated and doesn't do anything.

    Thanks

    #2
    Hello cliffhu,

    Thanks for your post.

    The following page offers more information about Update():


    You mentioned, "I am looking for a way to force indicator to call previous OBU" What do you mean by calling the previous OBU? Please provide more details or an example so I may better understand your use case and help to determine if the use of Update() is appropriate for that use case or not.

    I look forward to your reply.
    Emily C.NinjaTrader Customer Service

    Comment


      #3
      Hi Emily,

      Thanks for the links. I have read it. But that's to use Update() inside the indicator, not from host like "SMA.update()".

      My indicator has two series. As in live they never close at same time, calculation is when primary one close and using secondary one's current market price. Assuming the secondary close later, then the next primary bar close. Now I want to replace that 'current price' with closes[1][0] and recalculate for values[0][1], as well as values[0][0]. Hope this is a typical case?

      Comment


        #4
        Originally posted by cliffhu View Post
        Hi Emily,

        Thanks for the links. I have read it. But that's to use Update() inside the indicator, not from host like "SMA.update()".

        My indicator has two series. As in live they never close at same time, calculation is when primary one close and using secondary one's current market price. Assuming the secondary close later, then the next primary bar close. Now I want to replace that 'current price' with closes[1][0] and recalculate for values[0][1], as well as values[0][0]. Hope this is a typical case?
        Hello cliffhu,

        Thanks for your reply.

        The way bars data is referenced in a multi-series script is described here:If you need OnBarUpdate() to calculate how it would when set to OnEachTick or OnPriceChange in historical calculations, you could use Tick Replay:
        Otherwise, I may not be following what you are referring to for replacing the 'current price' and I would need you to provide me with a concrete example, such as an example of the two series in question and the current price value, plus what you are looking to 'replace' it with.

        Please let me know if I may be of further assistance.
        Emily C.NinjaTrader Customer Service

        Comment


          #5
          Hi Emily,

          Here is my example,

          AddDataSeries1

          OnBarUpdate()

          if (BarsInProgress == 1)
          return;

          (assuming Times[0][0] > Times[1][0] or Series1 still building)

          recalculate value[1] using Closes[0][1] and Close[1][0]​
          calculate value[0] using Closes[0][0] and GetCurrentBid(1);


          Comment


            #6
            I'd like the recalculate to be called from host, not duplicate the whole script inside indicator.

            Comment


              #7
              Hello cliffhu,

              Thank you for your reply.

              recalculate value[1] using Closes[0][1] and Close[1][0]​
              calculate value[0] using Closes[0][0] and GetCurrentBid(1);
              If you add prints of the values for Closes[0][1] and Close[1][0], are you getting the expected values? How about when you print Closes[0][0] and GetCurrentBid(1)? Then, you should be able to reassign the Value[1] and Value[0].

              More information about using prints to debug and understand your script's behavior may be found here:


              Here is an example of some prints you could use to test out if the series have been updated as expected and how you could "recalculate" or re-assign a value to Value[1] and Value[0]:

              Code:
              Print(string.Format("{0} | Closes[0][1]: {1} | {2} Close[1][0]: {3} | Value[0] before: {4} | Value[1] before: {5} | {6} Closes[0][0]: {7} | GetCurrentBid(1)", Times[0][1], Closes[0][1], Times[1][0], Value[0] Value[1], Times[0][0], Closes[0][0], GetCurrentBid(1)));
              Value[1] = // new value here
              Value[0] = // new value here
              Print(string.Format("{0} new Value[1]: {1} new Value[0]: {2}", Time[0], Value[1], Value[0]));
              Please let me know if I may be of further assistance.​
              Emily C.NinjaTrader Customer Service

              Comment


                #8
                Hi Emily,

                Back to my original question, could you just give me instructions on how .update() works in the way like SMA.update(). Does it update from first bar or just one bar?

                Reassign Value[1] make calculation wrong and different than plot.
                Last edited by cliffhu; 01-09-2024, 07:24 AM.

                Comment


                  #9
                  Originally posted by cliffhu View Post
                  Hi Emily,

                  Back to my original question, could you just give me instructions on how .update() works in the way like SMA.update(). Does it update from first bar or just one bar?

                  Reassign Value[1] make calculation wrong and different than plot.
                  "Forces the OnBarUpdate() method to be called for all data series so that indicator values are updated to the current bar index. If the values are already up to date, the Update() method will not be run."

                  It does not update from the first bar; it will update to ensure that indicator values are updated to the CurrentBar:


                  I do not suspect that what you are looking to achieve is an appropriate use case for Update() and that is why I have been trying to gather additional details. Please provide an example of what you are referring to by, "Reassign Value[1] make calculation wrong and different than plot."
                  What value did you reassign to Value[1]? What was the expected result from the calculation vs. the actual result and what plot are you comparing it to? What are the two different values?

                  I look forward to your reply.
                  Emily C.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by fx.practic, 10-15-2013, 12:53 AM
                  5 responses
                  5,403 views
                  0 likes
                  Last Post Bidder
                  by Bidder
                   
                  Started by Shai Samuel, 07-02-2022, 02:46 PM
                  4 responses
                  94 views
                  0 likes
                  Last Post Bidder
                  by Bidder
                   
                  Started by DJ888, Yesterday, 10:57 PM
                  0 responses
                  6 views
                  0 likes
                  Last Post DJ888
                  by DJ888
                   
                  Started by MacDad, 02-25-2024, 11:48 PM
                  7 responses
                  158 views
                  0 likes
                  Last Post loganjarosz123  
                  Started by Belfortbucks, Yesterday, 09:29 PM
                  0 responses
                  8 views
                  0 likes
                  Last Post Belfortbucks  
                  Working...
                  X