NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Indicator Development

Indicator Development Support for the development of custom indicators using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 05-18-2008, 02:12 PM   #1
GaryAlbers
Senior Member
 
Join Date: Nov 2007
Location: Arlington Heights, IL
Posts: 100
Thanks: 0
Thanked 4 times in 4 posts
Default Indicator inheritance and Ninja code generation question

A couple questions about inheritance and ninja's code generation. A little
back ground first:

I have 1 indicator that I am splitting into 2 different visual representations. The 2 new indicators will share the same core calculations and parameters. Each new indicator will also have some additional parameters.

I had no problem creating the base indicator with all of it's parameters.
I then created the new indicator that extends the new base indicator and
added the parameters to the new indicator unique to it's visual presentation.

Both indicators compile correctly and when I place the new indicator, (that extends the new base indicator), on a chart it also draws correctly and all the parameters show up correctly in the property panel.

However, when I created a strategy that used the new indicator, the
strategy had a compiler error which was a complaint about the number of parms required to construct the indicator.
Upon deeper inspection into the code generated by ninja, I noticed that
the construction of the new indicator only took in the parameters defined in that extended class. It did not take into account the inherited parameters of it's base class.

This seemed strange because when the indicator is on a chart, the
property panel properly shows all the parameters, even the inherited ones.

I also noticed that if I put the parameter code in the extending class, BUT COMMENTED OUT, then ninja recognizes them and generates the constructor correctly.

Can ninja's code generator be made to look up the inheritance chain for all parameters?
Shouldn't ninja ignore commented out code?
Is there something more I have to code in the extending class to make
ninja's code generation notice the inherited parameters?

Thanks,
Gary
GaryAlbers is offline  
Reply With Quote
Old 05-18-2008, 03:33 PM   #2
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

Gary,

I am unaware of how you are exactly coding this, but wouldn't it just be easier to expose properties that you want to access on your base indicator and call them from your addon indicator?
NinjaTrader_Josh is offline  
Reply With Quote
Old 05-18-2008, 04:39 PM   #3
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

I suggest not creating a new indicator based on inheritenace from our own class. Not sure if this would work or not but for sure we will not support this if it does not.
NinjaTrader_Ray is offline  
Reply With Quote
Old 05-18-2008, 07:18 PM   #4
GaryAlbers
Senior Member
 
Join Date: Nov 2007
Location: Arlington Heights, IL
Posts: 100
Thanks: 0
Thanked 4 times in 4 posts
Default Need more info...

Thanks Josh and Ray for responding, but I need more info.

1) Ray, are you saying I should not code any indicators or strategies
using inheritance?

2) Josh, I do have properties exposed in base indicator and are using
them in extending indicator. The 2 indicators only share their base calculations but they plot totally different. One indicator has 24 plots,
the other has 5 different plots. Creating a base indicator and extending
it 2 different ways seemed like the best way to do it.

3) Is there any documentation describing ninja's code generation (what
it looks at, what are the pieces it generates, how are each of the methods
intended to be used)?

4) Why would the code generation process use commented out property
code when creating the indicator creation code?

BTW, the indicators are working, in that I have 2 separate classes
extending a base class. They each plot differently.
However, the main irritation is the hack I had to use to get the
extending indicator to properly get it's code generated so a strategy
could call it. (I have a bunch of property accessors coded in the base
class and I had to also code them again, but they are commented out,
in the child class in order to get the right generated code.)

Regards,
Gary
GaryAlbers is offline  
Reply With Quote
The following user says thank you to GaryAlbers for this post:
Old 05-18-2008, 10:48 PM   #5
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

3 & 4) Sorry Gary. There is no documentation on the method you are approaching it with. Unfortunately like Ray said, this is beyond the level of support we can offer.
NinjaTrader_Josh is offline  
Reply With Quote
Old 01-23-2013, 05:41 AM   #6
alex.nt
Senior Member
 
Join Date: Nov 2011
Posts: 132
Thanks: 40
Thanked 2 times in 2 posts
Default

It seems that the same issue persists in 2013, i.e. it is not possible to re-use properties defined in the base class in descendant classes because NT cannot properly generate auto-generated methods for the indicator then.

The hack Gary described would obviously overwritten any time indicator is compiled, so while it works, it is irritating indeed

I also tried to use virtual properties but it appears that NT code generator takes 2 first words from property definition so it results with "override bool" or the like instead of "bool ParamA" in constructor, which ruins all the thing.

Anyone could suggest the best practice for indicator inheritance then? Should it be used at all while developing indicators?
alex.nt is offline  
Reply With Quote
Old 01-23-2013, 06:01 AM   #7
NinjaTrader_Joydeep
NinjaTrader Customer Service
 
NinjaTrader_Joydeep's Avatar
 
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
Default

Hello alex.nt,
I will leave the thread open for our forum member as this is beyond what we could support.
NinjaTrader_Joydeep is offline  
Reply With Quote
The following user says thank you to NinjaTrader_Joydeep for this post:
Old 01-23-2013, 09:08 AM   #8
GaryAlbers
Senior Member
 
Join Date: Nov 2007
Location: Arlington Heights, IL
Posts: 100
Thanks: 0
Thanked 4 times in 4 posts
Default

alex.nt,

Inheritance does work, you just have to live with the code generation quirk.
You will have to decide for yourself if you want to use inheritance since it is 'not supported'.

I have settled on a combination of using inheritance, 'partial' class definitions and a utility classes in a name space that I include with a using statement.

Gary
GaryAlbers is offline  
Reply With Quote
The following user says thank you to GaryAlbers for this post:
Old 01-23-2013, 02:51 PM   #9
alex.nt
Senior Member
 
Join Date: Nov 2011
Posts: 132
Thanks: 40
Thanked 2 times in 2 posts
Default

Of course the inheritance does work but I wonder how to avoid re-implementing the properties in the descendant indicators without your hack as this is the [only] problem with indicator inheritance. It would be great if someone knew a workaround and shared their knowledge.

Perhaps, this can be added to wish list for next NT version.
alex.nt is offline  
Reply With Quote
Reply

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
Convert TradeStation code to Ninja Razor_Trader General Programming 2 07-25-2008 12:45 AM
duplicating code question z32000 General Programming 7 11-29-2007 11:53 AM
Indicator Question For ninja t Ray prostyle NinjaScript File Sharing Discussion 1 09-19-2007 02:03 PM
code script question abikambic General Programming 8 06-19-2007 07:23 AM
code question abikambic General Programming 2 05-03-2007 06:03 AM


All times are GMT -6. The time now is 10:32 AM.