NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 12-13-2007, 01:47 PM   #1
GuyFB
Member
 
Join Date: Dec 2007
Location: Dallas, Texas
Posts: 65
Thanks: 0
Thanked 0 times in 0 posts
Default Dynamically change Color

I tried the example in the help screen to dynamically change color of a plot. However, only the last change is active throughout the plot so I get only one change rather than a change for different bars.
Example from help:
// Dynamically change the primary plot's color based on the indicator value
protected override void OnBarUpdate()
{
if (Values[0] > 100)
Plots[0].Pen = new Pen(Color.Blue);
else
Plots[0].Pen = new Pen(Color.Red);
}


My code:
if(piSignal[0] == 1)
{Plots[2].Pen = new Pen(Color.Green,3); else if (piSignal[0] == -1)
{Plots[2].Pen = new Pen(Color.Red,3);
else
{Plots[2].Pen = new Pen(Color.Yellow,3);
GuyFB is offline  
Reply With Quote
Old 12-13-2007, 01:54 PM   #2
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

Correct, your code does exactly that. If you want to have different plotted colors check out this sample.

http://www.ninjatrader-support.com/v...ead.php?t=3227
NinjaTrader_Ray is offline  
Reply With Quote
Old 03-16-2008, 07:26 PM   #3
rcsingleton
Senior Member
 
Join Date: Jan 2008
Posts: 127
Thanks: 8
Thanked 1 time in 1 post
Send a message via Skype™ to rcsingleton
Default Question about dynamically changing Plot colors

Hello Ray.

I am taking a look at the example you posted on dynamically changing Plot colors.

Question. I'm not sure how 'RisingPlot.Set(1, SMA(Period)[1]);' is working.

I have ..

Add(new Plot(Color.Green, PlotStyle.Dot, "Upper"));
Add(new Plot(Color.Red, PlotStyle.Dot, "Lower"));
Add(new Plot(Color.Yellow, PlotStyle.Dot, "Middle"));

But when I get to ..

UpperPlot.Set(1, MACD(fastLen, slowLen, smooth)[1]);
UpperPlot.Set(MACD(fastLen, slowLen, smooth)[0]);

The compiler tells me 'The name 'UpperPlot' does not exist in the current context'.

What am I missing ?

Why does the compiler recognize 'RisingPlot.Set' and not 'UpperPlot.Set' ?

Regards,
R. C. Singleton
rcsingleton is offline  
Reply With Quote
Old 03-16-2008, 07:39 PM   #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 rcsingleton,

The plot names are defined in the collapsed "Properties" section of your code.

Code:
// Adds three DataSeries to store the values of the three plots added in Initialize()
[Browsable(false)]    // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()]        // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries RisingPlot
{
    get { return Values[0]; }
}
The index on Values corresponds to the Add() method you had above.
Code:
Add(new Plot(Color.Green, PlotStyle.Dot, "Upper"));
Add(new Plot(Color.Red, PlotStyle.Dot, "Lower"));
Add(new Plot(Color.Yellow, PlotStyle.Dot, "Middle"));
Index of 0 corresponds with "Upper", index=1="Lower", index=2="Middle".
NinjaTrader_Josh is offline  
Reply With Quote
Old 03-16-2008, 10:12 PM   #5
rcsingleton
Senior Member
 
Join Date: Jan 2008
Posts: 127
Thanks: 8
Thanked 1 time in 1 post
Send a message via Skype™ to rcsingleton
Default Thank You

Thank you Josh.

That did the trick. Will remember to look at 'Properties' section in the future.
rcsingleton 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
Dynamically Modifying SetStopLoss() whitmark Strategy Development 6 10-13-2008 12:17 PM
Change background color trader2be Indicator Development 1 11-13-2007 09:13 PM
Volume Bars color-coded according to Price change Lost Trader Indicator Development 6 10-23-2007 11:15 PM
HMA (Hull Moving Average) color change Mexie Indicator Development 13 10-21-2007 08:58 AM
How . . . do I change color of Ray . . . . barrykish@comcast.net Charting 1 08-01-2007 02:24 PM


All times are GMT -6. The time now is 09:56 AM.