• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

State.SetDefaults (NT8) versus Initialize() (NT7)

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

    State.SetDefaults (NT8) versus Initialize() (NT7)

    When I compare State.SetDefaults in NT8 to Initialize() in NT7, there seems to be a major difference.

    When I access any of the Properties in the Initialize() section of NT7 they carry the user selected values.

    However, when I access any of the Properties while State == State.SetDefaults the user selectable parameters still carry the hardcoded default values. I need to go to State == State.Configure to access the user selected parameters.


    This has an impact on where some of the other settings should be implemented.

    Example: BarsRequiredToPlot

    Typically you do not wish to plot any false values on your chart. Therefore for a simple moving average the logical solution would be

    Code:
    BarsRequiredToPlot = Period
    where Period is the user selected period for the SMA. In a similar fashion you could use

    Code:
    BarsRequiredToPlot = 3*Period
    for the EMA which is an IIR filter and needs a longer training period.

    The problem here is that the current value of "Period" cannot be accessed while the inidcator is in State.SetDefaults. Period always returns the default value and not the user selected period. Therefore BarsRequiredToPlot should always be set in State.Configure.

    This is a bit confusing, as NinjaTrader 7 allowed for accessing properites in both Initialize() and OnStartUp(). Accordingly it was possible to set BarsRequired in both Initialize() and OnStartUp().

    Are there any other limitations I should be aware of?

    Shouldn't the help file specify that BarsRequiredToPlot be set in State.Configure?
    Last edited by Harry; 07-09-2016, 02:46 PM.

    #2
    Hello Harry,

    Thank you for your note about this.

    I will need to do some further research to find how this should be handled.
    I appreciate your patience.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello Harry,

      Thanks for your patience.

      From my understanding, SetDefaults is the state in which values would be set for the UI initially. Configure would allow for any changes made in the UI by the user to be passed to the NinjaScript object after the user has clicked OK or Apply.

      http://ninjatrader.com/support/helpG...n-us/state.htm

      From NT7, these two states were basically one (Initialize) and the new state system of NT8 allows for more distinction between these actions.

      This means that for any math to be applied with the BarsRequiredToPlot this would need to be done in State.Configure.

      I agree that there should be a warning on the Help guide page for BarsRequiredToPlot.
      Warning: This property should ONLY bet set from the OnStateChange() method during State.SetDefaults or State.Configure.

      I've sent a request to our product management to update the Help Guide on this page to add a warning this property should only be set in State.SetDefaults or State.Configure.

      Simularly, the OnStartUp() method would be replaced by the State.DataLoaded method as this would trigger after all data series have been loaded but before the historical data starts processing.
      State.Historical could also be used in the same way as this triggers right after State.DataLoaded, however, this is as the historical data has started processing.
      This again allows for distinction between these actions.

      When you ask if there are other limitations you should be aware of, one item is adding a secondary series using the primary instrument information. An example would be if you wanted to change the session template of the secondary series. This will not always work, specifically, when creating a MarketAnalyzer column and when calling an indicator from a strategy. For this, a BarsRequest would need to be done after the script has reached State.Configure and the primary instrument is ready.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Hello Harry,

        The BarsRequiredToPlot can be set in any state. The only concern for this would be if we are performing a check in OnBarUpdate() on BarsRequiredToPlot, such as if (CurrentBars <= BarsRequiredToPlot) return;. In that case you would need to ensure that BarsRequiredToPlot is set before the Historical State.
        Patrick H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Birdseye, Today, 04:52 AM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_PaulH  
        Started by U0000999, Today, 03:43 AM
        0 responses
        5 views
        0 likes
        Last Post U0000999  
        Started by NinjaCustomer, Today, 03:22 AM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Marco  
        Started by MarianApalaghiei, Today, 01:26 AM
        0 responses
        10 views
        0 likes
        Last Post MarianApalaghiei  
        Started by seagraph, Yesterday, 03:27 PM
        0 responses
        15 views
        0 likes
        Last Post seagraph  
        Working...
        X