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

When does the framework call the 'set' methods for strategy parameters?

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

    When does the framework call the 'set' methods for strategy parameters?

    Hi,

    In order to prevent having to manually set various strategy properties using the strategy dialog for each instrument I run my strategy against (which is cumbersome and error prone), I wrote some code that reads the values from within a method in my strategy and assigns the appropriate value to each property based on what the master instrument is. This method is called within the Initialize() method of my strategy.

    After I populate the values of these variables, I write them out using Print statements so I can confirm they are set correctly (which, at this point, they are). However, after noticing some odd behaviour, I have discovered that the values I set using my method that is called in Initialize() are later OVERWRITTEN to whatever values are set in the strategy dialog (when I say strategy dialog, I'm referring to the dialog that appears when right click on a strategy in the strategies tab of the Control Center and select 'edit strategy').

    My assumption, which is obviously incorrect, was that whatever values you set to properties within Initialize() would remain for the lifetime of the intantiated strategy object, but it seems the framework is calling the set methods on these properties at a later point in time.

    So, my question is: When, and under what conditions, does the framework call the set methods of a strategy's properties using the values defined in the strategy dialog?

    Note: it's an inefficient workaround, but I found calling my method to set the parameter values each time OnBarUpdate() is called fixes the problem.

    #2
    Hi HitTheCity, I would suggest you move your parameter set per task to the only once called OnStartUp() in NT7 - http://www.ninjatrader.com/support/h.../onstartup.htm

    This method would be called once after Initialize() but before the first OnBarUpdate().
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thanks for the response Bertrand, I will give that a try and get back to you.

      Comment


        #4
        Yes, that fixed the issue.

        So the order of operations performed by the platform for a Strategy is as such:

        - Strategy object instantiated
        - Initialize() called
        - Strategy parameters populated from values set in strategy dialog (overwriting any values set in Initialize(), hence my problem)
        - OnStartup() called
        - OnBarUpdate() called each time a data series object updates

        Thanks for you assistance once again.

        Comment


          #5
          Glad to hear that would be correct, Initialize() can be called multiple times and across scripts, so for one time operations or allocating custom resources OnStartUp() is ideal.
          BertrandNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Christopher_R, Today, 12:29 AM
          0 responses
          9 views
          0 likes
          Last Post Christopher_R  
          Started by sidlercom80, 10-28-2023, 08:49 AM
          166 responses
          2,235 views
          0 likes
          Last Post sidlercom80  
          Started by thread, Yesterday, 11:58 PM
          0 responses
          3 views
          0 likes
          Last Post thread
          by thread
           
          Started by jclose, Yesterday, 09:37 PM
          0 responses
          8 views
          0 likes
          Last Post jclose
          by jclose
           
          Started by WeyldFalcon, 08-07-2020, 06:13 AM
          10 responses
          1,415 views
          0 likes
          Last Post Traderontheroad  
          Working...
          X