![]() |
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
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Member
Join Date: Dec 2007
Location: Dallas, Texas
Posts: 65
Thanks: 0
Thanked 0 times in 0 posts
|
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); |
|
|
|
|
|
#2 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
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
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
|
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 |
|
|
|
|
|
#4 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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]; }
}
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"));
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Senior Member
|
Thank you Josh.
That did the trick. Will remember to look at 'Properties' section in the future. |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |