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

Clarification Best Practice Configure or DataLoaded

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

    Clarification Best Practice Configure or DataLoaded

    Best Practices suggests putting " MySMAIndicator = SMA(14) or mySeries = new Series,double.(this) in Data Loaded. The reason is for rests during Strategy Optimization. Based on examples I put many such values in State.Configure. Should I move them to DataLoaded?

    I see in Best Management Practices under "Resetting Class Level Variables" that such statements should be in DataLoaded. Doing that conflicts with what I thought from examples and other help items that I should do. Please clarify.

    Thank you.

    #2
    Hello JGRtrader,

    Yes, these should be moved to State.DataLoaded. Anything calls related to data should be called in State.DataLoaded or later after the data has loaded. This includes the Instrument, BarsArray, new Series<T>, and indicator calls.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Chelsea, can you explain why it is better to have those values in DataLoaded instread of Configure? I have bulk of my settings in SetDefaults and Configure

      Comment


        #4
        Hello UltraNIX,

        Data (bar series) objects are not fully instantiated by NinjaTrader until State.DataLoaded. You can call AddDataSeries() in State.Configure, which will also cause that data to be loaded. But the data series themselves are not fully ready until State.DataLoaded.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_ChelseaB View Post
          Yes, these should be moved to State.DataLoaded. Any calls related to use of data should be called in State.DataLoaded or later after the data has loaded. This includes the Instrument, BarsArray, new Series<T>, and indicator calls.
          [NOTE: The above emphasis and rewording in red are mine]

          So, in your previous comment, you really meant to say any use of the
          data
          should wait until State.DataLoaded, right?

          Adding new data series, or defining series with new Series<T>, or storing
          a reference to an indicator call (which will be called later) -- these could all
          be done safely from State.Configure, right?

          Chelsea, I'm not sure what you've said is very clear, so I'm trying to help.

          Thus I'm trying to make the distinction between 'no data is available' in
          State.Configure and reconcile that with things like,

          AddDataSeries(...);
          MySeries = new Series<T>;
          mySma = SMA(50);

          which don't seem to directly require data anyways. Thus the above kinds
          of code can be safely stuffed into State.Configure, as long we're careful
          to not access these data structures until State.DataLoaded, right?

          Comment


            #6
            Hello bltdavid,

            A new Series object is synchronized with the primary series which is not available until State.DataLoaded.
            In the help guide for Series<T>:
            "3.In the OnStateChange() method, in the State.DataLoaded create a new Series<T> object and assign it to the "myDoubleSeries" variable"


            Indicators require an input series, typically the primary series unless an added series is specified, and that data for the input series is not available until State.DataLoaded.
            From the help guide on OnStateChange():
            "State.DataLoaded
            DataLoaded is called only once after all data series have been loaded.
            •Use for logic that needs to access data related objects like Bars, Instruments, BarsPeriod, TradingHours or instantiating indicators
            •Notify that all data series have been loaded
            •Initialize any class level variables (including custom Series<T> objects)"


            From the help guide on NinjaScript Best Practices in 'Accessing properties related to market data'.
            "Do not attempt to access objects related to instrument market data until the State has reached State.DataLoaded
            Why: Waiting to access objects that depend on market data until DataLoaded prevents access errors in all scenarios"

            And from 'Setting up resources that rely on market data'
            "For objects which depend on market data, delay their construction until the State has reached State.DataLoaded
            Why: Waiting to construct objects that depend on market data until DataLoaded ensures that their underlying input contains significant values in all scenarios."



            These are not safe to construct or call from State.Configure as these require data which is not available until State.DataLoaded.

            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Gotcha, thanks!

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by rhyminkevin, Today, 04:58 PM
              3 responses
              48 views
              0 likes
              Last Post Anfedport  
              Started by iceman2018, Today, 05:07 PM
              0 responses
              5 views
              0 likes
              Last Post iceman2018  
              Started by lightsun47, Today, 03:51 PM
              0 responses
              7 views
              0 likes
              Last Post lightsun47  
              Started by 00nevest, Today, 02:27 PM
              1 response
              14 views
              0 likes
              Last Post 00nevest  
              Started by futtrader, 04-21-2024, 01:50 AM
              4 responses
              50 views
              0 likes
              Last Post futtrader  
              Working...
              X