PDA

View Full Version : Changing plot colors inside of a strategy or indicator


NinjaTrader_Ray
01-03-2007, 02:20 AM
In a NinjaScriptindicator or strategy, you add plots via the Add() method:

For example:

protected override void Intialize()
{
Add(new Plot(Color.Green, "Plot1"));
Add(new Plot(Color.Red, "Plot2"));
}


Plots are automatically added to the Plots array. You can access individual plot objects and modify properties on them through this array.

The example code belowswitches the entire "Plot1" color betweengreen and red depending on the SMA values:

protected override void OnBarUpdate()
{
if (SMA(5)[0] > SMA(15)[0])
Plots[0].Pen.Color = Color.Green;
else
Plots[0].Pen.Color = Color.Red;
}

whitmark
04-01-2007, 11:02 AM
Does this approach work? I was under the impression that you had to "set" different plots of different colors to dynamically change colors.

Regards,

Whitmark

OUFan
04-01-2007, 12:27 PM
I tried this method and couldn't get it to work. What else needs to be done to make it work?

OUFan

NinjaTrader_Ray
04-02-2007, 01:00 AM
Yes, this works for changing the "entire" plot color. This is not a solution for a multi-colored plot.

Ray

whitmark
04-02-2007, 01:25 AM
Okay, for the record then, the initial example works and is useful to understand how plots work but is not a practical example. The typical application of this type of example ismulti-color plot. . . NinjaScipt newbies take heed.

whitmark
06-23-2007, 11:30 AM
For the sake of clarification, there is a comment earlier in this thread that implies that the Add() method can be used within a NinjaScript strategy to add a Plot. This is not the case. The Add() method, when used with a strategy, can be used add an indicator (that may have its own plot) or another bars object (that will not display), but the Add(Plot) or Add(Line) is currently only reserved for NinjaScript indicators.