NinjaTrader Support Forum  

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 09-20-2010, 02:52 PM   #1
kenb2004
Senior Member
 
Join Date: Jul 2010
Posts: 415
Thanks: 1
Thanked 4 times in 4 posts
Default Macd Diff Change Direction

Can you please tell me how to program a condition to be true when the Macd "diff" has changed direction from up to down or down to up?
Thanks
Last edited by kenb2004; 09-20-2010 at 02:55 PM.
kenb2004 is offline  
Reply With Quote
Old 09-20-2010, 03:01 PM   #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 Kenb2004,

You can use Rising and Falling conditions if you just want to compare the MACD value to its prior value. The following reference sample can help you set this up in the Strategy wizard condition builder:
Using Rising and Falling conditions in the Strategy Wizard
NinjaTrader_RyanM is offline  
Reply With Quote
Old 09-20-2010, 04:13 PM   #3
kenb2004
Senior Member
 
Join Date: Jul 2010
Posts: 415
Thanks: 1
Thanked 4 times in 4 posts
Default

I get
if (Rising(MACD(12, 26, 9).Diff) == true)
but how do I compare it to the "Diff" Falling AbarAgo?
Thanks
kenb2004 is offline  
Reply With Quote
Old 09-20-2010, 04:36 PM   #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

Hello Ken,

These methods only compare the current MACD value to its prior value. If you want to test a longer duration condition, you have to reference specific values to compare.

if (MACD(12, 26, 9).Diff[0] > MACD(12, 26, 9).Diff[1]) //this is all rising method checks for.

You work with the index [] values to specify the condition you're looking for.
NinjaTrader_RyanM is offline  
Reply With Quote
Old 09-20-2010, 04:47 PM   #5
kenb2004
Senior Member
 
Join Date: Jul 2010
Posts: 415
Thanks: 1
Thanked 4 times in 4 posts
Default

What you showed only creates a condition that shows Rising. I am trying to create a condition that shows a "Change in Direction". Rising is Rising whether it has changed direction or not. How do I create a condition that shows a "Change in Direction"?
kenb2004 is offline  
Reply With Quote
Old 09-20-2010, 05:09 PM   #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

You can specify that there was a falling condition just prior to that, by specifying the bars ago setting for the index.

if (MACD(12, 26, 9).Diff[1] < MACD(12, 26, 9).Diff[2]) //Checks if one bar back was less than 2.
NinjaTrader_RyanM is offline  
Reply With Quote
Old 09-20-2010, 04:39 PM   #7
kenb2004
Senior Member
 
Join Date: Jul 2010
Posts: 415
Thanks: 1
Thanked 4 times in 4 posts
Default

I tried
if (Rising(MACD(12, 26, 9).Diff) == true
&& Rising(MACD(12, 26, 9).Diff, 1) == false)
but I got an error "No overload for method 'Rising' takes '2' arguments
kenb2004 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
Entries per direction Maletor Strategy Development 1 06-13-2009 06:29 AM
MA direction change counter JamesF Indicator Development 15 06-11-2009 03:50 PM
Entries per direction philxhong Strategy Analyzer 5 03-20-2009 10:24 AM
change bar color when MACD >0 or <0 suitguy1 Charting 11 03-08-2009 07:41 AM
MACD with up down arrows on MACD signal line crosses moonriver Indicator Development 1 12-03-2008 10:34 AM


All times are GMT -6. The time now is 05:14 PM.