PDA

View Full Version : Changing Plot color within code


tquinn
01-05-2007, 03:51 AM
if (Values[2][1]>Values[2][0])
{
Print("RED "+Diff[1].ToString()+" "+Diff[0].ToString());
Plots[2].Pen = new Pen(Color.Red,3);
}
else
{
Print("BLUE "+Diff[1].ToString()+" "+Diff[0].ToString());
Plots[2].Pen = new Pen(Color.Blue,3);
}

-------------------------------------------------------------------------------------------------
This always plots Red, even thou the Print confirms it enters the Blue Loop.

I'm sure I'm missing something simple. I'm new at C#, and NinjaScript.

NinjaTrader_Ray
01-05-2007, 04:56 AM
Create an indicator with one plotandadd the following code in the OnBarUpdate() method:

Values[0].Set(Close[0]);
if (Close[0] > SMA(5)[0])
Plots[0].Pen = new Pen(Color.Red, 2);
else
Plots[0].Pen = new Pen(Color.Blue, 2);

Run it on a 10 tick chart with "Calculate on bar close" set to false. This works fine here. Assuming it works as expected on your side. Work up from this sample to see where it may be breaking.

Ray

tquinn
01-05-2007, 05:24 AM
This toggles the entire line from Blue to Red.

I was wanting to have a multi-colored line.

NinjaTrader_Ray
01-05-2007, 05:38 AM
That is correct, working as designed. For multi-colored line, you have to actually use two lines and set Min/Max threshholds. See Custom Indicator Development Tutotrial Level 5 in the Help Guide.

There is a known bug in the current beta release with respect to this so even if you work through the tutorial example, it will not work as expected. This is resolved for next beta which is targeted for Monday release.

Ray

Creamers
01-29-2007, 09:08 AM
Tried to work with those multi colored lines to.

if (pctK2[0]>50)

Plot1.Set(pctK2[0]);

else

Plot2.Set(pctK2[0]);



As soon the value reaches above 50 it set the plot1 else plot2. Both different colors. See picture.

In tradestation I could set the previous line color like this:

setplotcolor[1](1,green)

Is this also possible in NT ?

NinjaTrader_Ray
01-29-2007, 09:55 AM
Please see the Help Guide NinjaScript > Developing Custom Indicators > Tutorial: Custom Plot Colors via Thresholds



Ray

Creamers
01-31-2007, 10:04 AM
Can't see how to use these tresholdswith stochasticsbut this fills up the gapsin the (see earlier attached) chart (and in my mind) :)

if (pctK2[0] > pctK2[1])
{
Plot1.Set(pctK2[0]);
Plot2.Reset();
}
else
{
Plot2.Set(pctK2[0]);
Plot1.Reset();
}
Plot3.Set(pctK2[0]);

OUFan
02-18-2007, 06:44 PM
Ray I noticed you said there was a bug in a version using Min & Max thresholds. I am having trouble and was wondering what version has the bug and is a new version out that fixes the bug.

Thanks,

OUFan

NinjaTrader_Ray
02-19-2007, 09:27 AM
If you are running the latest beta, Beta 7, this issue is for sure resolved.

Ray