View Full Version : Should new classes derive from Strategy?
jbeninga
03-22-2007, 07:45 AM
Hello,
I'm tryingto intoduce some additional C# class structure into my strategy.
It appears that BarsArray[] and Times[] are protected members of StrategyBase? So any class that does not derive from StrategyBase can not access them. Or are they public?
So my question is:Should "helper" classes also derive from Strategy in order to have access to BarsArray[] and Times[]? Is it OK to instantiate a Strategy within a Strategy, or will bad things happen?
What I'm trying to do with my code base is refactor it to make use of the State design pattern from Gamma, Helm et al. This willentailthe creation of many additional classes into the script which will all require access to BarsArray[] and Times[]
Any thoughts? Am I missing something?
Thanks,
Jim
NinjaTrader_Ray
03-22-2007, 10:18 AM
Hi Jim,
Unfortunately we are not in a position to support anything outside of what is currently documented in the Help Guide. Emedding strategies within strategies is for sure outside this scope. I highly suggest not to do this since you could run into issues even if you tried. This level of programming crosses the border into our our overall framework. The intention is over time to expose more of the under the hood capabilities.
Thanks for your understanding on this.
Ray
jbeninga
03-22-2007, 11:05 AM
Ok, I was kinda afraid that was gonna be the answer.... And yes I understand, I've done enterprise class software for many years.
So, if I'm gonna port my 250KLOC EasyLanguage codebase over. It needs to go into a single class if the code is gonna touch BarsArray or Time. But if the code has no need to access BarsArray or Time I'm free to create additional classes as long as they are nested withinthe singlederived Strategy class. Is that correct?
Best Regards,
Jim
NinjaTrader_Ray
03-22-2007, 11:10 AM
FYI: Most if not all class that implement IDataSeries such as Time, price series etc... must only be accessed from within the context of the OnBarUpdate() method.
Yes you can nest additional classes within the base strategy class, no issues there all, standard C# programming is your guideline.
Ray
jbeninga
03-22-2007, 11:35 AM
Great. Got it. Thanks for the help.
And one more thing as long as I have your attention... You really need a File->SaveAs and File->Read in the NinjaScript editor for script version control purposes.
;)
Jim
jbeninga
03-22-2007, 03:29 PM
Well, spent the remainder of the afternoon and evening playing with some high level class structure to try and bring together a design approach for my system port.
I *do* understand why y'all want to keep those two class members as protected. Especially in Beta. But, IMO,it does have the side-effect of turning what could bea *really* elegant solution upside down.
I'm more of aC++ guy then C#. (still searching for that "friend class" definition in C#)But, if there is a way to keep those two class members as externally namespace private, but internally namespace public, then it seems to me that responsibility for "being a good citizen" is on the shoulders of the strategy developer (who should be a NinjaTrader friend ;))and you all don't have to worry about somebody loading a rouge dll.
I do not want to come across as railing against you. I realy think NinjaTrader is on to something here. It's just when I see something that is sooooooo close to solvingmany ofthe problems I've been dealing with on TradeStation with bubblegum and baling twine-I get a little excited.
FWIW - my two cents.
Jim
maskiepop
12-20-2007, 03:51 AM
FYI: Most if not all class that implement IDataSeries such as Time, price series etc... must only be accessed from within the context of the OnBarUpdate() method.
Yes you can nest additional classes within the base strategy class, no issues there all, standard C# programming is your guideline.
Ray
Hi Ray,
I have been looking for some guidelines on how to build nested classes inside a strategy. This thread is just about the only one I found which touches on it.
But not being much of a C# proggie, I will need you to explain the points discussed in this thread a bit more :
I can build nested classes in strategies, but theses classes should not be derived from NT's strategy class? Is that right? Is that what you meant by a strategy within a strategy?
The Dataseries classes used in the Strategy class are completely off limits? Any others? The MarketPositions? Methods? i.e GetProfitLoss(), the various Order entries (EnterLong(), etc.)
I noticed that if I derived a class from Strategy, the code compiles, but fails during execution. It complains about not having a constructor, or a badly formed one. Are there specific guidelines about constructors in classes nested in strategies?Cheers
NinjaTrader_Dierk
12-20-2007, 05:14 AM
Unfortunately we are unable to provide support any other strategy model than the one generated by the strategy wizard.
May be the community can contribute?!?
Pete S
12-20-2007, 08:04 AM
Hi Ray,
I have been looking for some guidelines on how to build nested classes inside a strategy. This thread is just about the only one I found which touches on it.
But not being much of a C# proggie, I will need you to explain the points discussed in this thread a bit more :
I can build nested classes in strategies, but theses classes should not be derived from NT's strategy class? Is that right? Is that what you meant by a strategy within a strategy?
The Dataseries classes used in the Strategy class are completely off limits? Any others? The MarketPositions? Methods? i.e GetProfitLoss(), the various Order entries (EnterLong(), etc.)
I noticed that if I derived a class from Strategy, the code compiles, but fails during execution. It complains about not having a constructor, or a badly formed one. Are there specific guidelines about constructors in classes nested in strategies?Cheers
What exactly are you trying to do? Run multiple logical strategies in one NT strategy instance?