Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
What is the usual way of creating libraries of my own classes to use in NinjaScript?
Collapse
X
-
What is the usual way of creating libraries of my own classes to use in NinjaScript?
it appears that I cannot create a new folder in the Ninja Explorer tree view. I can only create directories in the existing ones. Therefore, my thought is to create a "Library" directory in "Strategies". However, when I right-click in "Library", the only option for a new file is "New Strategy". This makes me think that any code that is not a Strategy does not belong here. Where should I put my own custom classes? Is this "forbidden" in NinjaScript?Tags: None
-
Hello stokhastic,
Thank you for your note.
You could change the namespace so that those strategies will appear in a folder.
For example change the namespace of the strategy from,
Code:namespace NinjaTrader.NinjaScript.Strategies
Code:namespace NinjaTrader.NinjaScript.Strategies.AlanStrategies
You could import the attached strategy which demonstrates.
Please let us know if you need further assistance.
Attached FilesAlan P.NinjaTrader Customer Service
-
NinjaTrader_AlanP what if we need a common class that is used in multiple places (like an Indicator, SuperDOM column, MarketColumn, etc)?
I tried creating an extra folder in NinjaTrader8/bin/Custom and it works fine for local compilation, but I can't export it. The extra folder is also not visible in the NT Editor.Last edited by Zombie; 01-22-2021, 12:44 PM.
Comment
-
Hello Zombie, thanks for your reply.
You can define a Strategy or Indicator partial class and implement your shared methods and properties within the partial class definition. We have a set of examples of how to do this attached to this post. When you need to make a new folder within the Bin/Custom file system, create the folder by right-clicking a folder in the NinjaScript Editor, do not make the folder from the Windows file explorer. If the methods or properties need to be used by many different namespaces, you can add a static class to the NinjaTrader.NinjaScript.AddOns namespace.
Please let me know if I can assist any further.Attached FilesChris L.NinjaTrader Customer Service
Comment
-
NinjaTrader_ChrisL thanks for the example. Another question: what is the recommended/usual way to protect the shared code?
My specific example would be a class that is used by an indicator / market analyzer column / superDOM column and let's assume they are all different products. How can we protect this shared class such that only licensed users are able to use it?
If we don't protect the class with the VendorLicense call in the constructor, I am assuming that after the installation this class would be available to anyone. On the other hand, if we protect it with its own product, then we start to create dependencies among products which is tougher to manage. In particular, if free trials are offered, it is possible that the free trial on the shared class may be expired when the product one is not. It can get messy pretty quickly.
Is there any magical solution with partial class that we can use?
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by jaybedreamin, Today, 05:56 PM
|
0 responses
7 views
0 likes
|
Last Post
by jaybedreamin
Today, 05:56 PM
|
||
Started by DJ888, 04-16-2024, 06:09 PM
|
6 responses
18 views
0 likes
|
Last Post
by DJ888
Today, 05:12 PM
|
||
Started by Jon17, Today, 04:33 PM
|
0 responses
4 views
0 likes
|
Last Post
by Jon17
Today, 04:33 PM
|
||
Started by Javierw.ok, Today, 04:12 PM
|
0 responses
12 views
0 likes
|
Last Post
by Javierw.ok
Today, 04:12 PM
|
||
Started by timmbbo, Today, 08:59 AM
|
2 responses
13 views
0 likes
|
Last Post
by bltdavid
Today, 04:10 PM
|
Comment