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 > Indicator Development

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

Reply
 
Thread Tools Display Modes
Old 06-25-2009, 04:46 AM   #1
Shansen
Senior Member
 
Join Date: Jan 2009
Location: Melbourne
Posts: 178
Thanks: 3
Thanked 0 times in 0 posts
Default CrossAbove / CrossBelow

NT Team,

It appears the CrossAbove and CrossBelow indicators may have a bug.

Using CrossAbove(IDataSeries series1, IDataSeries series2, int lookBackPeriod), where lookBackPeriod = 1, it appears the indicator is designed along the lines of if the prior series1 value is less than the prior series2 value and the current series1 value is greater than the current series 2 value than return true, else false. That is:
if (series1[1] <= series2[1] && series1[0] > series2[0])
{
true;
else
false;
}
While this will be correct most the time there is an exception. In the event series1 has been above series2 for the last several bars, then in the next bar series1 dips to EQUAL series2, and in the following bar series1 remains above series two this would result in the CrossAbove indicator returning "true" when a cross above has not occurred.

Any input would be appreciated.
Thanks
Shannon
Shansen is offline  
Reply With Quote
Old 06-25-2009, 07:16 AM   #2
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,414
Thanks: 252
Thanked 977 times in 960 posts
Default

Shannon, thanks for your post - do you have a reproducible scenario so we can check into this?
NinjaTrader_Bertrand is online now  
Reply With Quote
Old 07-02-2009, 06:31 AM   #3
Shansen
Senior Member
 
Join Date: Jan 2009
Location: Melbourne
Posts: 178
Thanks: 3
Thanked 0 times in 0 posts
Default

Bertrand,

Apologies for the tardy reply.

Logically, CrossAbove and CrossBelow formulas, with the same settings should alternate when both placed in a script as price moves from above to below Series2 and vice versa. As shown the in the below listing this is not the case where CrossAboves or CrossBelows can occur consecutively. This occurs where the bar prior to the second consecutive CrossAbove / CrossBelow has its Close equal to the SMA(24).

On the ES 09-09 1min, while there are many many CrossAboves / Crossbelows, below are two examples where there are two consecutive CrossAboves / Crossbelows:

'UpBar' = CrossAbove(Close, SMA(Close, 24),1) = 13/06/2009 2:24:00 AM
'Downbar' = CrossBelow(Close, SMA(Close, 24),1) = 13/06/2009 2:25:00 AM
'Downbar' = CrossBelow(Close, SMA(Close, 24),1) = 13/06/2009 2:41:00 AM
'UpBar' = CrossAbove(Close, SMA(Close, 24),1) = 13/06/2009 2:43:00 AM

'UpBar' = CrossAbove(Close, SMA(Close, 24),1) = 15/06/2009 11:26:00 PM
'Downbar' = CrossBelow(Close, SMA(Close, 24),1) = 15/06/2009 11:32:00 PM
'UpBar' = CrossAbove(Close, SMA(Close, 24),1) = 15/06/2009 11:59:00 PM
'UpBar' = CrossAbove(Close, SMA(Close, 24),1) = 16/06/2009 12:06:00 AM
'Downbar' = CrossBelow(Close, SMA(Close, 24),1) = 16/06/2009 12:15:00 AM


Happy hunting
Regards
Shannon
Shansen is offline  
Reply With Quote
Old 07-02-2009, 07:22 AM   #4
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

Shannon,

Not sure I entirely follow you. Once you have "crossed above" you need to come back down for it to be able to cross above another time.

If you are running with CalculateOnBarClose = false, it is very possible to get a cross above = true while the bar is building, but ultimately have a cross above = false at the end of the bar which when coupled with a future bar may seem like two consecutive cross aboves.
NinjaTrader_Josh is offline  
Reply With Quote
Old 07-02-2009, 02:49 PM   #5
Shansen
Senior Member
 
Join Date: Jan 2009
Location: Melbourne
Posts: 178
Thanks: 3
Thanked 0 times in 0 posts
Default

Josh,

Thank you for the reply. Apologies for my less than clear explanation.

I agree 100% with your first statement, "Once you have 'crossed above' you need to come back down for it to be able to cross above another time". Though, to be complete I understand it to be "Once you have 'crossed above' you need to 'cross below' for it to be able to cross above another time".

The script was run with CalculateOnBarClose = true. Please investigate the examples provided.

Thanks
Shannon
Shansen is offline  
Reply With Quote
Old 07-02-2009, 03:50 PM   #6
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

Shannon,

Please try printing evaluations on every single bar and see what the values are between those events.
NinjaTrader_Josh is offline  
Reply With Quote
Old 07-03-2009, 09:34 PM   #7
Shansen
Senior Member
 
Join Date: Jan 2009
Location: Melbourne
Posts: 178
Thanks: 3
Thanked 0 times in 0 posts
Default

Josh,

Not sure what you're asking.
Just run the following script on the ES 09-09 1min.

protectedoverridevoid OnBarUpdate()

{
if (CurrentBar < 100) return;
// Set past SMA CrossAbove bars
if (CrossAbove(Close, SMA(Close, 24),1))

{
Print (
"'UpBar' = CrossAbove(Close, SMA(Close, 24),1) = " + Time.ToString());

}
// Set past SMA CrossBelow bars
if (CrossBelow(Close, SMA(Close, 24),1))

{
Print (
"'Downbar' = CrossBelow(Close, SMA(Close, 24),1) = " + Time.ToString());

}
}

Shannon
Shansen is offline  
Reply With Quote
Old 07-04-2009, 01:19 PM   #8
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

Quote:
Originally Posted by Shansen View Post
While this will be correct most the time there is an exception. In the event series1 has been above series2 for the last several bars, then in the next bar series1 dips to EQUAL series2, and in the following bar series1 remains above series two this would result in the CrossAbove indicator returning "true" when a cross above has not occurred.

Any input would be appreciated.
Thanks
Shannon
This is correct and is expected. I recall vaguely years ago we had internally discussed this and for whatever reason, it was implemented as you have pointed out. I will check into this again.
NinjaTrader_Ray 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
CrossAbove GreenTrade Strategy Development 1 02-26-2009 06:56 AM
What does CrossAbove/Below do? tradefaz General Programming 1 08-23-2008 12:56 PM
CrossBelow and Compiled Strategies tony900hwk Strategy Development 4 07-18-2008 11:46 PM
Correct argument passing, CrossBelow, Stochastics MarkBN General Programming 3 04-16-2008 07:06 AM
No CrossAbove/CrossBelow condition for alerts? Elliott Wave Market Analyzer 1 04-11-2008 01:39 PM


All times are GMT -6. The time now is 06:51 AM.