![]() |
This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Member
Join Date: Nov 2008
Location: London
Posts: 53
Thanks: 0
Thanked 0 times in 0 posts
|
How would I go about assigning indicator plot values to a variable in a strategy? Currently I have an indicator that provides/plots an entry level. However the actual entry will only occur when that level is pierced, which normally happens a few bars after the plot.
So what I am asking is how I can store a value derived from an indicator in a strategy and once price breaks that value, a trade is entered. As you can see in the picture, the indicator fires at 18:15, however, the buy zone (between the blue dots) is only pierced at 18:30. I have tried using the examples for using an indicator's plots in a strategy and these do not work as I think that it has to occur on the same bar, which this is not. Any ideas would be most helpful. |
|
|
|
|
|
#2 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
Code:
storeValue = myIndicator()[0]; Code:
if (Close[0] >= storeValue)
EnterLong();
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Member
Join Date: Nov 2008
Location: London
Posts: 53
Thanks: 0
Thanked 0 times in 0 posts
|
Thanks for the quick response, will give it a go once the markets close. Thx again.
|
|
|
|
|
|
#4 |
|
Member
Join Date: Nov 2008
Location: London
Posts: 53
Thanks: 0
Thanked 0 times in 0 posts
|
Where would I put my variable from the indicator in the code that you pprovided ...
storeValue = myIndicator()[0]; Would it be ... storeValue = GartleyRobotBull(BullDa)[0]; where GartleyRobotBull is the indicator and BullDa is the variable within the indicator that contains the value that I need? |
|
|
|
|
|
#5 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
traderT,
You need to first create the storeValue variable as a double in the Variables region of your code. Code:
private double storeValue = 0;
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#6 |
|
Member
Join Date: Nov 2008
Location: London
Posts: 53
Thanks: 0
Thanked 0 times in 0 posts
|
I am the orginal author ;-)
I understand that storeValue would need to be defined. Within my indicator I have the following line... privatedouble BullDa(){return (BullCa() + (1.27 * (BullB() - BullCa())));} So, in my strategy, I want to set storeValue = myIndicator.BullDa And then have ... if (Low[0] <= storeValue) EnterLong(); What I need to know is the syntax for myIndicator.BullDa if it is possible, or, if not, then what type of syntax would I need. I have only been doing c# for a couple of months so I am still fudging my way through stuff and have managed to write a few indicators (You and the team have helped me quite a bit with the indicators that I wrote (Gartley and ****** indicators), but am now want to incorporate them into strategies, which I have not done as yet, hence the dumb questions ( I promise to make them more complicated as I learn more ;-) |
|
|
|
|
|
#7 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
You need to expose your indicator variable then. Please see this reference sample: http://www.ninjatrader-support2.com/...ead.php?t=4991
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#8 |
|
Member
Join Date: Nov 2008
Location: London
Posts: 53
Thanks: 0
Thanked 0 times in 0 posts
|
if (GartleyRobotBull(5, 2, 65).BullDa[0]) > 0
{ (storeValue = (GartleyRobotBull(5, 2, 65).BullDa[0])) } Am having a look at the sample stuff now |
|
|
|
|
|
#9 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
Yea, that wouldn't work because you closed the if-statement too early. You need to watch your parenthesis placement.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#10 |
|
Member
Join Date: Nov 2008
Location: London
Posts: 53
Thanks: 0
Thanked 0 times in 0 posts
|
So what do I need to change to make this work?
if (GartleyRobotBull(5, 2, 65).BullDa[0]) > 0 { (storeValue = (GartleyRobotBull(5, 2, 65).BullDa[0])) } |
|
|
|
|
|
#11 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
Code:
if (condition)
{
// code;
}
This is C# programming. I suggest you go to MSDN or google some resources for a starters guide to C# programming.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#12 |
|
Member
Join Date: Nov 2008
Location: London
Posts: 53
Thanks: 0
Thanked 0 times in 0 posts
|
if ((GartleyRobotBull(5, 2, 65).BullDa[0]) > 0)
{ storeValue = GartleyRobotBull(5, 2, 65).BullDa[0]; } Sorry, I figured that out, however (hopefully last question), now I get a protection level error. Do I have to declare BullDa as a public variable in my indicator? |
|
|
|
|
|
#13 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
Please see the reference sample for how to expose the variable via a public property.
Josh
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to expose indicator values for strategies | cassb | Indicator Development | 3 | 11-07-2008 11:31 AM |
| Assigning indicator values | ericadam | Strategy Development | 1 | 09-06-2008 11:19 PM |
| How do I show values for an indicator | hammall | Charting | 1 | 01-29-2008 07:33 AM |
| Indicator: Exposing indicator values that are not plots | NinjaTrader_Josh | Reference Samples | 0 | 01-15-2008 02:27 AM |
| How are the Pivot indicator values calculated? | NinjaTrader_Ray | Charting | 0 | 12-24-2007 07:54 AM |