PDA

View Full Version : CCI (or any indicator) with changing color


Jibu V
08-03-2007, 09:00 AM
I'm trying to develop an indicator (specifically CCI) that will change colors depending on whether it's increasing, decreasing, or the same compared to the previous bar. I put together this code from other code I found in different places but this seems to look at the price bar instead of the previous CCI bar to determine color. Does anyone know how I may change this to make the color change due to the previous CCI bar? BTW, I am not an expert at all in programming, so all help would be GREATLY appreciated... Thanks.

#region Variables
// Wizard generated variables
// User defined variables (add any user defined variables below)
#endregion

/// <summary>
/// This method is used to configure the indicator and is called once before any bar data is loaded.
/// </summary>
protected override void Initialize()
{
Add(new Line(Color.DarkGray, 180, "Level 1"));
Add(new Line(Color.DarkGray, 0, "Zero line"));
Add(new Line(Color.DarkGray, -180, "Level -1"));

Add(new Plot(Color.Green, PlotStyle.Bar, "UpCCI"));
Add(new Plot(Color.Red, PlotStyle.Bar, "DnCCI"));
Add(new Plot(Color.Brown, PlotStyle.Bar, "UnchCCI"));
CalculateOnBarClose = false;
Overlay = false;
PriceTypeSupported = false;
}

/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Use this method for calculating your indicator values. Assign a value to each
// plot below by replacing 'Close[0]' with your own formula.
if (Close[0] > Open[0]) UpCCI.Set(CCI(45)[0]);
if (Close[0] < Open[0]) DnCCI.Set(CCI(45)[0]);
if (Close[0] == Open[0]) UnchCCI.Set(CCI(45)[0]);
}

NinjaTrader_Ray
08-03-2007, 09:05 AM
The first line of code should be:

If (CurrentBar < 1)
return;

if (CCI(45)[0] > CCI(45)[1]) UpCCI.Set(CCI(45)[0]);

Jibu V
08-03-2007, 09:14 AM
The first line of code should be:

If (CurrentBar < 1)
return;

if (CCI(45)[0] > CCI(45)[1]) UpCCI.Set(CCI(45)[0]);

Thanks for your response Ray. I input the code as you described and it gives me an error stating that I need a ';' after the line ' If (CurrentBar < 1)'. What should I do here...?

NinjaTrader_Ray
08-03-2007, 09:21 AM
The code I provided is a sample of the concept and to demonstrate how to access the CCI indicator value of the current bar and compare to the prior bar. You will need to take it from that point.

Jibu V
08-03-2007, 09:25 AM
I adjusted the code as shown below, but I still receive the ';' error. Could you please point me in the right direction with this? Thank you..

If (CurrentBar < 1)
return;
if (CCI(45)[0] > CCI(45)[1]) UpCCI.Set(CCI(45)[0]);
if (CCI(45)[0] < CCI(45)[1]) DnCCI.Set(CCI(45)[0]);
if (CCI(45)[0] = CCI(45)[1]) UnchCCI.Set(CCI(45)[0]);

NinjaTrader_Dierk
08-03-2007, 09:32 AM
Likely should read:
if (CCI(45)[0] == CCI(45)[1])

Also: clicking on the error message brings you to the erroneous code line.

Jibu V
08-03-2007, 09:36 AM
Thanks Dierk. I did change that to == also, but it seems to be pointing the error message to the 'If (CurrentBar < 1)' line. The message is '; expected'

NinjaTrader_Dierk
08-03-2007, 09:39 AM
Likely needs to be:
if (CurrentBar < 1)
Note: "if" and not "If".

You might consider getting in touch with a NinjaScript consultant: http://www.ninjatrader-support.com/v...ght=consultant (http://www.ninjatrader-support.com/vb/showthread.php?t=2634&highlight=consultant)

Jibu V
08-03-2007, 09:42 AM
Likely needs to be:
if (CurrentBar < 1)
Note: "if" and not "If".

You might consider getting in touch with a NinjaScript consultant: http://www.ninjatrader-support.com/v...ght=consultant (http://www.ninjatrader-support.com/vb/showthread.php?t=2634&highlight=consultant)
That fixed the problem! Thanks Dierk!

Bondi9999
09-24-2010, 06:52 AM
Hi,

Would you mind sharing the indicator. I am after such a CCI but I have no idea where to begin regarding coding.

Best regards,

NinjaTrader_Bertrand
09-24-2010, 07:07 AM
Have you already looked at those scripts related from our sharing section?

http://www.ninjatrader.com/support/forum/local_links_search.php?action=show&literal=1&search=CCI&desc=1

At least they would give you a good starting point for yours hopefully.