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 09-16-2008, 04:48 PM   #1
dwalls
Senior Member
 
Join Date: Jul 2007
Posts: 176
Thanks: 0
Thanked 0 times in 0 posts
Default Indicator ploted on CCI zero line

Hello,
If I took the standard CCI indicator in Ninja and wanted to make the zero line change colors when another condition was true or false...how would I do this?
The CCI zero line already has a color attached to it that you can change but this would go over it or on top of it.

Example 1: If the condition...3 period ema is above the 34 period ema...paint the CCI zero line Green. If the condition...3 period ema is below the 34 period ema...paint the CCI zero line Red.

OR

Example 2: If the condition...RSI 14,3 is above the 70 line...paint the CCI zero line Green. If the condition...RSI 14,3 is below the 30 line...paint the CCI zero line Red.

Thanks for your help
dwalls is offline  
Reply With Quote
Old 09-16-2008, 05:00 PM   #2
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

dwalls,

You will need to custom code the color change. Please see this reference sample for multi-colored plots: http://www.ninjatrader-support.com/v...ead.php?t=3227
NinjaTrader_Josh is offline  
Reply With Quote
Old 09-16-2008, 05:35 PM   #3
dwalls
Senior Member
 
Join Date: Jul 2007
Posts: 176
Thanks: 0
Thanked 0 times in 0 posts
Default

Hi Josh,
Thanks for the response. Could you look at this , please.


