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
New indicators added each time strategy is started
Collapse
X
-
New indicators added each time strategy is started
My strategy uses two indicators that I wrote. Each time I disable and then re-enable my strategy another instance of each indicator appears in the indicator dialog. When I try to remove them I get a dialog that says they cannot be removed because they are being used, even though the strategy has been removed.Tags: None
-
Originally posted by bernie_c View PostMy strategy uses two indicators that I wrote. Each time I disable and then re-enable my strategy another instance of each indicator appears in the indicator dialog. When I try to remove them I get a dialog that says they cannot be removed because they are being used, even though the strategy has been removed.
Comment
-
As suggested, I make a new strategy with the wizard and just added the lines of code that load my indicator and a strategyPlot. My code also does the load in Initialize(). Here is the edit:
Code:private bcIi bc_ind; protected override void Initialize() { bc_ind = bcIi(); Add( bc_ind ); Add( StrategyPlot(0) ); }
This is exactly how I do it in my problematic strategy.
Just to be clear, in my original post I mentioned two indicators. I was actually referring to the one indicator (bcIi()) and the strategyPlot. They both persist after my strategy is removed.
Comment
-
The plot thickens...
My strategy has a tool strip button. I have this event handler in my strategy. When I comment this handler out the persistent indicators problem goes away.
Code:protected override void OnTermination() { if( strip != null ) { if( butt_trade_ctrl != null ) strip.Items.Remove( butt_trade_ctrl ); } strip = null; butt_trade_ctrl = null; base.Dispose(); }
Comment
-
Originally posted by bernie_c View PostThe plot thickens...
My strategy has a tool strip button. I have this event handler in my strategy. When I comment this handler out the persistent indicators problem goes away.
Code:protected override void OnTermination() { if( strip != null ) { if( butt_trade_ctrl != null ) strip.Items.Remove( butt_trade_ctrl ); } strip = null; butt_trade_ctrl = null; base.Dispose(); }
Comment
-
koganam, That appeared to do the trick. I no longer get the persistent indicators.
Backstory:
OnTermination() which is where the Dispose() call is is from the MAToggle example. MAToggle is an indicator. I liked the toolbar buttons, so I just copied all the button related logic. My implementation of the buttons is in a strategy. Do I really need to dispose in a strategy? Or do I need to do the equivalent in another way?
Comment
-
Originally posted by bernie_c View Postkoganam, That appeared to do the trick. I no longer get the persistent indicators.
Backstory:
OnTermination() which is where the Dispose() call is is from the MAToggle example. MAToggle is an indicator. I liked the toolbar buttons, so I just copied all the button related logic. My implementation of the buttons is in a strategy. Do I really need to dispose in a strategy? Or do I need to do the equivalent in another way?
Comment
-
Hello bernie_c,
Thank you for your response.
You can call Dispose() in OnTermination(). In general, any indicators called from the strategy are removed when the strategy is disabled, so this may complicate the process when you call Dispose() in OnTermination for the strategy.
ToolStrips are unsupported as well and there may be unexpected behavior when attempting to Dispose() any forms from a strategy when it is disabled.
Comment
-
Originally posted by NinjaTrader_PatrickH View PostHello bernie_c,
Thank you for your response.
You can call Dispose() in OnTermination(). In general, any indicators called from the strategy are removed when the strategy is disabled, so this may complicate the process when you call Dispose() in OnTermination for the strategy.
ToolStrips are unsupported as well and there may be unexpected behavior when attempting to Dispose() any forms from a strategy when it is disabled.
ref: http://www.ninjatrader.com/support/h...rmination2.htm
Moreover, this particular case actually more or less proves the point, does it not?
Comment
-
Hello koganam.
Agreed, the Help Guide details it as the following:
Note: Please do NOT overload the Dispose() method. Dispose() method could be triggered much later than expected resulting in resources not being released early enough.
Code:protected override void OnTermination() { textBrush.Dispose(); stringFormat.Dispose(); }
Comment
-
Originally posted by NinjaTrader_PatrickH View PostHello koganam.
Agreed, the Help Guide details it as the following:
However, the CustomPlotSample indicator in NinjaTrader does in fact use Dispose() for the textBrush and stringFormat:
Code:protected override void OnTermination() { textBrush.Dispose(); stringFormat.Dispose(); }
Comment
-
Maybe calling the Dispose() method of each specific created object is the ticket. I did some trial and error and came up with the following arrangement that appears to work.
Code:protected override void OnTermination() { if( strip != null ) { if( butt_trade_ctrl != null ) strip.Items.Remove( butt_trade_ctrl ); butt_trade_ctrl.Dispose(); // strip.Dispose(); } }
Is strip.Items.Remove( butt_trade_ctrl ); really needed?
Patrick said: "ToolStrips are unsupported as well and there may be unexpected behavior when attempting to Dispose() any forms from a strategy when it is disabled."
Are any buttons (other than toolStrip buttons) supported? It seems like a natural thing to want to interact with a running strategy.
Comment
-
Originally posted by bernie_c View PostMaybe calling the Dispose() method of each specific created object is the ticket. I did some trial and error and came up with the following arrangement that appears to work.
Code:protected override void OnTermination() { if( strip != null ) { if( butt_trade_ctrl != null ) strip.Items.Remove( butt_trade_ctrl ); butt_trade_ctrl.Dispose(); // strip.Dispose(); } }
Is strip.Items.Remove( butt_trade_ctrl ); really needed?
Patrick said: "ToolStrips are unsupported as well and there may be unexpected behavior when attempting to Dispose() any forms from a strategy when it is disabled."
Are any buttons (other than toolStrip buttons) supported? It seems like a natural thing to want to interact with a running strategy.
Just be careful that they are objects that can get reinitialized. Remember that OnTermination() is also called when you refresh the chart (F5).
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by cutzpr, Today, 08:54 AM
|
0 responses
4 views
0 likes
|
Last Post
by cutzpr
Today, 08:54 AM
|
||
Started by benmarkal, Today, 08:44 AM
|
0 responses
4 views
0 likes
|
Last Post
by benmarkal
Today, 08:44 AM
|
||
Started by Tin34, Today, 03:30 AM
|
2 responses
26 views
0 likes
|
Last Post
by Tin34
Today, 04:11 AM
|
||
Started by sastrades, Yesterday, 09:59 AM
|
2 responses
38 views
0 likes
|
Last Post Today, 04:06 AM | ||
Started by ETFVoyageur, Today, 12:52 AM
|
1 response
21 views
0 likes
|
Last Post Today, 03:36 AM |
Comment