![]() |
|
|||||||
| Version 7 Beta General Questions & Bug Reports Ask questions here and post bug reports. |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Jan 2009
Posts: 584
Thanks: 2
Thanked 21 times in 12 posts
|
Hello,
I would like to understand better the sequence of Initialize and Dispose of an Indicator in NT7. I have one chart window open and on this chart MyIndicator is loaded. So it shows up as MyIndicator(ES 12-09,1Min,..) fine. Now I put some Print statements in Dispose and Initialize Then I change the symbol in the chart window from ES 12-09 to FDAX 12-09. From the Print statements I get. MyIndicator(FDAX(12-09).Dispose ( ????? My expectation: MyIndicator(ES 12-09) MyIndicaor(FDAX(12-09).Initialize MyIndicator(FDAX(12-09).Dispose Now I am puzzled: I would expect the first .Dispose to be associated with the (ES 12-09) Instrument, which is the one beeing disposed. Could you please enlight what is happening? P.S. Please enable debugging for the scripts, it is almost impossible to debug only via Print statements. Best regards Andreas |
|
|
|
|
|
#2 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,164
Thanks: 6
Thanked 46 times in 32 posts
|
Hi,
This is not documented but we no longer advise using Dispose(). Please use the following to dispose of your resources. protected override void OnTermination() { // Dispose logic here }
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Jan 2009
Posts: 584
Thanks: 2
Thanked 21 times in 12 posts
|
Thank you, I will try...
just to know: Same for Strategies, OnTermination() instead of Dispose() what about calling the base class implementation, necessary? i guess no longer needed otherwise you could well stick with Dispose OnTermination(){ base.OnTermination().... needed? } Best regards andreas |
|
|
|
|
|
#4 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
Right it's not needed. OnTermination only would hold your "custom cleanup" code.
Dierk
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Senior Member
Join Date: Jan 2009
Posts: 584
Thanks: 2
Thanked 21 times in 12 posts
|
OK,
so OnTermination is called before Dispose, right? Probably you want to clean up as much as possible outside the GC Dispose? My problem before was Instrument.FullName related. Same as in Initialize, Instrument.MasterInstrument.Name now. regards |
|
|
|
|
|
#6 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
What exact issue do you see?
Dierk
NinjaTrader Customer Service |
|
|
|
|
|
#7 |
|
Senior Member
Join Date: Jan 2009
Posts: 584
Thanks: 2
Thanked 21 times in 12 posts
|
Dierk,
please read again my first post , the behaviour with OnTermination is the same as with Dispose. First issue: My point is: On a chart window , when I change the instrument from ES 12-09 to FDAX 12-09 I expect something like this: MyIndicator(ES 12-09).OnTerminate MyIndicator(FDAX 12-09).Initilialize Instead all calls are with the new instrument, hence I see MyIndicator(FDAX 12-09).OnTerminate. MyIndicator(FDAX) Initialize This does not make sense to me, especially I need the correct instrument informnation because I save and load instrument relative data in Initialize and OnTerminate. Second issue; How can I get the instrument.FullName in Initialize()? GetBarsInProgress is not allowed, so this means that there are changes due to the multinstrument charts, any doc around or should I just dissassmble ...? I get only MasterInstrument.Name and the expiry, so I can by hand construct me the Fullname, but does all this make sense? What am I missing? Best regards, Sorry if I am less clear than usual , but I am sick and therfore a bit confused. |
|
|
|
|
|
#8 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
on 1) Not sure why you keep referring to particular instruments. This is irrelevant. The actual indicator instance is relevant and nothing else. If you wanted to understand the sequence of events, then I suggest marking your indicator instances so that they would be unique.
on 2) Unfortunately there is no way to retrieve the instrument name on Initialize() since the actual instrument/series is assigned AFTER Initialize(). This was the case NT6.5 and nothing has changed since. Hope you'll feel better soon
Dierk
NinjaTrader Customer Service |
|
|
|
|
|
#9 |
|
Senior Member
Join Date: Jan 2009
Posts: 584
Thanks: 2
Thanked 21 times in 12 posts
|
OK,
finally used the Visual Studio Debugger on NT7, and what I need can be done inside the string ovverride ToString() function. Andreas |
|
|
|
|
|
#10 |
|
Senior Member
Join Date: Jan 2009
Location: Budapest, HUNGARY
Posts: 258
Thanks: 0
Thanked 0 times in 0 posts
|
Hello,
i dont understand everithing connected to this. In help: - This is what we want users to overload to dispose of their resources - Do not overload Dispose() any longer - Reason that dispose could be much later that you might expect - Any reference sample updates required In code: // Summary: // Overload this method to handle the termination of an indicator. Use this // method to dispose of any resources vs overloading the Dispose() method. 1) question: the code is about indicator. Is it right for the strategy as well? 2) question: i did not find any exact sample, how to use it corretly. Can you help me? Now, this in the strategy, how would that be in OnTermination() method? Code:
public override void Dispose()
{
try
{
// Disposes resources
if (MyClass1 = null)
{
MyClass1.PropertyChanged -= MyClass1 _PropertyChanged;
MyClass1.Dispose();
}
if (MyClass2 != null)
MyClass2.Dispose();
}
...
}
|
|
|
|
|
|
#11 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,164
Thanks: 6
Thanked 46 times in 32 posts
|
Same as for a strategy.
Just replace: public override void Dispose() with public override void OnTermination()
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#12 |
|
Senior Member
Join Date: Jan 2009
Location: Budapest, HUNGARY
Posts: 258
Thanks: 0
Thanked 0 times in 0 posts
|
|
|
|
|
|
|
#13 |
|
Senior Member
Join Date: Apr 2008
Posts: 298
Thanks: 4
Thanked 0 times in 0 posts
|
there is a problem with NT creating instances of custom classes and holding them for no apparent reason.
if I compile an indicator but dont add to a chart NT already has an instance. I have an indicator wich writes to a file. I create a stream in Initialize an close it on terminate. this doesnt work because once I compiled it NT has initialised the code and it will not release until the NT shut. a new instance on the chart cant use the same file name as it is locked. I had to do a dirty trick with random file names to avoid the problem. why do you do it? what is the purpose of idle indicator? seems as resources leak to me... I think same was in NT 6.5
Last edited by maxima; 01-25-2010 at 06:55 PM.
|
|
|
|
|
|
#14 |
|
Senior Member
Join Date: Apr 2008
Posts: 298
Thanks: 4
Thanked 0 times in 0 posts
|
P.S. a year ago it was promised that Ninja would resolve problem with releasing custom dlls as well..
same problem as with indicators. If you reference a custom dll and you are making changes, compile it - you cant copy it other as Ninja is always holding dll until completely shut (no mater if it used anywhere or not).... In NT7 beta is still not addressing this and I think will not. |
|
|
|
|
|
#15 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
>> there is a problem with NT creating instances of custom classes and holding them for no apparent reason.
Incorrect. Those instances are created so you can properly manage them on the UI before they e.g. get placed on chart.
Dierk
NinjaTrader Customer Service |
|
|
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| DataSeries input to indicator in strategy Initialize() routine | trader20 | Strategy Development | 2 | 07-16-2009 06:03 AM |
| Initialize | Laurent68 | General Programming | 2 | 04-07-2009 09:21 AM |
| Dispose of array | irurn | General Programming | 2 | 01-27-2009 06:01 AM |
| Strategy Dispose() | monpere | Strategy Development | 8 | 06-15-2008 05:33 AM |
| Failed to call method "Initialize" for indicator 'Test': Object reference not set to | clearpicks | Indicator Development | 3 | 04-23-2008 12:53 PM |