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!
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
NinjaTrader
OnStateChange() is called from "inactive" Strategy
Collapse
X
-
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.
-
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.
Tags: None
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by helpwanted, Today, 03:06 AM
|
1 response
12 views
0 likes
|
Last Post Today, 03:35 AM | ||
Started by Brevo, Today, 01:45 AM
|
0 responses
9 views
0 likes
|
Last Post
by Brevo
Today, 01:45 AM
|
||
Started by aussugardefender, Today, 01:07 AM
|
0 responses
5 views
0 likes
|
Last Post Today, 01:07 AM | ||
Started by pvincent, 06-23-2022, 12:53 PM
|
14 responses
242 views
0 likes
|
Last Post
by Nyman
Today, 12:47 AM
|
||
Started by TraderG23, 12-08-2023, 07:56 AM
|
9 responses
387 views
1 like
|
Last Post
by Gavini
Today, 12:29 AM
|
Leave a comment: