PDA

View Full Version : Changing indicator colours as part of NT Strategy


dgregor5
07-15-2007, 04:55 AM
Hi
How does one change the indicator line (e.g. EMA) colour if part of an NT strategy?

thx
David

NinjaTrader_Ray
07-15-2007, 02:07 PM
You can do something like:


protected override void Initialize()
{
Add(SMA(20));
SMA(20).Plots[0].Pen.Color = Color.Red;
CalculateOnBarClose = true;
}

dgregor5
07-17-2007, 01:52 PM
thx - this works a treat.........
next step, how does one change the colours of both the two lines & histogram for the MACD.

thx
David

NinjaTrader_Ray
07-17-2007, 02:03 PM
The concept is that the Plots[] and Lines[] are arrays holding plot and line objects. If you have a two line plot, you can change the color by accessing either Plots[0] for the first plot, Plots[1] for the second plot and so on...

http://www.ninjatrader-support.com/HelpGuideV6/Lines.html

http://www.ninjatrader-support.com/HelpGuideV6/Plots.html

Review my sample code to get an idea of how you could replicate this for the MACD indicator.

dgregor5
07-17-2007, 02:29 PM
great - easy to code; work a treat. thx for your help !
David

dgregor5
07-19-2007, 10:53 AM
OK - hopefully final question on this thread. I am now struggling to change the thickness of the MACD histogram! How can I resolve this one. thx !!!!
David

NinjaTrader_Dierk
07-19-2007, 10:55 AM
On the indicator properties: Right click->Indicators

dgregor5
07-19-2007, 11:04 AM
thx. but would like to integrate into the coded strategy....pls refer to earlier notes on this. thx. David

NinjaTrader_Ray
07-19-2007, 11:47 AM
Try:

SMA(20).Plots[0].Pen.Width = 2;

dgregor5
07-19-2007, 12:28 PM
thx Ray ! it works

higler
08-01-2007, 05:08 PM
I am having a problem controlling the Plot Color. I have an indicator that has one plot that was generated by the wizard:

Add(new Plot(Color.FromKnownColor(KnownColor.Blue), PlotStyle.Bar, "ChangeFromOpen"));

I am assuming that this is stored in Plots[0].

The indicator works until I add the following code to the OnBarUpdate method to try and manipulate the color of the plot (the code was copied directly from the help example):

if (Values[0] > 100)
Plots[0].Pen = new Pen(Color.Blue);
else
Plots[0].Pen = new Pen(Color.Red);

I get the compiler error: Operator '>' cannot be applied to operands of type 'NinjaTrader.Data.DataSeries' and 'int'

If I try and compare it to 100.0 then I get the same error message except 'double' instead of 'int'

Any help would be greatly appreciated.

NinjaTrader_Ray
08-01-2007, 05:15 PM
Values[0] returns a DataSeries at that index. To get the value of try something like:

Values[0][0]

Also, no need to create a new Pen object. Best to avoid creating new objects if you do not have to.

Plots[0].Pen.Color = Color.Red;
'
will work for example.

higler
08-01-2007, 05:31 PM
Thanks. That works.

higler
08-02-2007, 09:12 AM
If I have an indicator with three plots, is there a way to programmatically turn off/on the price markers for the individual plots? Thanks.

NinjaTrader_Ray
08-02-2007, 09:19 AM
Unfortunately this can only be programatically controlled at the indicator level for all price markers, not individually.