NinjaTrader Support Forum  

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

Indicator Development Support for the development of custom indicators using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 01-11-2011, 11:00 AM   #1
sgordet
Senior Member
 
Join Date: Feb 2010
Posts: 150
Thanks: 1
Thanked 1 time in 1 post
Default Price at Cross Above / Cross Below

I'm using the CrossAbove and CrossBelow indicators on range charts which update on every tick., e.g.,
if (CrossAbove(EMA(10), EMA(20), 1))
{
do something
}

Is there a way that I can capture the instrument price at the time the actual crossover occurs?
sgordet is offline  
Reply With Quote
Old 01-11-2011, 11:04 AM   #2
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

Hello sgordet,

Yes, you can capture a value in a variable at the time of a crossover.

if (CrossAbove(EMA(10), EMA(20), 1))
{
double myDouble = Close[0];
}
NinjaTrader_RyanM is offline  
Reply With Quote
Old 01-11-2011, 11:10 AM   #3
sgordet
Senior Member
 
Join Date: Feb 2010
Posts: 150
Thanks: 1
Thanked 1 time in 1 post
Default

Quote:
Originally Posted by NinjaTrader_RyanM View Post
Hello sgordet,

Yes, you can capture a value in a variable at the time of a crossover.

if (CrossAbove(EMA(10), EMA(20), 1))
{
double myDouble = Close[0];
}
If one is updating intrabar, does Close[0] wait until the first tick of the next bar to update or do you get the price of the current tick when the crossover occurs?
sgordet is offline  
Reply With Quote
Old 01-11-2011, 11:18 AM   #4
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

With CalculateOnBarClose = false and real time: You get the value of current tick, when crossover occurs.
NinjaTrader_RyanM is offline  
Reply With Quote
Old 01-11-2011, 11:24 AM   #5
sgordet
Senior Member
 
Join Date: Feb 2010
Posts: 150
Thanks: 1
Thanked 1 time in 1 post
Default

I'm sorry to trouble you again, it didn't occur to me at the time to ask: I just noticed that the cross often occurs outside of the price bar. Can I also get the price point at the intersection of the two moving averages involved in the crossover when I plot them overlaying the price chart?
sgordet is offline  
Reply With Quote
Old 01-11-2011, 11:42 AM   #6
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

Yes, you can use the same principles to capture an indicator value.

if (CrossAbove(EMA(10), EMA(20), 1))
{
double myDouble1 = EMA(10)[0];
double myDouble2 = EMA(20)[0];
}
NinjaTrader_RyanM is offline  
Reply With Quote
Old 01-11-2011, 02:33 PM   #7
sgordet
Senior Member
 
Join Date: Feb 2010
Posts: 150
Thanks: 1
Thanked 1 time in 1 post
Default

I got an error message when I tried this
double crossValue = 0;
if (CrossAbove(EMA(10), EMA(20), 1))
{
crossValue = EMA[
10][0];
Print(
"crossValue" + crossValue.ToString());
}
Error: Cannot apply indexing with [] to an expression of type 'method group' CS0021
What have I missed?
Thanks.
Last edited by sgordet; 01-11-2011 at 02:38 PM.
sgordet is offline  
Reply With Quote
Old 01-11-2011, 02:58 PM   #8
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

Your EMA code is formatted incorrectly. It should be:

crossValue = EMA(10)[0];
NinjaTrader_RyanM 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
Alerts Price cross Sma akka1970 Market Analyzer 3 12-31-2010 10:29 AM
Cross Hair Price Change Intentional? DeskTroll Version 7 Beta General Questions & Bug Reports 1 02-11-2010 08:23 AM
Cross price with Bollinger Band 4x2win Market Analyzer 3 07-21-2009 04:13 PM
Compare price level with last cross-over Novicetrader General Programming 1 02-23-2009 01:29 AM
cross hair price marker politcat Charting 2 12-30-2008 09:51 AM


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