Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnStateChange() is called from "inactive" Strategy

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

  • NinjaTrader_Jim
    replied
    Hello localappleseed,

    Thanks for your post.

    Private variables are not accessible in other classes. Each strategy is its own class and each strategy created is a new instance of that class. If you have "StrategyA" utilize a private variable, and create 2 instances of the strategy, these properties will be unique.

    OnStateChange does occur multiple times throughout a scripts life. It is suggested to use State.DataLoaded for operations that should be performed only once when the script starts up. State.SetDefaults and State.Configure will be seen during the NinjaScritp LifeCycle when the script is listed in the Strategies dialog and when properties are listed in the property grid.

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

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

    Let us know if you have any additional questions.

    Leave a comment:


  • OnStateChange() is called from "inactive" Strategy

    I have several independent Strategies defined in separate code files. They are unrelated and all Strategies have their own OnStateChange() defined. Each OnStateChange() may do different things in their individual Strategies. Now I noticed OnStateChange() in all Strategies will be called and executed when I start Strategies before enabling individual Strategy.
    Question 1: If this behavior is expected, how do I avoid this?
    Question 2: If a private variable is defined and used OnStateChange() in one Strategy class, this variable will be changed by all other Strategies as they all call OnStateChange()?

    Thanks.

Latest Posts

Collapse

Topics Statistics Last Post
Started by Hagar, Today, 04:38 PM
1 response
7 views
0 likes
Last Post NinjaTrader_ShawnB  
Started by Lloyd143, Today, 05:24 PM
0 responses
5 views
0 likes
Last Post Lloyd143  
Started by [email protected], Today, 04:49 PM
0 responses
7 views
0 likes
Last Post bpatel20@gmail.com  
Started by forrestang, Today, 02:05 PM
3 responses
19 views
0 likes
Last Post NinjaTrader_ChrisL  
Started by harryodell55, Today, 01:30 PM
3 responses
26 views
0 likes
Last Post NinjaTrader_ChrisL  
Working...
X