Is there a way to ensure, that only a single instance of an indicator is loaded on chart?
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Ensuring that only a single instance of an indicator is loaded on chart
Collapse
X
-
Ensuring that only a single instance of an indicator is loaded on chart
Hi,
Is there a way to ensure, that only a single instance of an indicator is loaded on chart?Tags: None
-
Hello Shai Samuel,
Thank you for writing in. While there is no way to prevent a user from attempting to add multiples of the same indicator, you can add a check in your indicator so that it simply returns if it has been added more than once.
For example:
Please let me know if I may be of further assistance.Code:#region Variables private bool alreadyExists = false; #endregion protected override void Initialize() { foreach(Indicator i in ChartControl.Indicators) { if(i.Name == "myIndicator") //Replace with the name of your indicator { alreadyExists = true; return; } else { //Initialize the indicator } } } protected override void OnBarUpdate() { if(!alreadyExists) { //your OnBarUpdate() code goes here } }Michael M.NinjaTrader Quality Assurance
-
Thank you Michael, this is really helpful.
koganam, what I would add to this code, is a Log message with NinjaTrader.Cbi.LogLevel.Alert, and return.
Comment
-
Comment
-
Hello Shai Samuel,
Please see this post for more information on this topic: http://ninjatrader.com/support/forum...ad.php?t=64014
Please let me know if you have any further questions.Michael M.NinjaTrader Quality Assurance
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by CarlTrading, 03-31-2026, 09:41 PM
|
1 response
82 views
1 like
|
Last Post
|
||
|
Started by CarlTrading, 04-01-2026, 02:41 AM
|
0 responses
43 views
0 likes
|
Last Post
by CarlTrading
04-01-2026, 02:41 AM
|
||
|
Started by CaptainJack, 03-31-2026, 11:44 PM
|
0 responses
64 views
2 likes
|
Last Post
by CaptainJack
03-31-2026, 11:44 PM
|
||
|
Started by CarlTrading, 03-30-2026, 11:51 AM
|
0 responses
68 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:51 AM
|
||
|
Started by CarlTrading, 03-30-2026, 11:48 AM
|
0 responses
56 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:48 AM
|

Comment