Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Common variable between an indicator and a strategy?
Collapse
X
-
Common variable between an indicator and a strategy?
Is it possible to establish a shared variable [a static counter], to be used when running a strategy analysis, for tracing the logic flow as it progresses back and forth between an indicator and a strategy?Tags: None
-
Originally posted by joemiller View PostIs it possible to establish a shared variable [a static counter], to be used when running a strategy analysis, for tracing the logic flow as it progresses back and forth between an indicator and a strategy?
-
Originally posted by joemiller View PostIs it possible to establish a shared variable [a static counter], to be used when running a strategy analysis, for tracing the logic flow as it progresses back and forth between an indicator and a strategy?
Just like the often derided goto statement, there are times when using static variables borders on inevitable, but generally, they are just a PITA.
If you are calling the indicator from the strategy, then it should be possible to use a class variable to store states.
Comment
-
reply to Sledge and Koganam
1)
when I put the indicator and the strategy in my UserDefinedMethods files,
which presently are as shown below, will I then be able to have then share a common value?
2)
Re: “If you are calling the indicator from the strategy, then it should be possible to use a class variable to store states” …. please forgive me, much appreciated but I have no idea what you are trying to tell me.
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
/// <summary>
/// This file holds all user defined strategy methods.
/// </summary>
partial class Strategy
{
}
}
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
/// <summary>
/// This file holds all user defined indicator methods.
/// </summary>
partial class Indicator
{
}
}
Comment
-
Hello joemiller,
Thank you for your post.
Sledge is correct to use the User Defined Methods. However, you can not share user defined methods created for custom strategies with custom indicators.
There is one UserDefinedMethods.cs file that contain your user defined methods for custom strategies found under Tools > Edit NinjaScript > Strategy.
There is one UserDefinedMethods.cs file that contain your user defined methods for custom indicators found under Tools > Edit NinjaScript > Indicator.
Please let me know if I may be of further assistance.
Comment
-
Originally posted by koganam View PostYou do not really want to use static variables. Even seasoned programmers try to avoid them: there are just too many gotchas.
Just like the often derided goto statement, there are times when using static variables borders on inevitable, but generally, they are just a PITA.
If you are calling the indicator from the strategy, then it should be possible to use a class variable to store states.
Comment
-
thank you Patrick,
1) does that mean I should forget altogether about UserDefinedMethods files? I suspect obviously not, otherwise why would UserDefinedMethods files ever have entered this dialogue?
2) so my understanding now is that I can make variables global between indicators and strategies by integrating the use of UserDefinedMethods files with "writing items outside the namespace". my problem is I don't have the foggiest idea of what that means or what to do to make it happen".
if the following request is reasonable ...please just simply do me a great service and give me a short list of a few explicit steps to take from here. I really sincerely appreciate explanations from everyone of why things work or not, but I just don't understand the significance of most of what is explained and therefore cannot make any use of what is presented. after nine posts now I am still dead in the water.
Comment
-
Originally posted by joemiller View Postthank you Patrick,
1) does that mean I should forget altogether about UserDefinedMethods files? I suspect obviously not, otherwise why would UserDefinedMethods files ever have entered this dialogue?
2) so my understanding now is that I can make variables global between indicators and strategies by integrating the use of UserDefinedMethods files with "writing items outside the namespace". my problem is I don't have the foggiest idea of what that means or what to do to make it happen".
if the following request is reasonable ...please just simply do me a great service and give me a short list of a few explicit steps to take from here. I really sincerely appreciate explanations from everyone of why things work or not, but I just don't understand the significance of most of what is explained and therefore cannot make any use of what is presented. after nine posts now I am still dead in the water.
Comment
-
Post #1 said “Is it possible to establish a shared variable [a static counter], to be used when running a strategy analysis, for tracing the logic flow as it progresses back and forth between an indicator and a strategy?”
I created the strategy which uses the indicator. Then I ran the strategy analyzer to test the strategy, and in so doing the indicator was involved so I then wanted to share a common variable between the indicator and the strategy. it seemed a simple enough concept to inquire about at the time. the optimum course for me is now to hang it up and move on. Many thanks to all for your help … I sincerely mean that.
Comment
-
Originally posted by NinjaTrader_PatrickH View PostHello joemiller,
Thank you for your post.
Sledge is correct to use the User Defined Methods. However, you can not share user defined methods created for custom strategies with custom indicators.
There is one UserDefinedMethods.cs file that contain your user defined methods for custom strategies found under Tools > Edit NinjaScript > Strategy.
There is one UserDefinedMethods.cs file that contain your user defined methods for custom indicators found under Tools > Edit NinjaScript > Indicator.
Please let me know if I may be of further assistance.
You can create user defined methods (global methods or functions) that can be accessed by all custom indicators and strategies. User defined methods should ONLY be created if you intend to re-use these methods over and over again across different custom indicators or strategies. Otherwise, just code your method logic directly into your indicator or strategy.
Last edited by sledge; 10-28-2013, 05:02 PM.
Comment
-
Originally posted by joemiller View PostPost #1 said “Is it possible to establish a shared variable [a static counter], to be used when running a strategy analysis, for tracing the logic flow as it progresses back and forth between an indicator and a strategy?”
I created the strategy which uses the indicator. Then I ran the strategy analyzer to test the strategy, and in so doing the indicator was involved so I then wanted to share a common variable between the indicator and the strategy. it seemed a simple enough concept to inquire about at the time. the optimum course for me is now to hang it up and move on. Many thanks to all for your help … I sincerely mean that.
Yes it is possible. make the static variable public.
Comment
-
to be clear, when I make the variable public in the indicator and strategy it doesn't result in the variable becoming one common shared value ... which of course is how I got started on this in the first place.
should I move or copy the indicator and the strategy to their respective UserDefinedMethods.cs files?
Comment
-
Originally posted by joemiller View PostPost #1 said “Is it possible to establish a shared variable [a static counter], to be used when running a strategy analysis, for tracing the logic flow as it progresses back and forth between an indicator and a strategy?”
I created the strategy which uses the indicator. Then I ran the strategy analyzer to test the strategy, and in so doing the indicator was involved so I then wanted to share a common variable between the indicator and the strategy. it seemed a simple enough concept to inquire about at the time. the optimum course for me is now to hang it up and move on. Many thanks to all for your help … I sincerely mean that.
- Create the variable in the indicator.
- Expose the variable as public in the indicator. This must be done using the Properties of the variable.
You should now be able to access the variable from either entity. Which is what I meant when I wrote: "If you are calling the indicator from the strategy, then it should be possible to use a class variable to store states."
To access the variable from the Strategy, you will have to use standard OOP syntax on the indicator variable:
indicatorName([]parameters).variableNameLast edited by koganam; 10-29-2013, 08:15 AM.
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by fernandobr, Today, 09:11 AM
|
0 responses
0 views
0 likes
|
Last Post
by fernandobr
Today, 09:11 AM
|
||
Started by itrader46, Today, 09:04 AM
|
1 response
3 views
0 likes
|
Last Post Today, 09:10 AM | ||
Started by timmbbo, Today, 08:59 AM
|
0 responses
2 views
0 likes
|
Last Post
by timmbbo
Today, 08:59 AM
|
||
Started by bmartz, 03-12-2024, 06:12 AM
|
5 responses
33 views
0 likes
|
Last Post Today, 08:34 AM | ||
Started by Aviram Y, Today, 05:29 AM
|
4 responses
14 views
0 likes
|
Last Post
by Aviram Y
Today, 07:57 AM
|
Comment