Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

What is the value of OnStartUp()?

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

    What is the value of OnStartUp()?

    Hello,
    As I was studying NT sample code I discovered OnStartUp() there isn't much information about it in the NT7 Help guide. Could someone share it's value and when one would use it?
    Thanks.

    #2
    Originally posted by CaptainAmericaXX View Post
    Hello,
    As I was studying NT sample code I discovered OnStartUp() there isn't much information about it in the NT7 Help guide. Could someone share it's value and when one would use it?
    Thanks.
    Think of it as a method to handle things right before OnBarUpdate() runs the first time, after Initialize() has run. Typically it is used as a substitute for this block that we used to code at the start of OnBarUpdate().

    Code:
    if (CurrentBar == 0)
    {
    
    //check the validity of inputs and other stuff that must be correct before we continue.;
    //set any flags that will gate further processing;
    
    }

    Comment


      #3
      Hello CaptainAmericaXX,

      Thank you for your post.

      Kognam's answer is correct, I just thought I would offer a bit more insight and some use cases.

      Additionally, anything that you want set that you don't want changed by the user but still have a public parameter, such as CalculateOnBarClose, you can set in OnStartup() and this will supersede anything the user sets. Also, if you create custom checks outside of traditional Vendor Licensing for user authentication for a script you're planning to distribute, you would want to do that in OnStartup() as well.

      Here's a link to a help guide sample that uses OnStartUp() to start a timer:



      Please let us know if we may be of further assistance to you.
      Kate W.NinjaTrader Customer Service

      Comment


        #4
        Thank you both for your responses.
        I created an indicator that I want to use as input for other indicators. I used this method to introduce the first indicator to the second so I could use the properties from the first.
        Code:
        #region Variables
                B1HourGlass b1hg; //Introduce HourGlass indicator
         #endregion
         protected override void Initialize()
         {
                 b1hg        = B1HourGlass(14,14,7, 15, 7);//Initialize indicator
         }  
        protected override void OnBarUpdate()
        {
                 if(b1hg.BlueBackGround[0]){//Use bool
                      //some code
                 }
        }
        This approach return a false bool on every bar. When I used OnStartUp()
        Code:
        protected override void OnStartUp()
         {
                 b1hg        = B1HourGlass(14,14,7, 15, 7);//Initialize indicator
         }
        everything worked properly. I'm still trying to understand OnStartUp(). What was the difference?

        Also I could just do this and I got the results I wanted.
        Code:
        protected override void OnBarUpdate()
        {
               B1HourGlass b1hg = B1HourGlass(14,14,7,15,3);
               if(b1hg.BlueBackGround[0]){//Use bool
                      //some code
               }
        }
        Is there a preferred method? Thanks.

        Comment


          #5
          Hello CaptainAmericaXX,

          Thank you for your reply.

          Unfortunately you can't add an indicator to an indicator in Initialize() as it hasn't loaded bar data yet. The Initialize() method is called once before any initial calculation triggered by an update bar event. This method is used to configure the indicators plots, lines and properties.

          If you instantiate the indicator in OnStartUp() would mean you're creating that once, then referring to it in OnBarUpdate(). If you put it in OnBarUpdate(), it's creating a new instance of the indicator object every time OnBarUpdate() runs. It would be better to instantiate from within OnStartUp() so you can just reference the same instance repeatedly.

          Please let us know if we may be of further assistance to you.



          Kate W.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Tim-c, Today, 02:10 PM
          1 response
          7 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by Taddypole, Today, 02:47 PM
          0 responses
          2 views
          0 likes
          Last Post Taddypole  
          Started by chbruno, 04-24-2024, 04:10 PM
          4 responses
          50 views
          0 likes
          Last Post chbruno
          by chbruno
           
          Started by TraderG23, 12-08-2023, 07:56 AM
          10 responses
          399 views
          1 like
          Last Post beobast
          by beobast
           
          Started by lorem, Yesterday, 09:18 AM
          5 responses
          25 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Working...
          X