![]() |
|
|||||||
| Indicator Development Support for the development of custom indicators using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Mar 2008
Posts: 731
|
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) Code:
for (score=0,k=0; k<LookBackLength; k++)
if (Close[i] >= Close[i+k+LookBack])
score++;
else score--;
TrendBuffer[i] = score/LookBackLength;
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. |
|
|
|
|
|
#2 |
|
Certified NinjaScript Consultant
Join Date: Sep 2006
Location: New York, USA
Posts: 681
|
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--;
}
__________________
"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 |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: May 2008
Location: Hartford, CT. USA
Posts: 487
|
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 |
|
|
|
|
|
#4 |
|
Certified NinjaScript Consultant
Join Date: Sep 2006
Location: New York, USA
Posts: 681
|
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 |
|
|
|
|
|
#5 |
|
Senior Member
Join Date: Mar 2008
Posts: 731
|
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. |
|
|
|
|
|
#6 |
|
Certified NinjaScript Consultant
|
Is this what are you looking for?
I hope I understood the logics properly... Looks like rt6176 was right Last edited by roonius; 01-08-2009 at 08:00 PM. |
|
|
|
|
|
#7 |
|
Senior Member
Join Date: Mar 2008
Posts: 731
|
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.
|
|
|
|
|
|
#8 |
|
Senior Member
Join Date: Mar 2008
Posts: 731
|
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. |
|
|
|
|
|
#9 |
|
Certified NinjaScript Consultant
|
Thanks,
Since English is not my native, I appologize in advance for future spelling mistakes.
Last edited by roonius; 01-08-2009 at 08:00 PM. |
|
|
|
|
|
#10 |
|
Senior Member
Join Date: Mar 2008
Posts: 731
|
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. |
|
|
|
|
|
#11 |
|
Junior Member
Join Date: Feb 2010
Posts: 5
|
Can anybody re-write this Indicator for NT7?
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|