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

What does OnBarUpdate() return when...

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

    What does OnBarUpdate() return when...

    Hello,

    I'm an NTD newb... However, (humbly) I am a seasoned C# developer. I was wondering if / where I can find more detailed / granular documentation on functions like "OnBarUpdate()". (White papers)

    In the case of OnBarUpdate() I'd like to see how it was written and how it is constructed to handle different return values. In this documentation



    it states:

    "If the "CalculateOnBarClose" property is set to true, it is only called on the close of each bar, otherwise it is called on each incoming tick."


    more specifically: "...it is only called on the close of each bar, otherwise it is called on each incoming tick."

    This indicates to me OnBarUpdate() returns a double (or float).

    Question: Is there an overload for OnBarUpdate() that returns an array of values or would I have to write that? The algorithm I want to write and test needs tick data for a given time series.

    In a nutshell... I've got questions that the online documentation doesn't address. Where can I find that information? Also, is there a Git repository of examples I can look at?

    Thank You for anything!
    Robert

    #2
    Hmmm... It doesn't return anything. It's void.


    Code:
    protected override void OnBarUpdate()
    {
        if (CurrentBar < 1)
            return;
     
        // Compares the primary bar's low price to the 5-minute bar's low price
        if (Low[0] > Lows[1])
             Print("The current bar's low price is greater");
    }
    Now it does allow you access to all sorts of things related to price data:

    Comment


      #3
      Hey Sledge! Thanks for responding! It's refreshing to see that I'm not the only Saturday morning code junky studying forum posts! I salute you brother ;>

      Re: "It doesn't return anything. It's void."

      (humble newb asking, not asserting) Yes, but that's on the NinjaScript layer... Not the C# definition underneath... Right?

      So here's what I aim to do... I want to look at a DataSet / Array of values from a block of time (Bar) and make a decision. Can I use the Object in the link you pasted?



      Rob
      Last edited by RobVig; 04-23-2016, 10:16 AM.

      Comment


        #4
        I'm not 100% sure of what you are asking.

        When data comes in from whatever adapter - OnBarUpdate gets called for either each tick or when a bar closes as you have noted. It's really as simple as that.

        You mentioned you need access to the data. That's where https://ninjatrader.com/support/help...rice_data2.htm comes in.

        You can access all the tick data you have with on each call.

        Previous data+more current tick each and every call to OnBarUpdate.


        I hope this helps.

        Comment


          #5
          Sledge,
          Thanks again for sticking with me.
          On this: https://ninjatrader.com/support/help...rice_data2.htm
          Working with Price data / Referencing Price Type Data
          We can get Open-High-Low-Last-Vol... But what if I want to analyze all the tick data for a given time period based on OnBarUpdate() ?
          So let's say when OnBarUpdate() fires (which itself returns void) I somehow get access to all the tick data for that specific "BarUpdate"... I'm inclined to think I'd need to:
          1. create an array
          2. have OnBarUpdate() run for each tick
          3. Call a method from OBU() which stuffs each tick into an array
          4. Build a timer
          5. Stuff my array into my algorithm and grind it...

          I was hoping I could just get it from an override of OBU()...

          I'm interested in your thoughts.

          Rob

          Comment


            #6
            I'm not sure what your algorithm will do, so I can't really speculate what is needed.

            But if you look at how some other indicators are coded, like the supplied ones from NT, it might give you a better idea. Maybe have a look here in the NT7 download folder to find something similar that you can adapt for your needs.

            You might want to also read up on DataSeries class. It's kind of like an array, and that is what all the High/Low/Close/etc are built from.

            So Close[0] = most current incoming , Close[1] = previous, Close[2] = before previous...

            Sometimes there is no need to recompute everything. Like in the SMA.

            Comment


              #7
              Yep. I think (perhaps) using combo of DataSeries and SMA; I might be able to rig what I want to build.

              Thank You for answering my questions and pointing me in the right direction Sledge :>

              Rob

              Comment


                #8
                So... After looking around a little in the Language Reference material... In a nutshell, let's say I need to write a custom Rising() method.



                Question 1 : Can I see how Rising() is built?
                Answer 1 :

                Question 2 : Can I override Rising()?
                Answer 2 :

                Question 3: According to the docs, am I only able to use SMA() as an input parameter?
                Answer 3:
                Last edited by RobVig; 04-23-2016, 12:51 PM.

                Comment


                  #9
                  Originally posted by RobVig View Post
                  Sledge,
                  Thanks again for sticking with me.
                  On this: https://ninjatrader.com/support/help...rice_data2.htm
                  Working with Price data / Referencing Price Type Data
                  We can get Open-High-Low-Last-Vol... But what if I want to analyze all the tick data for a given time period based on OnBarUpdate() ?
                  So let's say when OnBarUpdate() fires (which itself returns void) I somehow get access to all the tick data for that specific "BarUpdate"... I'm inclined to think I'd need to:
                  1. create an array
                  2. have OnBarUpdate() run for each tick
                  3. Call a method from OBU() which stuffs each tick into an array
                  4. Build a timer
                  5. Stuff my array into my algorithm and grind it...

                  I was hoping I could just get it from an override of OBU()...

                  I'm interested in your thoughts.

                  Rob
                  So essentially you want to capture streaming data into a fixed dataset, then process that fixed dataset, instead of processing the data stream in the manner of a stream editor?

                  Comment


                    #10
                    Originally posted by RobVig View Post
                    So... After looking around a little in the Language Reference material... In a nutshell, let's say I need to write a custom Rising() method.



                    Question 1 : Can I see how Rising() is built?
                    Answer 1 :

                    Question 2 : Can I override Rising()?
                    Answer 2 :

                    Question 3: According to the docs, am I only able to use SMA() as an input parameter?
                    Answer 3:
                    1. Checks for a rising condition which is true when the current value is greater than the value of 1 bar ago.


                    Probably does something like:

                    if ( Close[0] > Close[1] )
                    return TRUE;
                    else
                    return FALSE;

                    2. I guess. Never tried.




                    3: No.
                    Code:
                    Parameters
                    
                    series  Any DataSeries type object such as an[B][U] indicator, Close, High, Low, etc[/U][/B]...

                    Comment


                      #11
                      CRAP !!! I deleted one of my posts and it deleted the last guys' post!!!!

                      So... Everyone else can't read what he said but addressing him directly, my answer if "correct". I'm so bummed... He hit the nail on the head... I hope "he" can re-post his answer.

                      Anyway, I do want a DataSet or better, a custom object.


                      I want to collect values (data) into a DataSet consisting of say, the past five seconds, process that data, return it from a function and pass it to another function. Also... can I sub class???

                      Ex:


                      public class MyStrategy : Strategy
                      {
                      MyClass myClass = new MyClass();

                      private OnBarUpdate() {
                      // Create a DataSet of the current Bar <<< ---------------
                      myClass.DoMagicA(dataSet);
                      }
                      }

                      Class MyClass {
                      public double CurrentTickValue { get; set; }
                      ...

                      MyClass() {
                      // initializer stuff
                      }

                      public double DoMagicA(double ctv) {
                      // magic mojo here...
                      this.DoMagicB(someDouble);
                      return someValue
                      }

                      public bool DoMagicB(double ctv) {
                      // magic mojo here...
                      return someVal;
                      }
                      }
                      Last edited by RobVig; 04-23-2016, 04:57 PM.

                      Comment


                        #12
                        Originally posted by RobVig View Post
                        CRAP !!! I deleted one of my posts and it deleted the last guys' post!!!!

                        So... Everyone else can't read what he said but addressing him directly, my answer if "correct". I'm so bummed... He hit the nail on the head...

                        Anyway, I do want a DataSet...
                        Check your email. The reply might be there if you get email notifications.

                        Comment


                          #13
                          I've got some emails with the post but not this particular one... Anyway, regarding "Rising()" specifically, it's not so much about "Rising' per se, rather "extending / overriding" existing functions and creating my own from scratch... I feel like there's going to be a glass ceiling on writing algorithms if I am confined by builtin functions. I'd like to harvest data, bring it into my custom objects, do my particular crunch and then apply it to a trade... As a newb studying the NinjaScript library and reference material, it's almost like a set of lego's that will only take me so far. Hopefully I'm wrong and I just haven't learned how to extend NTD yet :>

                          Comment


                            #14
                            Originally posted by RobVig View Post
                            CRAP !!! I deleted one of my posts and it deleted the last guys' post!!!!

                            So... Everyone else can't read what he said but addressing him directly, my answer if "correct". I'm so bummed... He hit the nail on the head... I hope "he" can re-post his answer.

                            Anyway, I do want a DataSet or better, a custom object.


                            I want to collect values (data) into a DataSet consisting of say, the past five seconds, process that data, return it from a function and pass it to another function. Also... can I sub class???

                            Ex:


                            public class MyStrategy : Strategy
                            {
                            MyClass myClass = new MyClass();

                            private OnBarUpdate() {
                            // Create a DataSet of the current Bar <<< ---------------
                            myClass.DoMagicA(dataSet);
                            }
                            }

                            Class MyClass {
                            public double CurrentTickValue { get; set; }
                            ...

                            MyClass() {
                            // initializer stuff
                            }

                            public double DoMagicA(double ctv) {
                            // magic mojo here...
                            this.DoMagicB(someDouble);
                            return someValue
                            }

                            public bool DoMagicB(double ctv) {
                            // magic mojo here...
                            return someVal;
                            }
                            }
                            NinjaTrader is a c# framework that does a lot of that structural work for you. Of course, if you prefer to reinvent the wheel, have at it.

                            As far as creating a dataset, yes, you will have to put that data into some kind of collection, if that is your preference, then analyze the collection and return what you want. This would be especially true if you want to collect tick data in a bar, though you could just use a multi-timeframe class and use the resultant DataSeries elements directly. After all, they are collections in themselves.

                            It may pay you better to read through the manual, so you get the hang of how to set things up. There are tutorials in there.

                            Comment


                              #15
                              Originally posted by RobVig View Post
                              I've got some emails with the post but not this particular one... Anyway, regarding "Rising()" specifically, it's not so much about "Rising' per se, rather "extending / overriding" existing functions and creating my own from scratch... I feel like there's going to be a glass ceiling on writing algorithms if I am confined by builtin functions. I'd like to harvest data, bring it into my custom objects, do my particular crunch and then apply it to a trade... As a newb studying the NinjaScript library and reference material, it's almost like a set of lego's that will only take me so far. Hopefully I'm wrong and I just haven't learned how to extend NTD yet :>
                              (Un?)fortunately, you are wrong.

                              NT is just a framework. Have it at with standard C#. There are a few restrictions because of how things are handled internally. The keyword is "few". A lot of what you will come across are not even actually restrictions, just a misunderstanding of how things work. Some are actual restrictions, especially when it comes to the behavior of class properties.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by funk10101, Today, 09:43 PM
                              0 responses
                              1 view
                              0 likes
                              Last Post funk10101  
                              Started by pkefal, 04-11-2024, 07:39 AM
                              11 responses
                              36 views
                              0 likes
                              Last Post jeronymite  
                              Started by bill2023, Yesterday, 08:51 AM
                              8 responses
                              44 views
                              0 likes
                              Last Post bill2023  
                              Started by yertle, Today, 08:38 AM
                              6 responses
                              25 views
                              0 likes
                              Last Post ryjoga
                              by ryjoga
                               
                              Started by algospoke, Yesterday, 06:40 PM
                              2 responses
                              24 views
                              0 likes
                              Last Post algospoke  
                              Working...
                              X