![]() |
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
|
|||||||
| Indicator Development Support for the development of custom indicators using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Nov 2007
Location: Arlington Heights, IL
Posts: 100
Thanks: 0
Thanked 4 times in 4 posts
|
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 |
|
|
|
|
|
#2 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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?
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
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.
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#4 |
|
Senior Member
Join Date: Nov 2007
Location: Arlington Heights, IL
Posts: 100
Thanks: 0
Thanked 4 times in 4 posts
|
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 |
|
|
|
|
The following user says thank you to GaryAlbers for this post: |
|
|
|
#5 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#6 |
|
Senior Member
Join Date: Nov 2011
Posts: 132
Thanks: 40
Thanked 2 times in 2 posts
|
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? |
|
|
|
|
|
#7 |
|
NinjaTrader Customer Service
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
|
Hello alex.nt,
I will leave the thread open for our forum member as this is beyond what we could support.
Joydeep M.
NinjaTrader Customer Service |
|
|
|
|
The following user says thank you to NinjaTrader_Joydeep for this post: |
|
|
|
#8 |
|
Senior Member
Join Date: Nov 2007
Location: Arlington Heights, IL
Posts: 100
Thanks: 0
Thanked 4 times in 4 posts
|
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 |
|
|
|
|
The following user says thank you to GaryAlbers for this post: |
|
|
|
#9 |
|
Senior Member
Join Date: Nov 2011
Posts: 132
Thanks: 40
Thanked 2 times in 2 posts
|
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. |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |