![]() |
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
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Member
Join Date: Mar 2008
Posts: 78
Thanks: 0
Thanked 0 times in 0 posts
|
Hey gurus,
As I develop some strategies, I'm accumulating a growing collection of methods that I would like to share with all of my strategies. I wonder if someone can help with ways of doing this without cut-and-paste... Can I use polymorphism, so something like: public class MySubStrategy : MyParentStrategy where I provide default implementations of OnBarUpdate or OnPositionUpdate? Is there some way of templating so that the OnPositionUpdate comes from one source and OnBarUpdate comes from another? I can create helper methods of course, as long as I pass all necessary properties but it's messy. And is there some good location to stuff all of the other helper methods and utilities I create? Right now I have a sort of dummy Indicator. It doesn't do anything indicator-esqe, but it's the only way I've found to create a new class which can be instantiated and referenced in Strategies. Feels like a hack. Is there any better way? |
|
|
|
|
|
#2 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
>> public class MySubStrategy : MyParentStrategy
We have not tried that and this would be beyond what we provide support for. You would need to try by yourself.
Dierk
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Feb 2008
Location: Paris
Posts: 713
Thanks: 10
Thanked 10 times in 7 posts
|
Can you suggest another method of sharing code between strategies? I'm having the same issue.
|
|
|
|
|
|
#4 |
|
Certified NinjaScript Consultant
Join Date: Sep 2006
Location: New York, USA
Posts: 774
Thanks: 1
Thanked 7 times in 5 posts
|
Since NT strategies / indicators / functions are all "partial" classes, they all compile to one project. So, you can basically create an empty indicator, make it a "partial" class, and write "public" functions.
I have attached the framework with some comments to help. I hope this is helpful
"You look closely enough, you can find everything has a ... weak spot where it can break, sooner or later"
PureLogikTrading |
|
|
|
|
|
#5 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
Our UserDefinedMethods is a partial class that does just this as well although mrlogik approach might work better since if you export your custom scripts, this global indicator will be included in the export file were the UserDefinedMethods will not.
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#6 |
|
Certified NinjaScript Consultant
Join Date: Sep 2006
Location: New York, USA
Posts: 774
Thanks: 1
Thanked 7 times in 5 posts
|
Hey Ray,
Thanks, i forgot to mention that. This is the reason I created my own indicator / class to do it; I export to a few computers for trading whenever I create something.
"You look closely enough, you can find everything has a ... weak spot where it can break, sooner or later"
PureLogikTrading |
|
|
|
|
|
#7 |
|
Junior Member
Join Date: Feb 2008
Posts: 8
Thanks: 0
Thanked 0 times in 0 posts
|
Thanks mrlogik,
I tried your GV module and it works great for public functions but do I have to create a public static variable to access the global variable examples in your file? or is there another way to use them? |
|
|
|
|
|
#8 |
|
Certified NinjaScript Consultant
Join Date: Sep 2006
Location: New York, USA
Posts: 774
Thanks: 1
Thanked 7 times in 5 posts
|
You have ot make a public static variable within the Gv global indicator.
For example, with the code I gave you. Code:
public static BData gBData; Make sure you don't run into any race conditions with reading / writing out of sequence, or writing from multiple indicators at the same time.
"You look closely enough, you can find everything has a ... weak spot where it can break, sooner or later"
PureLogikTrading |
|
|
|
|
|
#9 |
|
Junior Member
Join Date: Nov 2008
Posts: 11
Thanks: 0
Thanked 0 times in 0 posts
|
I know this is an old thread but it seems very useful. However I seem to be missing something very simple. After defining global functions in the GV indicator, the functions do not seem to be available, including the original GetDateFunction. Intellisense isn't picking it up and there is a "not found" error from the compiler.
What am I missing? Using Ninjatrader 6.5.1000.8 Thanks! |
|
|
|
|
|
#10 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
You will need to fix the error before you will see anything. Unfortunately this is outside the scope we can offer support for. Maybe a forum member familiar with what is being requested could help you out.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#11 |
|
Junior Member
Join Date: Nov 2008
Posts: 11
Thanks: 0
Thanked 0 times in 0 posts
|
That was fast!
Oh sorry, I wasn't clear. If I try typing the global function, it doesn't show in intellisense. But if I do go ahead and type it manually anyway, the compiler isn't able to locate the method. Is there anything special I have to add, say in the Using section? For example, I can't just do GetDateFunction(...). Of course, GV.GetDateFunction doesn't work either. How would I call that one from my strategy? Thanks! |
|
|
|
|
|
#12 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
As mentioned, this is outside the scope of what we can support. I have no idea what this "GV" thing you refer to is.
Likely you need to do GV().GetDateFunction. Not sure. You may want to contact whoever's code you are duplicating to try and get help.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#13 |
|
Junior Member
Join Date: Nov 2008
Posts: 11
Thanks: 0
Thanked 0 times in 0 posts
|
The GV is in the GlobalShare.zip file above where the example is provided. I'll see if mrlogik can be of assistance though. But thanks for writing. The compiler doesn't complain so that's a step in the right direction. I'll start testing it out now. Thank you!
When writing partials like this, is there a way to refresh the intellisense cache?
Last edited by michaelangela; 02-04-2009 at 04:19 PM.
Reason: new to C# and still learning!
|
|
|
|
|
|
#14 |
|
Senior Member
Join Date: Feb 2008
Location: Paris
Posts: 713
Thanks: 10
Thanked 10 times in 7 posts
|
Here is what I did: I created a class to facilitate the use of these Global Variable methods. I'm attaching it to this post.
BTW I'm not sure if you're trying to coordinate between two strategies or two different applications. If two strategies, you don't need GV. You can just use a static variable. The GV is useful for having two different processes communicate, like Ninjatrader and Tradestation for example. |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Organization of Indicators.............. | redrum28 | Miscellaneous Support | 1 | 02-27-2008 06:55 AM |
| Standard Return Code for Functions | arbifox | Automated Trading | 1 | 12-13-2007 08:21 PM |
| renaming functions | z32000 | General Programming | 3 | 12-03-2007 10:47 AM |
| Code->test/debug->change code->retest ... cycle process | bbarroux | Strategy Development | 3 | 10-02-2007 12:44 PM |
| Unrealized PnL for ATI Functions | whitmark | Automated Trading | 1 | 09-19-2007 03:47 PM |