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

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:



    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 PaulMohn, Today, 03:49 AM
    0 responses
    3 views
    0 likes
    Last Post PaulMohn  
    Started by inanazsocial, Today, 01:15 AM
    1 response
    7 views
    0 likes
    Last Post NinjaTrader_Jason  
    Started by rocketman7, Today, 02:12 AM
    0 responses
    10 views
    0 likes
    Last Post rocketman7  
    Started by dustydbayer, Today, 01:59 AM
    0 responses
    2 views
    0 likes
    Last Post dustydbayer  
    Started by trilliantrader, 04-18-2024, 08:16 AM
    5 responses
    23 views
    0 likes
    Last Post trilliantrader  
    Working...
    X