![]() |
|
|||||||
| Indicator Development Support for the development of custom indicators using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Feb 2010
Posts: 150
Thanks: 1
Thanked 1 time in 1 post
|
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? |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
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]; }
Ryan M
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Feb 2010
Posts: 150
Thanks: 1
Thanked 1 time in 1 post
|
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?
|
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
With CalculateOnBarClose = false and real time: You get the value of current tick, when crossover occurs.
Ryan M
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Senior Member
Join Date: Feb 2010
Posts: 150
Thanks: 1
Thanked 1 time in 1 post
|
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?
|
|
|
|
|
|
#6 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
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]; }
Ryan M
NinjaTrader Customer Service |
|
|
|
|
|
#7 |
|
Senior Member
Join Date: Feb 2010
Posts: 150
Thanks: 1
Thanked 1 time in 1 post
|
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.
|
|
|
|
|
|
#8 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
Your EMA code is formatted incorrectly. It should be:
crossValue = EMA(10)[0];
Ryan M
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |