NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > Application Technical Support > Miscellaneous Support > Historical Version 7 Beta Threads > Version 7 Beta General Questions & Bug Reports

Version 7 Beta General Questions & Bug Reports Ask questions here and post bug reports.

 
 
Thread Tools Display Modes
Old 10-12-2009, 07:31 AM   #1
zweistein
Senior Member
 
Join Date: Jan 2009
Posts: 584
Thanks: 2
Thanked 21 times in 12 posts
Default Indicator Initialize - Dispose

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
zweistein is offline  
Old 10-12-2009, 08:04 AM   #2
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,164
Thanks: 6
Thanked 46 times in 32 posts
Default

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
}
NinjaTrader_Ray is offline  
Old 10-12-2009, 08:13 AM   #3
zweistein
Senior Member
 
Join Date: Jan 2009
Posts: 584
Thanks: 2
Thanked 21 times in 12 posts
Default

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
zweistein is offline  
Old 10-12-2009, 08:18 AM   #4
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

Right it's not needed. OnTermination only would hold your "custom cleanup" code.
NinjaTrader_Dierk is offline  
Old 10-12-2009, 09:33 AM   #5
zweistein
Senior Member
 
Join Date: Jan 2009
Posts: 584
Thanks: 2
Thanked 21 times in 12 posts
Default

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
zweistein is offline  
Old 10-12-2009, 09:35 AM   #6
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

What exact issue do you see?
NinjaTrader_Dierk is offline  
Old 10-12-2009, 10:07 AM   #7
zweistein
Senior Member
 
Join Date: Jan 2009
Posts: 584
Thanks: 2
Thanked 21 times in 12 posts
Default

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.
zweistein is offline  
Old 10-12-2009, 11:03 AM   #8
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

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
NinjaTrader_Dierk is offline  
Old 10-12-2009, 04:05 PM   #9
zweistein
Senior Member
 
Join Date: Jan 2009
Posts: 584
Thanks: 2
Thanked 21 times in 12 posts
Default

OK,

finally used the Visual Studio Debugger on NT7, and what I need can be done inside the

string ovverride ToString()

function.

Andreas
zweistein is offline  
Old 01-23-2010, 09:06 AM   #10
tamas
Senior Member
 
Join Date: Jan 2009
Location: Budapest, HUNGARY
Posts: 258
Thanks: 0
Thanked 0 times in 0 posts
Default OnTermination()

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();
  }
  ...
}
Thanks in advance, Tamas
tamas is offline  
Old 01-23-2010, 01:43 PM   #11
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,164
Thanks: 6
Thanked 46 times in 32 posts
Default

Same as for a strategy.

Just replace:

public override void Dispose()

with

public override void OnTermination()
NinjaTrader_Ray is offline  
Old 01-24-2010, 03:38 AM   #12
tamas
Senior Member
 
Join Date: Jan 2009
Location: Budapest, HUNGARY
Posts: 258
Thanks: 0
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by NinjaTrader_Ray View Post
Just replace:
Ohhh thank you Ray
tamas is offline  
Old 01-25-2010, 06:51 PM   #13
maxima
Senior Member
 
Join Date: Apr 2008
Posts: 298
Thanks: 4
Thanked 0 times in 0 posts
Default

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.
maxima is offline  
Old 01-25-2010, 09:48 PM   #14
maxima
Senior Member
 
Join Date: Apr 2008
Posts: 298
Thanks: 4
Thanked 0 times in 0 posts
Default

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.
maxima is offline  
Old 01-26-2010, 06:05 AM   #15
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

>> 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.
NinjaTrader_Dierk is offline  
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

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


All times are GMT -6. The time now is 01:37 AM.