• 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

OnStateChange() and State.SetDefaults

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

    OnStateChange() and State.SetDefaults

    I understand how the OnStateChange() method works and what should be done in each state:

    https://ninjatrader.com/support/help...tatechange.htm

    On other hand I can see that if I develop simple indicators setting up the parameters just on the state SetDefaults everything seems to work fine. Even when I don't use the rest of the states.

    I'm not sure about this. Is there any risk in programming an indicator using just the state SetDefaults when the other states are not required? Is there any case in which the use of the other states is mandatory? For example, optimizations, real time trading, etc?

    I would appreciate any light here.

    Thanks in advance.



    #2
    Hello Planket,

    Thanks for your post.

    There are some specific tasks that should be done in specific states. For example, transitioning Order objects from historical processing must be done in State.Realtime, UI modifications should be done in State.Historical, State.Configure would be used for adding additional data, and State.DataLoaded would be best for all other NinjaScript start up operations and resetting class level variables for using IsInstantiatedOnEachOptimizationIteration.

    Scripts also are cloned and pass through a LifeCycle where State.SetDefaults will be called when the indicator is populated in the Indicators window and when the indicator default properties are added to the Indicators window property grid before the indicator actually gets added and used. If State.SetDefaults is over utilized, it can impact how long it takes the Indicators dialog to open.

    For more information on NinjaScript states, the NinjaScript LifeCycle and best practices for State Management, please see the publicly available resources below.

    Understanding OnStateChange - https://www.youtube.com/watch?v=gyel6m3VIWs

    NinjaScript LifeCycle - https://ninjatrader.com/support/help...fecycle_of.htm

    Best Practices for State Management - https://ninjatrader.com/support/help...urceManagement

    IsInstantiatedOnEachOptimizationIteration - https://ninjatrader.com/support/help...niteration.htm

    Please let me know if I can be of further assistance.
    Last edited by NinjaTrader_Jim; 03-18-2019, 11:53 AM.
    JimNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Dan_D_Trader, Today, 03:49 PM
    0 responses
    4 views
    0 likes
    Last Post Dan_D_Trader  
    Started by JohnAymin, Today, 02:38 PM
    1 response
    5 views
    0 likes
    Last Post NinjaTrader_Tyler  
    Started by Rmos22, Today, 02:20 PM
    2 responses
    22 views
    0 likes
    Last Post Rmos22
    by Rmos22
     
    Started by sawtooth500, Today, 12:59 PM
    1 response
    9 views
    0 likes
    Last Post NinjaTrader_Spencer  
    Started by Steve L, Yesterday, 09:36 PM
    1 response
    22 views
    0 likes
    Last Post NinjaTrader_Kate  
    Working...
    X