Thanks
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
Disable PlaySound() if running in Strategy
Collapse
X
-
Hello RandyT,
Thanks for your post.
Out of box, an indicator does not have any knowledge if it is added to a strategy. As a workaround, you could create an AddOn with static methods/variables for a means to have the strategy and the indicator communicate and share if that indicator is added by the strategy. C# code using GetHashCode() could be used to uniquely identify a specific instance of a NinjaScript object.
An example for creating an AddOn for shared methods can be found below.
Please let us know if you have any additional questions.JimNinjaTrader Customer Service
-
Originally posted by RandyT View PostIs there a State flag I can use or something similar to avoid playing audio when an indicator is being used in a strategy? (Indicator I am developing)
Why not create your own public non-browsable boolean property in your indicator that controls whether sound is played or not?
When adding the indicator to the strategy, the strategy programmer explicitly sets this property to make the indicator 'go silent'.
Problem solved.
Comment
-
Thanks bltdavid,
This is the way I have handled this. Seems a bit messy.
Is there a way to may parameters optional when loading an indicator from a strategy? Just use the defaults? That would allow me to keep the PlaySound() false and load the indicator without passing a string of parameters every time. Not a huge deal, but generally I am just wanting default parameters for these indicators anyway.
Comment
-
Originally posted by RandyT View PostThanks bltdavid,
This is the way I have handled this. Seems a bit messy.
Is there a way to may parameters optional when loading an indicator from a strategy? Just use the defaults? That would allow me to keep the PlaySound() false and load the indicator without passing a string of parameters every time. Not a huge deal, but generally I am just wanting default parameters for these indicators anyway.
Are you sure you know what 'non-browsable' means?
Code:[Browsable(false)] public bool Silence { get; set; }
This property, although public, is not added to the parameter list of your indicator.
Why? Read about Browsable and NinjaScriptProperty (which is new for NT8) attributes.
In your indicator, you check the value of this property before calling PlaySound, for example, setup a wrapper function, like this,
Code:private void MyPlaySound(string filnam) { if (!Silence) PlaySound(filnam); }
Code:MyIndicator ind = MyIndicator(...); ind.Silence = true; AddChartIndicator(ind); // optional
Good luck!Last edited by bltdavid; 08-15-2018, 01:41 AM.
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by SnailHorn, 03-27-2024, 09:54 AM
|
4 responses
17 views
0 likes
|
Last Post
by SnailHorn
Today, 09:19 AM
|
||
Started by ninza33, Today, 07:16 AM
|
3 responses
18 views
0 likes
|
Last Post
by ninza33
Today, 09:01 AM
|
||
Started by foxtrott21, Today, 08:27 AM
|
0 responses
4 views
0 likes
|
Last Post
by foxtrott21
Today, 08:27 AM
|
||
Started by jaypelle3, Today, 08:26 AM
|
0 responses
3 views
0 likes
|
Last Post
by jaypelle3
Today, 08:26 AM
|
||
Started by linkcou, Today, 07:01 AM
|
2 responses
26 views
0 likes
|
Last Post
by bltdavid
Today, 08:25 AM
|
Comment