![]() |
|
|||||||
| Indicator Development Support for the development of custom indicators using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Jul 2007
Posts: 176
Thanks: 0
Thanked 0 times in 0 posts
|
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 |
|
|
|
|
|
#2 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Jul 2007
Posts: 176
Thanks: 0
Thanked 0 times in 0 posts
|
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 |
|
|
|
|
|
#4 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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);
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Senior Member
Join Date: Jul 2007
Posts: 176
Thanks: 0
Thanked 0 times in 0 posts
|
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 |
|
|
|
|
|
#6 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#7 | |
|
Senior Member
Join Date: Jul 2008
Posts: 271
Thanks: 4
Thanked 7 times in 7 posts
|
Quote:
(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.
|
|
|
|
|
|
|
#8 |
|
Senior Member
Join Date: Jul 2007
Posts: 176
Thanks: 0
Thanked 0 times in 0 posts
|
Thanks for your help.
I got that to work. Thanks |
|
|
|
|
|
#9 |
|
Senior Member
Join Date: Jul 2007
Posts: 176
Thanks: 0
Thanked 0 times in 0 posts
|
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. |
|
|
|
|
|
#10 |
|
Senior Member
Join Date: Jul 2008
Posts: 271
Thanks: 4
Thanked 7 times in 7 posts
|
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 |
|
|
|
|
|
#11 |
|
Senior Member
Join Date: Jul 2007
Posts: 176
Thanks: 0
Thanked 0 times in 0 posts
|
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 |
|
|
|
|
|
#12 |
|
Senior Member
Join Date: Jul 2008
Posts: 271
Thanks: 4
Thanked 7 times in 7 posts
|
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 |
|
|
|
|
|
#13 |
|
Senior Member
Join Date: Jul 2007
Posts: 176
Thanks: 0
Thanked 0 times in 0 posts
|
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 |
|
|
|
|
|
#14 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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?
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#15 | |
|
Senior Member
Join Date: Jul 2008
Posts: 271
Thanks: 4
Thanked 7 times in 7 posts
|
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:
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 |
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |