Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Partial Class does not work!
Collapse
X
-
Hello stevenev,
The Position is not part of the Indicators namespace.
To use Position, this code would need to be in the Strategies namespace.
Attached is an example of how this code would be used between namespaces.
Also, print cannot be used in a static method.
Instead the NinjaTrader.Code.Output.Process(string message, PrintTo output tab); would be used.
Example in post # 6.Last edited by NinjaTrader_ChelseaB; 01-24-2023, 10:51 AM.Chelsea B.NinjaTrader Customer Service
-
Hi Chelsea, your code is working great. I can call a method in the AddOns > MySharedMethods from my main strategy script.
NOW, can you please help me with the reverse. In the AddOns > MySharedMethods, I need to use:
High
EMA
for example in the MySharedMethods, I would have:
public static double Range( int BarsAgo )
{
return High[BarsAgo] - Low[BarsAgo]; // but this does not work
}
public static EMA_val( int span, int BarsAgo )
{
return EMA(span)[BarsAgo];
}
How would I access them. I believe there is namespace prefix to be used, I just don't know how. Please help.
Thanks!
steveLast edited by stevenev; 01-04-2016, 07:54 PM.
Comment
-
Hello Steve,
An addon is not applied to a chart the way an indicator or a strategy is applied to the chart. Because of this there is not an automatic creation of any bar data the way there is in an indicator that has been added to a chart.
You would need to request bar data from the addon. You can also subscribe to bar updates and market data updates from an indicator.
BarRequest - http://ninjatrader.com/support/helpG...arsrequest.htm
MarketData - http://ninjatrader.com/support/helpG...marketdata.htmChelsea B.NinjaTrader Customer Service
Comment
-
Hi Chelsea,
In NT7, I put all my 'helper' functions in 'UserDefinedMethods' script and everything works. I have access to bar open/close/etc and indicators.
In NT8, from the solution provided, doing the same thing is extremely complex - actually the c# part is hard for me.
I am assuming any NT programmer would have a need for an easy way to replace methods they had in UserDefinedMethods. What is the solution.
Thanks, steve
Comment
-
Hello steve,
With NinjaTrader 7, the High, Close, Open, etc series are not available to the UserDefinedMethods.cs file either. A screenshot is attached to demonstrate what happens.
Are you passing these dataseries to your method?
If so, you can do the same in NT8.
I've modified the indicator script for to demonstrate passing in a dataseries and doing a calculation.
I've modified the addon script because i realized that adding classes that extend the Indicator class or Strategy class will cause those classes to appear in the Indicator / Strategy windows.
To hide these from the window, instead of an extended partial class, its a partial class of Indicator (without extending it). Then I put a nested class called MySharedMethods within this for organization reasons, however, this is optional. (I've left a method outside of that inner class so we can we how to use a method directly without a nested container class).
As a heads up, static classes and methods are outside of what is supported by NinjaTrader Support and is not documented in the NinjaTrader 8 Help Guide.
MySharedMethodsAddonExample.zip
Last edited by NinjaTrader_ChelseaB; 01-24-2023, 10:52 AM.Chelsea B.NinjaTrader Customer Service
- Likes 1
Comment
-
Hi Chelsea,
In NT7, it actually works. With the code provided above, I think STATIC is the problem, as that requires objects instantiation. Also the namespace in UserDefinedMethods is the same as for strategies, making things simple (you can tell I am not a c#'ian...).
Here is my code snippet in UserDefinedMethods. I just call it in my strategies with fGreen(0) and that is all I have to do
I looked at your code and it works great. But when using "static" the code has to pass ISeries all the time, gets repetitive when one has to call multiple methods in the helper. If you don't make the methods static, because it is in the same namespace, would it not be available just the same way I am calling it?
---------------------------------
// my UserDefinedMethods
namespace NinjaTrader.Strategy
{
/// <summary>
/// This file holds all user defined strategy methods.
/// </summary>
partial class Strategy
{
//---------------------------
public bool fGreen( int BarsBack )
{
return Close[BarsBack] > Open[BarsBack];
}
.....Last edited by stevenev; 01-07-2016, 10:43 AM.
Comment
-
Hi stevenv,
Yes, you are correct it is the static modifier that prevents the internal data series from an instance of indicator or strategy from being shared.
The same is true of NT8.
The choice of making these static is up to you, however, keep in mind the following note from the help guide:
Note: Methods within partial classes should be use the "public" and "static" modifiers, to allow for any other classes to invoke the methods without requiring an instance of the partial class.
http://ninjatrader.com/support/helpG...ng_changes.htmChelsea B.NinjaTrader Customer Service
Comment
-
Shared Partial Class across Strategies and Indicators
Hi Chelsea,
I've been reading this thread with great interest. I am seeking to implement some methods that are meant to be shared across the Strategy and Indicator space. For instance a simple debug print statement like the following...
Code:public void P(string msg, int minLvl = 1){ string intro = DateTime.Now.ToLongTimeString() + " - Bar: " + Time[0].ToShortDateString() + " " + Time[0].ToLongTimeString() + " (" + CurrentBar.ToString() + "): "; Print(intro + "OHLC: " + Open[0] + "/" + High[0] + "/" + Low[0] + "/" + Close[0] + " - " + msg); }
P("Test Message");
Is there any way to achieve this? (i.e. truly SHARED methods)
Cheers
Frank
Comment
-
Hello Frank,
To access this from any script the method would need to be added to the NinjaTrader.NinjaScript namespace which may be difficult to acheive.
Instead the best way would be to use the fully qualified name. In the example in post #6 I've done exactly this with theCode:NinjaTrader.NinjaScript.AddOns.MySharedMethods.SharedDouble
Last edited by NinjaTrader_ChelseaB; 07-11-2016, 08:16 AM.Chelsea B.NinjaTrader Customer Service
- Likes 1
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Touch-Ups, Today, 10:36 AM
|
0 responses
1 view
0 likes
|
Last Post
by Touch-Ups
Today, 10:36 AM
|
||
Started by geddyisodin, 04-25-2024, 05:20 AM
|
8 responses
61 views
0 likes
|
Last Post Yesterday, 10:45 AM | ||
Started by jxs_xrj, 01-12-2020, 09:49 AM
|
4 responses
3,289 views
1 like
|
Last Post
by jgualdronc
Today, 10:02 AM
|
||
Can someone turn this thinkscript into a ninjascript. 5PM CST OHL and Previous Day
by Option Whisperer
Started by Option Whisperer, Today, 09:55 AM
|
0 responses
5 views
0 likes
|
Last Post Today, 09:55 AM | ||
Started by halgo_boulder, 04-20-2024, 08:44 AM
|
2 responses
22 views
0 likes
|
Last Post Today, 09:41 AM |
Comment