protectedoverridevoid OnBarUpdate()
{
if (CurrentBar == 0)
Value.Set(
0);
else
{
double mean = 0;
for (int idx = Math.Min(CurrentBar, Period - 1); idx >= 0; idx--)
mean += Math.Abs(Typical[idx] - SMA(Typical, Period)[
0]);
Value.Set((Typical[
0] - SMA(Typical, Period)[0]) / (mean == 0 ? 1 : (0.015 * (mean / Math.Min(Period, CurrentBar + 1)))));
}

if (EMA(3)[0] >= EMA(34)[0])

{
DrawHorizonalLine(
"CCI, Zero Line, Color.LimeGreen);
}
if (EMA(3)[0] <= EMA(34)[0])

{
DrawHorizonalLine(
"CCI, Zero Line, Color.Red);
}


}
Properties





Error: Newline in constant CS1010
dwalls is offline  
Reply With Quote
Old 09-17-2008, 08:14 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

Hi dwalls,

You forgot the ending " for the string CCI on your DrawHorizontalLine(). Also, you need to adhere to the proper syntaxing.

DrawHorizontalLine(string tag, double y, Color color)

so...
DrawHorizontalLine("CCI", 0, Color.LimeGreen);
NinjaTrader_Josh is offline  
Reply With Quote
Old 10-13-2008, 11:39 AM   #5
dwalls
Senior Member
 
Join Date: Jul 2007
Posts: 176
Thanks: 0
Thanked 0 times in 0 posts
Default

I cant seem to get this to work.
There must be something I'm missing.
Is there something that I need to have in theprotectedoverridevoid Initialize()...area to make this work?

Or could someone please post a working code for changing the color of the CCI zero line using conditions like the one shown below.

Thanks
dwalls is offline  
Reply With Quote
Old 10-13-2008, 11:46 AM   #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

dwalls,

Are you trying to modify the original CCI indicator? If that is what you are doing you will first need to rename your indicator to a different name for the changes to be saved.

After that and you want color changing zero line you will need to replace the Add(new Line....) with an Add(new Plot(....)) and then use the techniques demonstrated in this reference sample for multi-colored plots. http://www.ninjatrader-support.com/v...ead.php?t=3227
NinjaTrader_Josh is offline  
Reply With Quote
Old 10-13-2008, 05:00 PM   #7
anachronist
Senior Member
 
Join Date: Jul 2008
Posts: 271
Thanks: 4
Thanked 7 times in 7 posts
Default

Quote:
Originally Posted by dwalls View Post
If I took the standard CCI indicator in Ninja and wanted to make the zero line change colors when another condition was true or false...how would I do this?
Me, I'd create two plots for the zero line and plot them as hash marks.

(Initialize)
Add(new Plot(Color.Green, PlotStyle.Hash, "ZeroGreen"));
Add(new Plot(Color.Red, PlotStyle.Hash, "ZeroRed"));

(OnBarUpdate)
if (condition) ZeroGreen.Set(0); else ZeroRed.Set(0);

The zero line will appear as a dashed line with red or green dashes, depending on the condition above. Also, remember to add the appropriate properties code for ZeroGreen and ZeroRed in the properties region, else you'll have to use Values[2].Set(0) and Values[3].Set(0), assuming ZeroGreen and ZeroRed are plots 2 and 3, respectively.
-Alex
Last edited by anachronist; 10-13-2008 at 05:04 PM.
anachronist is offline  
Reply With Quote
Old 10-14-2008, 11:55 AM   #8
dwalls
Senior Member
 
Join Date: Jul 2007
Posts: 176
Thanks: 0
Thanked 0 times in 0 posts
Default

Thanks for your help.
I got that to work.

Thanks
dwalls is offline  
Reply With Quote
Old 10-14-2008, 03:29 PM   #9
dwalls
Senior Member
 
Join Date: Jul 2007
Posts: 176
Thanks: 0
Thanked 0 times in 0 posts
Default

anachronist,
Thanks for your help on the zeroline.
While were at it, how about the Ploting for something on the 100,-100 or 200,-200 lines using the same type color changes but for a different condition. I tried to by using the same code and just changed the
ZeroGreen.Set(0); else ZeroRed.Set(0); to (200) and (-200) but it wouldn't work. Do you mind sharing a working code for this as well if you have one.

Thanks for you help.
dwalls is offline  
Reply With Quote
Old 10-14-2008, 04:30 PM   #10
anachronist
Senior Member
 
Join Date: Jul 2008
Posts: 271
Thanks: 4
Thanked 7 times in 7 posts
Default

Were you also setting ZeroGreen and ZeroRed to zero in the same code? You will need to allocate more plots if you want additional multicolor lines.
-Alex
anachronist is offline  
Reply With Quote
Old 10-14-2008, 05:39 PM   #11
dwalls
Senior Member
 
Join Date: Jul 2007
Posts: 176
Thanks: 0
Thanked 0 times in 0 posts
Default

Yes, and I was setting ZeroGreen and ZeroRed to 200, -200 in the same code. That must be a conflict. I created two new plots called TwoHundredGreen and TwoHundredRed and then used TwoHundredGreen (200) & TwoHundredRed (200) and then did TwoHundredGreen (-200)and TwoHundredRed (-200) but that didnt work either.
How do you think it should be done?
Thanks
dwalls is offline  
Reply With Quote
Old 10-14-2008, 11:55 PM   #12
anachronist
Senior Member
 
Join Date: Jul 2008
Posts: 271
Thanks: 4
Thanked 7 times in 7 posts
Default

Yes, you probably had a conflict. The value plotted would be the last one you set.

I would do it like this:

(Initialize)
Add(new Plot(Color.Green, PlotStyle.Hash, "ZeroGreen"));
Add(new Plot(Color.Red, PlotStyle.Hash, "ZeroRed"));
Add(new Plot(Color.Green, PlotStyle.Hash, "TwoHundredGreen"));
Add(new Plot(Color.Red, PlotStyle.Hash, "TwoHundredRed"));

(OnBarUpdate)
if (condition1) ZeroGreen.Set(0); else ZeroRed.Set(0);
if (condition2) TwoHundredGreen.Set(200);
else TwoHundredRed.Set(-200);

You're saying you tried that and it didn't work? Is the scale on the right side of the plot at least spanning 200 to -200?
-Alex
anachronist is offline  
Reply With Quote
Old 10-15-2008, 10:06 AM   #13
dwalls
Senior Member
 
Join Date: Jul 2007
Posts: 176
Thanks: 0
Thanked 0 times in 0 posts
Default

Thanks Alex,
I got this to work.
It will change the color from green to red on the 200 line and will also work if I set it to the -200 line.

(Initialize)
Add(new Plot(Color.Green, PlotStyle.Hash, "ZeroGreen"));
Add(new Plot(Color.Red, PlotStyle.Hash, "ZeroRed"));
Add(new Plot(Color.Green, PlotStyle.Hash, "TwoHundredGreen"));
Add(new Plot(Color.Red, PlotStyle.Hash, "TwoHundredRed"));

(OnBarUpdate)
if (condition1) ZeroGreen.Set(0); else ZeroRed.Set(0);
if (condition2) TwoHundredGreen.Set(200);
else TwoHundredRed.Set(200);

Now I want to duplicate this so the 200 line and the-200 line show the same green and red colors at the same time...so the 200 line colors and
the -200 line colors actually match each other.
I tried using the same TwoHundredGreen.Set on the (200) & (-200) and TwoHundredRed.Set on the (200) & (-200) but it wouldnt plot so I added a third set of color plots but still coulnt get it to plot on the 200 and the -200 lines at the same time...dont know why...it looks like it should work...again, I must be missing something. There seems to be a conflict.
Do you see anything wrong here:

(Initialize)
Add(new Plot(Color.Green, PlotStyle.Hash, "ZeroGreen"));
Add(new Plot(Color.Red, PlotStyle.Hash, "ZeroRed"));
Add(new Plot(Color.Green, PlotStyle.Hash, "TwoHundredGreen"));
Add(new Plot(Color.Red, PlotStyle.Hash, "TwoHundredRed"));
Add(new Plot(Color.Green, PlotStyle.Hash, "MinusTwoHundredGreen"));
Add(new Plot(Color.Red, PlotStyle.Hash, "MinusTwoHundredRed"));


(OnBarUpdate)
if (condition1) ZeroGreen.Set(0); else ZeroRed.Set(0); //works
if (condition2) TwoHundredGreen.Set(200);
else TwoHundredRed.Set(200); //works
if (condition3 same as condition2) MinusTwoHundredGreen.Set(-200);
else MinusTwoHundredRed.Set(-200); //doesnt work

Thanks
dwalls is offline  
Reply With Quote
Old 10-15-2008, 10:15 AM   #14
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

dwalls,

I have not been following this thread intimately, but please describe what does not work. Have you created the plots properly in the Properties region of the code too? Each plot has its own unique Values[] index?
NinjaTrader_Josh is offline  
Reply With Quote
Old 10-15-2008, 10:24 AM   #15
anachronist
Senior Member
 
Join Date: Jul 2008
Posts: 271
Thanks: 4
Thanked 7 times in 7 posts
Default

You're right, sorry, I meant that you had to create two new plots for each new color-changing line you want to add.

Quote:
Originally Posted by dwalls View Post
(Initialize)
Add(new Plot(Color.Green, PlotStyle.Hash, "ZeroGreen"));
Add(new Plot(Color.Red, PlotStyle.Hash, "ZeroRed"));
Add(new Plot(Color.Green, PlotStyle.Hash, "TwoHundredGreen"));
Add(new Plot(Color.Red, PlotStyle.Hash, "TwoHundredRed"));
Add(new Plot(Color.Green, PlotStyle.Hash, "MinusTwoHundredGreen"));
Add(new Plot(Color.Red, PlotStyle.Hash, "MinusTwoHundredRed"));

(OnBarUpdate)
if (condition1) ZeroGreen.Set(0); else ZeroRed.Set(0); //works
if (condition2) TwoHundredGreen.Set(200);
else TwoHundredRed.Set(200); //works
if (condition3 same as condition2) MinusTwoHundredGreen.Set(-200);
else MinusTwoHundredRed.Set(-200); //doesnt work
Don't use a condition 3, just use

if (condition2) {
TwoHundredGreen.Set(200);
MinusTwoHundredGreen.Set(-200);
} else {
TwoHundredRed.Set(200);
MinusTwoHundredRed.Set(-200);
}

I don't know why that wouldn't work. As Josh says above, you need to make sure you have the correct properties set in the properties region, with each plot returning a different value (Value[0], Value[1], Value[2], etc.).

-Alex
anachronist 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
Indicator line multi-coloring for up/down zlpele General Programming 8 08-15-2009 06:55 PM
Help me fix my simple Line @ Bid Price Indicator NinjaCustomer Indicator Development 8 03-06-2008 10:06 AM
How do I adapt the constant line indicator? winJR Indicator Development 6 02-03-2008 12:27 PM
Indicator line goes to zero when CalculateOnBarClose set to True ThePatientOne Indicator Development 1 08-30-2007 11:42 AM
Line "names" in Indicator Box change to "Line" after modification higler Charting 3 05-02-2007 06:05 AM


All times are GMT -6. The time now is 03:11 AM.