using MyMethods;
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
Creating User Defined methods
Collapse
X
-
Creating User Defined methods
I am reading the section regarding Partial Classes (Porting methods and properties from UserDefinedMethods.cs) at this link and I have some questions. In the Partial Class Usage example, shouldn't there be a using statement such as:
Code:Tags: None
-
Hello swcooke,
There would not be a need for a using statement for this case, the partial class will be part of the namespace/class you are working from. Partial classes are a C# concept, for further education on this topic I would suggest using external C# education materials surrounding partial classes.
The sample in the help guide would be specifically what the partial class looks like, what did you try that was not working?
If you are exporting this as a DLL, you need to include this inside of the export, however, if your overall plan is to share this between DLL's that would not be possible using a partial class.
A partial class cannot be used from a different type than where it was defined (indicator) or different assembly. Potentially this is where the problem in what you were trying comes from. The sample in the help guide is a complete Indicator sample which includes both the necessary code and instructions on where to define the file (addons folder). During the export, the scripts which use the partial class and the partial class itself would need to be exported, but as noted before the partial class cannot be a dll by its self, this is going to need to be exported in addition to the other scripts that use it.
I look forward to being of further assistance.JesseNinjaTrader Customer Service
-
Hello swcooke,
Did you put the partial class in the Addon folder or have you placed it in the Indicator folder? If you place it in the indicator folder, it will show up as an indicator. The help guide sample notes that this needs to be placed in the Addons folder, have you done this?
Partial classes are now built manually and saved in the C:\Users\<user>\Documents\NinjaTrader 8\bin\Custom\AddOns folder.
JesseNinjaTrader Customer Service
Comment
-
Yes, I did. Here is a screenshot:
Why is it suggested that these go into the AddOn folder but the example shows them namespaced like this:
Code:namespace NinjaTrader.NinjaScript.Indicators
Code:namespace NinjaTrader.NinjaScript.AddOns
Comment
-
Hello swcooke,
Thank you for your reply.
The namespace would be correct, this is part of how partial classes work. You would need the partial class inside of the addon folder and the class its self would be in the Indicators namespace so that the class can be part of the Indicator class which is also in the Indicators namespace.
I tried the sample we have in the help guide and exported it as a compiled assembly then imported it, however, I am not seeing the class show up as an indicator. Can you provide a sample of how you defined your partial class?
I look forward to being of further assistance.JesseNinjaTrader Customer Service
Comment
-
What is the preferred method for creating one? Do I click the plus icon on the Tabbed interface at the bottom and choose New Add On and let the Wizard do it and then edit the file? Or should I manually create the file outside of NT and drop it into the folder?
Comment
-
Hello swcooke,
You can use the addon wizard to generate the file, you would then need to remove the existing code and use the code from the help guide. The using statements at the top can be retained, you mainly need to remove the addon namespace and generated addon code from the file.
I look forward to being of further assistance.JesseNinjaTrader Customer Service
Comment
-
Hello swcooke,
I took a look at the video however this does not necessarily help in this case. I would still want to see a sample of the partial class that I can test. Could you export what you have created as source code so that I can try this on my end with identical code?
I look forward to being of further assistance.
JesseNinjaTrader Customer Service
Comment
-
-
Hello swcooke,
Thank you for your reply.
I can now see where the disconnect is, the help guide sample seems to be demonstrating how to define a named partial class which would not be specifically what you want to use here.
In this case, the class name is NpLicenseCheck and you are also defining this as inheriting from an Indicator which makes it an indicator. This will show up in the menu as it is currently defined. I will note this to development to see if this can be changed to a more standard partial class example.
In your use case, you would just want to make a partial indicator class or exactly what you see in NT7's UserDefinedMethods file (its just a C# partial class). Here is the NT8 help guide sample without the indicator name:
Code:namespace NinjaTrader.NinjaScript.Indicators { public partial class Indicator { //Sample method which calculates the delta of two prices public double CalculateDelta(double firstPrice, double secondPrice) { return Math.Abs(firstPrice - secondPrice); } //Sample method which prints Position information public void PrintPositionInfo(Position position) { Print(String.Format("{0}: {1} {2} at {3}", position.Instrument, position.Quantity, position.MarketPosition, position.AveragePrice)); } } }
Code:public partial class Indicator
I look forward to being of further assistance.
JesseNinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by strategist007, Today, 07:51 PM
|
0 responses
2 views
0 likes
|
Last Post Today, 07:51 PM | ||
Started by StockTrader88, 03-06-2021, 08:58 AM
|
44 responses
3,967 views
3 likes
|
Last Post
by jhudas88
Today, 06:59 PM
|
||
Started by rbeckmann05, Today, 06:48 PM
|
0 responses
4 views
0 likes
|
Last Post
by rbeckmann05
Today, 06:48 PM
|
||
Started by rhyminkevin, Today, 04:58 PM
|
4 responses
58 views
0 likes
|
Last Post
by dp8282
Today, 06:13 PM
|
||
Started by iceman2018, Today, 05:07 PM
|
0 responses
6 views
0 likes
|
Last Post
by iceman2018
Today, 05:07 PM
|
Comment