Thanks,
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
Passing values from indicator to strategy
Collapse
X
-
Passing values from indicator to strategy
I would like to be able to pass a set of values back from an indicator to a strategy. e.g. if my strategy detects a entry signal and calculates optimum profit and loss targets, I'd like the strategy to use those values to set the stop loss and profit targets before entering the trade. Can anybody point me to an example of how to do this?
Thanks,Tags: None
-
don't know exactly about that. But I can tell you that in any class you can use Getters and Setters to open up private variables and set any value you want. As long as the object is instantiated, you can do it. In the case of indicators, they all seem to be instantiated at start (I think) and you have access to them from your API, so yes, you should be able to do that.
-
Hi Owlman, you can check this reference sample to expose the needed values in your indicator for access - http://www.ninjatrader-support2.com/...ead.php?t=4991BertrandNinjaTrader Customer Service
Comment
-
Still a bit confused
Thanks to you both for your responses.
I discovered the example you quoted Bertrand, and put it into my indicator. After a LOT of mucking around with names having the wrong capitalisation, I eventually got it to the point where there is only one error message left. This one says the "Property or indexer 'NinaTrader.Indicator.myIndicator.myParameter' cannot be assigned to - it is read only". I've copied the code in the example as near as I have been able to determine so far, so not sure why I'm getting this error message.
Anyway, I'll keep playing.
Thanks again for the incredibly rapid response, and expert advice and guidance for this beginner C# programmer!
Cheers,
Ian
Comment
-
All good now... ;-)
Hi Josh,
I've got it working now. Yet another capitalisation error! I had defined the variable with a lower case first character, but referred to it with an upper case first character in the code. But I guess that is referring to the definition in the Properties, which must have the opposite capitalisation to the variable in the Variables section. (I learnt that the hard way a few months back).
Thanks again,
Ian
Comment
-
please post example
I found the reference sample SampleBoolSeries which illustrates "exposing indicator variables that are not plots."
(see tutorial article at http://www.ninjatrader-support2.com/...ead.php?t=4991)
The sample creates a BoolSeries object called bullIndication. I tried to access the variable from a strategy script as follows:
NinjaTrader.Indicator.SampleBoolSeries.bullIndicat ion()[0]
The compiler reports that "SampleBoolSeries.bullIndication is inaccessible due to its protection level." What is the correct way to access it?
Perhaps the answer to this question should be included in the above article.Last edited by dave_b_quickc; 04-17-2009, 01:22 PM.
Comment
-
example?
I have tried:
NinjaTrader.Indicator.SampleBoolSeries.BullIndicat ion()[0]
NinjaTrader.Indicator.SampleBoolSeries.BullIndicat ion[0]
NinjaTrader.Indicator.SampleBoolSeries.BullIndicat ion()
NinjaTrader.Indicator.SampleBoolSeries.BullIndicat ion
All variations I've tried are rejected. Is there an example somewhere?
Comment
-
Thanks!
I was just trying to learn how to access the exposed indicator value from a strategy file. I did not know that there was a sample strategy file associated with the sample indicator file. You have answered my question by pointing me to where I could find the answer. Thanks!
Comment
-
Accessing indicator variable for a strategy
I need to access the "dir" variable from the ZigZagUTC indicator found in the NinjaScript Filesharing/ Indicators section.
I simply wish to draw a Up/Down arrow on a chart from a strategy accessing the "dir" value.
I looked at the SampleBoolSeries example and can't seem to correlate it.
Any help would be appreciated...
It is listed in the #region Variables section as below:
#region Variables
// Wizard generated variables
privateint span = 2; // Default setting for Span
privatebool useHiLo = true; // Default setting for UseHiLo
private Color zigZagColor = Color.Green; // Default setting for zigZagColor
privateint show = 3; // Default setting for Show
// User defined variables (add any user defined variables below)
private DataSeries hi, lo;
privatebool drawlines, showdots;
privateint linewidth = 2;
// Useful public properties
publicint dir; // direction of current zigzag trend, 1=up, -1=down
It is also shown under the "protected override void Initialize()" section as dir = 0;
And then again under the "protected override OnBarUpdate()" section as it is set to dir = 1 or dir = -1
Comment
-
Randwulf,
Please look at the indicator from the SampleBoolSeries zip file. You want to keep the variable as private and just create a public variable down in the Properties region that access the private variable. Then in your other scripts you access the public variable.Josh P.NinjaTrader Customer Service
Comment
-
Thx 4 the reply Josh..
I changed the variable "dir" to private and in the "Properties" section I added:
[Browsable(false)]
[XmlIgnore()]
public int dir
{
get { return dir; } // Allows our public dir int to access and expose our interal dir int
}
However, I get a compile error that "... already contains a definition for 'dir'"
I know it probably appears obvious to most but, as close as I probably am to the solution, I just can't seem to get the last little bit.... Help
Edit: Figured it out
The line above "public int dir" should have been "public int Dir"
Forgot to make it capitalized.
Thx again however for the earlier assistanceLast edited by Randwulf; 05-30-2009, 04:59 AM.
Comment
-
Trouble using ZigZagUTC
I am a new member; just trying to figure out how to simply print ZigZag points and direction. But when I use following code, I get all 0, not a single 1 or -1 as it should. What am I doing wrong here?
Print(ZigZagUTC(3,6,true,Color.Blue).dir);
If possible, How will I get past points marked by ZigZag?
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by ETFVoyageur, Today, 07:05 PM
|
0 responses
7 views
0 likes
|
Last Post
by ETFVoyageur
Today, 07:05 PM
|
||
Started by Orion815, 05-02-2024, 08:39 AM
|
2 responses
18 views
0 likes
|
Last Post
by Orion815
Today, 06:24 PM
|
||
Started by suroot, 02-25-2017, 04:43 AM
|
11 responses
2,552 views
0 likes
|
Last Post
by Zilvercat
Today, 05:36 PM
|
||
Started by Rogers101, 05-05-2024, 11:30 AM
|
16 responses
50 views
0 likes
|
Last Post
by Rogers101
Today, 04:44 PM
|
||
Started by ninza33, Today, 12:31 PM
|
2 responses
12 views
0 likes
|
Last Post
by ninza33
Today, 03:52 PM
|
Comment