Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Post Initialize Routine

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

    Post Initialize Routine

    I have been converting a bunch of indicators, and had an idea for a new routine in the indicator framework.

    Today there is Initialize() and OnBarUpdate(), and certain items can not be accessed in Initialize() because Bars does not exists yet. There are certain kinds of setup that needs to be done post initialize and before processing data. Typically, this is done with a if (CurrentBar == 0) or some other bool flag to call a routine once.

    What would be nice is to have a new routine PostInitialize() that could be overridden to implement this type of functionality (dont care about the name). The routine would only be called once after initialize and before the first tick of data.

    By placing this in the framework, the constant checking if a routine has run once could be removed from OnBarUpdate(). There should be an elegant place to put this routine call in the Ninja indicator framework (and perhaps strategy also).

    This is a minor enhancement, but would really clean things up and move functionality to where it really belongs.

    #2
    Thanks for the suggestion, this is something we considered but decided against...I don't recall all the reasons why at this time.
    RayNinjaTrader Customer Service

    Comment


      #3
      try

      ToString()


      could do what you need.


      regards
      andreas

      Comment


        #4
        Well, I had to think about that one, but yes, that is a nice place to put that function. ToString() will be called multiple times, but it is a good place to slip in one time init functionality. Here is an example for others:

        Code:
        private bool runOnce = false;   // put this in your var section
        
        public override string ToString() {
            if (!runOnce) {
                runOnce = true;
                // do one time init post Initialize()
            }
            return base.ToString();
        }
        Thanks for the hint Andreas.

        Comment


          #5
          Actually I recommend NOT doing that. Reason: your code likely only needed to executed BEFORE OnBarUpdate(). There are many temporary instances of indicators and strategies around where
          - either Initialize() was not yet called but .ToString() was
          - Initialize() and .ToString() was called but OnBarUpdate() NEVER would be called

          Don't try to be too sophisticated and go with our suggestion which always was having a flag and putting the logic in OnBarUpdate().

          Comment


            #6
            Interesting. So now we have another reason to consider my original suggestion

            Comment


              #7
              I would say you have another reason to do we recommended.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              602 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              347 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              103 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              560 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              559 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X