NinjaTrader Support Forum  
X

Attention!

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


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 01-09-2009, 11:43 AM   #1
traderT
Member
 
Join Date: Nov 2008
Location: London
Posts: 53
Thanks: 0
Thanked 0 times in 0 posts
Default Using indicator values

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.
Attached Images
File Type: jpg AutoGartley Strategy v1.JPG (20.1 KB, 38 views)
traderT is offline  
Reply With Quote
Old 01-09-2009, 11:45 AM   #2
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
Default

Code:
storeValue = myIndicator()[0];
Then you can do something like:
Code:
if (Close[0] >= storeValue)
     EnterLong();
or any other logic you may want to use.
NinjaTrader_Josh is offline  
Reply With Quote
Old 01-09-2009, 12:02 PM   #3
traderT
Member
 
Join Date: Nov 2008
Location: London
Posts: 53
Thanks: 0
Thanked 0 times in 0 posts
Default Much appreciated

Thanks for the quick response, will give it a go once the markets close. Thx again.
traderT is offline  
Reply With Quote
Old 01-09-2009, 12:35 PM   #4
traderT
Member
 
Join Date: Nov 2008
Location: London
Posts: 53
Thanks: 0
Thanked 0 times in 0 posts
Default Taking this a step further

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?
traderT is offline  
Reply With Quote
Old 01-09-2009, 01:16 PM   #5
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
Default

traderT,

You need to first create the storeValue variable as a double in the Variables region of your code.
Code:
private double storeValue = 0;
Then you would use the code inside the OnBarUpdate() method. I do not know how your indicator works and how to access the particular variables for your indicator. I suggest you ask the original author of it.
NinjaTrader_Josh is offline  
Reply With Quote
Old 01-09-2009, 01:29 PM   #6
traderT
Member
 
Join Date: Nov 2008
Location: London
Posts: 53
Thanks: 0
Thanked 0 times in 0 posts
Default The original author is useless

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 ;-)

traderT is offline  
Reply With Quote
Old 01-09-2009, 01:31 PM   #7
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
Default

You need to expose your indicator variable then. Please see this reference sample: http://www.ninjatrader-support2.com/...ead.php?t=4991
NinjaTrader_Josh is offline  
Reply With Quote
Old 01-09-2009, 01:48 PM   #8
traderT
Member
 
Join Date: Nov 2008
Location: London
Posts: 53
Thanks: 0
Thanked 0 times in 0 posts
Default So something like this wouldn't work ...

if (GartleyRobotBull(5, 2, 65).BullDa[0]) > 0
{
(storeValue = (GartleyRobotBull(
5, 2, 65).BullDa[0]))
}

Am having a look at the sample stuff now
traderT is offline  
Reply With Quote
Old 01-09-2009, 01:51 PM   #9
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
Default

Quote:
Originally Posted by traderT View Post
if (GartleyRobotBull(5, 2, 65).BullDa[0]) > 0
{
(storeValue = (GartleyRobotBull(
5, 2, 65).BullDa[0]))
}

Am having a look at the sample stuff now
Yea, that wouldn't work because you closed the if-statement too early. You need to watch your parenthesis placement.
NinjaTrader_Josh is offline  
Reply With Quote
Old 01-09-2009, 02:02 PM   #10
traderT
Member
 
Join Date: Nov 2008
Location: London
Posts: 53
Thanks: 0
Thanked 0 times in 0 posts
Default

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]))
}


traderT is offline  
Reply With Quote
Old 01-09-2009, 02:04 PM   #11
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
Default

Code:
if (condition)
{
   // code;
}
Lines need to end with ;
This is C# programming. I suggest you go to MSDN or google some resources for a starters guide to C# programming.
NinjaTrader_Josh is offline  
Reply With Quote
Old 01-09-2009, 02:13 PM   #12
traderT
Member
 
Join Date: Nov 2008
Location: London
Posts: 53
Thanks: 0
Thanked 0 times in 0 posts
Default

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?
traderT is offline  
Reply With Quote
Old 01-09-2009, 02:15 PM   #13
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
Default

Please see the reference sample for how to expose the variable via a public property.
NinjaTrader_Josh is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

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


All times are GMT -6. The time now is 08:06 PM.