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

Series<T> Instantiation in OnStateChange() State == State.Configure Vs. DataLoaded?

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

    Series<T> Instantiation in OnStateChange() State == State.Configure Vs. DataLoaded?

    Hello,

    Either the NT8 help documentation is inconsistent with itself regarding where a Series<T> should be instantiated, or perhaps the answer is "it depends".

    On the main NT8 "OnStateChange()" documentation page (https://ninjatrader.com/support/help...tatechange.htm), the grid row for "State.Historical" has the following bullet point under the column "this is where you should":

    "Initialize any class level variables (including custom Series<T> objects)"

    However, on the "NinjaScript Best Practices" page ( https://ninjatrader.com/support/help..._practices.htm ), under the "State management practices" header, it recommends that a Series<T> be instantiated in the "else if (State == State.DataLoaded)" if/else branch:

    Code:
      else if (State == State.DataLoaded)
      {
        // Since these values do are dependent on bars, they should only reset during State.DataLoaded
        mySMAIndicator = SMA(14);
        mySeries = new Series<double>(this);
      }
    Also, the NT8 Strategy Builder instantiates Series<T> objects in the DataLoaded if/else branch. Here's an example from a strategy I created in the NT8 Strategy Builder:

    HTML Code:
    			else if (State == State.DataLoaded)
    			{				
    				MyDataSeries = new Series<double>(this);			
    			}
    When should a Series<T> object be instantiated in the "else if (State == State.DataLoaded)" section?

    When should a Series<T> object be instantiated in the "else if (State == State.Historical)" section?


    Thank you very much in advance,

    EquityTrader

    #2
    Hello,

    It's been over a day and a half since I asked the question below.

    Can anyone from NinjaTrader give an official ruling on which official NinjaScript documentation is right and which is wrong by answering the question in my previous post below?

    Based on your answer, the Strategy Builder may also need a change, but at the very least, either your "NinjaScript Best Practices" page or your "OnStateChange()" will need to be edited.

    Thank you very much,

    EquityTrader

    Comment


      #3
      Hello EquityTrader,

      Thank you for your patience.

      The Best Practices would be correct here. Thank you for bringing this to our attention I will forward this to our Product Management team.

      Comment


        #4
        Hi NinjaTrader_Patrick,

        Thank you very much for your help.

        Per your advice, I will instantiate all Series<T> objects in "else if (State == State.DataLoaded)" (per the NinjaScript Best Practices page and the Strategy Builder output) instead of in "else if (State == State.Historical)" (per the OnStateChange() page).

        Thanks again,

        EquityTrader

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by gravdigaz6, Today, 11:40 PM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by MarianApalaghiei, Today, 10:49 PM
        3 responses
        10 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by XXtrader, Today, 11:30 PM
        0 responses
        4 views
        0 likes
        Last Post XXtrader  
        Started by love2code2trade, Yesterday, 01:45 PM
        4 responses
        28 views
        0 likes
        Last Post love2code2trade  
        Started by funk10101, Today, 09:43 PM
        0 responses
        9 views
        0 likes
        Last Post funk10101  
        Working...
        X