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 11-13-2008, 07:47 AM   #1
caldolegare
Junior Member
 
Join Date: Nov 2008
Posts: 7
Thanks: 0
Thanked 0 times in 0 posts
Default Totally noob question about barsago

Ok let's say I want to compare the current MACD value to the previous value:

double macd1 = MACD(period1, period2, smooth).Avg[0];
double macd2 = MACD(period, period2, smooth).Avg[1];

if (macd1<macd2)
{do something}

macd1 seems to be computing fine but macd2 is not.

Where am I messing up? Thanks!

caldolegare is offline  
Reply With Quote
Old 11-13-2008, 08:14 AM   #2
mrlogik
Certified NinjaScript Consultant
 
mrlogik's Avatar
 
Join Date: Sep 2006
Location: New York, USA
Posts: 774
Thanks: 1
Thanked 7 times in 5 posts
Default

I think...

Code:
double macd2 = MACD(period, period2, smooth)[1].Avg; 
"You look closely enough, you can find everything has a ... weak spot where it can break, sooner or later"

PureLogikTrading
mrlogik is offline  
Reply With Quote
Old 11-13-2008, 08:14 AM   #3
NinjaTrader_Ben
NinjaTrader Customer Service
 
NinjaTrader_Ben's Avatar
 
Join Date: May 2008
Location: Denver, CO
Posts: 3,157
Thanks: 0
Thanked 3 times in 3 posts
Default

Hello,


Try adding this before the condition:

Print(macd1 + " macd1");
Print(macd2 + " macd2");

Then go to Tools>Output Window and see what prints when the strategy is running.

If that doesn't work try printing your macd parameters before they are assigned to macd1 and macd2.

Another possible issue may be that you do not have enough bars to calculate the macd. Please review this link:
http://www.ninjatrader-support2.com/...ead.php?t=3170
NinjaTrader_Ben is offline  
Reply With Quote
Old 11-13-2008, 08:19 AM   #4
caldolegare
Junior Member
 
Join Date: Nov 2008
Posts: 7
Thanks: 0
Thanked 0 times in 0 posts
Default

When I put this in I get nothing

Print(macd1 + " macd1");
Print(macd2 + " macd2");

If I remove the macd2 line I get all the values for macd1 in the output window.
caldolegare is offline  
Reply With Quote
Old 11-13-2008, 08:21 AM   #5
mrlogik
Certified NinjaScript Consultant
 
mrlogik's Avatar
 
Join Date: Sep 2006
Location: New York, USA
Posts: 774
Thanks: 1
Thanked 7 times in 5 posts
Default

I think what ben means is the following

Code:
Print("MACD1 = " + macd1.ToString());
Print("MACD2 = " + macd2.ToString());
Did you try what I suggested?
"You look closely enough, you can find everything has a ... weak spot where it can break, sooner or later"

PureLogikTrading
mrlogik is offline  
Reply With Quote
Old 11-13-2008, 08:32 AM   #6
NinjaTrader_Ben
NinjaTrader Customer Service
 
NinjaTrader_Ben's Avatar
 
Join Date: May 2008
Location: Denver, CO
Posts: 3,157
Thanks: 0
Thanked 3 times in 3 posts
Default

Hello,



The issue is probably arising from not adding if(CurrentBar > some_number) return; at the top of the OnBarUpdate() block.
NinjaTrader_Ben is offline  
Reply With Quote
Old 11-17-2008, 09:05 AM   #7
caldolegare
Junior Member
 
Join Date: Nov 2008
Posts: 7
Thanks: 0
Thanked 0 times in 0 posts
Default

Thanks that worked perfectly.

Quote:
Originally Posted by NinjaTrader_Ben View Post
Hello,



The issue is probably arising from not adding if(CurrentBar > some_number) return; at the top of the OnBarUpdate() block.
caldolegare 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
barsAgo NinjaCustomer Indicator Development 2 05-19-2008 07:24 AM
Noob questions... FubaR Miscellaneous Support 1 04-02-2008 10:49 AM
How to Plot a Dot 50 BarsAgo robhef Indicator Development 2 01-21-2008 02:30 PM
Retrieve Indicator Value n BarsAgo TAJTrades Indicator Development 1 12-27-2007 04:27 AM
barsago error Jim-Boulder Strategy Development 1 10-18-2007 02:17 PM


All times are GMT -6. The time now is 05:12 AM.