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-24-2008, 11:37 PM   #1
Elliott Wave
Senior Member
 
Join Date: Mar 2008
Posts: 731
Default Tushar Chande's Trendscore

I was watching a trading lecture that mentioned this indicator and it seemed interesting.

The code is so hopelessly simple that I'm embarrassed I've spent the last hour and still can't get it to plot. I'm obviously overlooking something very basic and was hoping someone could take a look at it.

This is the Metastock code and I've attached the MetaTrader indicator (which I tried to convert)

Code:
Chande's Trendscore                                                    If(C>=Ref(C,-11),1,-1) + If(C>=Ref(C,-12),1,-1) + 
  If(C>=Ref(C,-13),1,-1) + If(C>=Ref(C,-14),1,-1) + 
  If(C>=Ref(C,-15),1,-1) + If(C>=Ref(C,-16),1,-1) +
  If(C>=Ref(C,-17),1,-1) + If(C>=Ref(C,-18),1,-1) + 
  If(C>=Ref(C,-19),1,-1) + If(C>=Ref(C,-20),1,-1)
In MetaTrader it seems the 'meat' of it is;

Code:
for (score=0,k=0; k<LookBackLength; k++)
                  if (Close[i] >= Close[i+k+LookBack])
                        score++;
                  else  score--;                        
         TrendBuffer[i] = score/LookBackLength;
Which would be something like this in NT;

Code:
for (score=0,k=0; k<LookBackLength; k++)
                  if (Close[0] >= Close[k+LookBack])
                        score++;
                  else  score--;                        
         TrendBuffer.Set(score/LookBackLength);


thanks in advance.
Attached Files
File Type: zip Chandes trendscore.zip (1.4 KB, 18 views)
Elliott Wave is offline  
Reply With Quote
Old 11-25-2008, 05:39 AM   #2
mrlogik
Certified NinjaScript Consultant
 
mrlogik's Avatar
 
Join Date: Sep 2006
Location: New York, USA
Posts: 681
Default

Hey Elliott

What are you getting on your plot? (I cant try the code until later today)

Also, I suggest you always use brackets around statements just to keep things clean and 100% certain the logic is executing as you suspect. Additionally, keep the for statement to only "controlled" variables (so here we remove the score). This is probably not the cause of a problem, but it makes code more readable.

Code:
score = 0;
for(int k = 0 ; k < LookBackLength ; k++)
{
  if(Close[0] >= Close[k + LookBack])
     score++;
  else
     score--;
}
let me know
__________________
"The notion of impossibility only exist in the world of those who had already been imprisoned by their own fears and limitations."

"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-25-2008, 08:57 AM   #3
rt6176
Senior Member
 
Join Date: May 2008
Location: Hartford, CT. USA
Posts: 487
Default

Elliot,

I'm curious about this code,

you posted :
------------------------------------------------------------------
for (score=0,k=0; k<LookBackLength; k++)
if (Close[0] >= Close[k+LookBack])
score++;
else score--;
TrendBuffer.Set(score/LookBackLength);
-----------------------------------------------------------------

OK, my stupid question first. Is this an issue?

if CurrentBar < (k+LookBack)
return;

-----------------------------------------------------------------

Anyway, could you show us the NT code you developed so far...

Thanks,

RJay
rt6176 is offline  
Reply With Quote
Old 11-25-2008, 09:10 AM   #4
mrlogik
Certified NinjaScript Consultant
 
mrlogik's Avatar
 
Join Date: Sep 2006
Location: New York, USA
Posts: 681
Default

If what rt is suggesting is the problem you should see an error in the LOG tab.
__________________
"The notion of impossibility only exist in the world of those who had already been imprisoned by their own fears and limitations."

"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-25-2008, 02:09 PM   #5
Elliott Wave
Senior Member
 
Join Date: Mar 2008
Posts: 731
Default

I'll take another look today after being well rested, but I tried many different things included busting out my C# for dummies and changing the for loop to a while loop etc.

I think part of the issue is that the MT4 indicator is multi-timeframe and has some code I don't think is needed, but perhaps is.

I also tried doing a very inefficient string of 20 if/else statements regarding Close[0] > Close [1, 2, 3] etc, and no matter what I couldn't get anything to plot.
Elliott Wave is offline  
Reply With Quote
Old 11-25-2008, 04:22 PM   #6
roonius
Certified NinjaScript Consultant
 
Join Date: Oct 2008
Location: Chicago, IL
Posts: 523
Send a message via Skype™ to roonius
Default

Is this what are you looking for?
I hope I understood the logics properly...
Looks like rt6176 was right
Attached Images
File Type: jpg chandes.JPG (68.9 KB, 227 views)
Attached Files
File Type: zip ChandesTrendScore.zip (2.0 KB, 24 views)
__________________
www.tradingstudies.com
info[at]tradingstudies[dot]com

Last edited by roonius; 01-08-2009 at 08:00 PM.
roonius is offline  
Reply With Quote
Old 11-25-2008, 04:39 PM   #7
Elliott Wave
Senior Member
 
Join Date: Mar 2008
Posts: 731
Default

That looks exactly right, I'll check it out now and try to learn where I was going wrong.

While I feel I'm improving at NinjaScript sometimes the only way to see where I was going wrong is to see it right.

Elliott Wave is offline  
Reply With Quote
Old 11-25-2008, 05:09 PM   #8
Elliott Wave
Senior Member
 
Join Date: Mar 2008
Posts: 731
Default

It seems to work perfect.

I added a description and interpretation instructions as well as a zero line and fixed the parameter spellings (length vs lenght).

Very simple code, but it seems quite effective for what its supposed to do.
Attached Files
File Type: zip ChandesTrendscore_v1.0.zip (2.3 KB, 123 views)
Elliott Wave is offline  
Reply With Quote
Old 11-25-2008, 05:17 PM   #9
roonius
Certified NinjaScript Consultant
 
Join Date: Oct 2008
Location: Chicago, IL
Posts: 523
Send a message via Skype™ to roonius
Default

Thanks,

Since English is not my native, I appologize in advance for future spelling mistakes.
__________________
www.tradingstudies.com
info[at]tradingstudies[dot]com

Last edited by roonius; 01-08-2009 at 08:00 PM.
roonius is offline  
Reply With Quote
Old 11-25-2008, 05:22 PM   #10
Elliott Wave
Senior Member
 
Join Date: Mar 2008
Posts: 731
Default

Since C# is not my native language I apologize in advance for any future bonehead coding mistakes. lol

Its good to have you here Roonuis and thanks again for contributing.
Elliott Wave is offline  
Reply With Quote
Old 06-16-2010, 11:08 AM   #11
smalltrader35
Junior Member
 
Join Date: Feb 2010
Posts: 5
Default

Can anybody re-write this Indicator for NT7?
smalltrader35 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


All times are GMT -6. The time now is 10:55 AM.