View Full Version : Color Stochastic/2-line Indicator
jeremymgp
12-18-2007, 10:35 PM
Hello,
Does anyone have a Color Stochastic, any colored 2-line indicator, or a tutorial for coloring indicators with more than one line? Color's a huge help for determining "has that indicator really turned?" and I'm going bananas trying to convert the Sample color SMA template. Thanks for your help,
Cheers,
Jeremy
NinjaTrader_Josh
12-19-2007, 01:14 AM
Check out this reference sample: http://www.ninjatrader-support.com/vb/showthread.php?t=3227
There is also a similar tutorial here: http://www.ninjatrader-support.com/HelpGuideV6/helpguide.html?Overview25
jeremymgp
12-19-2007, 08:29 AM
Hi,
Thanks for the tutorials, I've tried to hash the two together & set up my 3 Plot lines for the rising/neutral/falling D-line but the indicator is full of errors.
In lines like
"DRisingPlot.Set(1, Stochastics(Period)[1]);"
I've changed it to
"DRisingPlot.Set(1, Stochastics(K, D, Smooth)[1]);"
but this is a guess & I only need the D-line colored.
protected override void Initialize()
{
Add(new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Line, "DRising"));
Add(new Plot(Color.FromKnownColor(KnownColor.Yellow), PlotStyle.Line, "DNeutral"));
Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "DFalling"));
Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "KLine"));
Add(new Line(Color.FromKnownColor(KnownColor.DarkOrchid), 80, "Eightyline"));
Add(new Line(Color.FromKnownColor(KnownColor.DarkOrchid), 20, "Twentyline"));
CalculateOnBarClose = true;
Overlay = false;
PriceTypeSupported = false;
}
protected override void OnBarUpdate()
{
DRising.Set(Close[0]);
DNeutral.Set(Close[0]);
DFalling.Set(Close[0]);
KLine.Set(Close[0]);
if (CurrentBar < 1)
return;
if (Rising(Stochastics(K, D, Smooth)))
{
DRisingPlot.Set(1, Stochastics(K, D, Smooth)[1]);
DRisingPlot.Set(Stochastics(K, D, Smooth)[0]);
}
else if (Falling(Stochastics(K, D, Smooth)))
{
DFallingPlot.Set(1, Stochastics(K, D, Smooth)[1]);
DFallingPlot.Set(Stochastics(K, D, Smooth)[0]);
}
else
{
DNeutralPlot.Set(1, Stochastics(K, D, Smooth)[1]);
DNeutralPlot.Set(Stochastics(K, D, Smooth)[0]);
}
}This is all over the place but I'm learning till I get this, any pointers much appreciated,
Thanks,
Jeremy
NinjaTrader_Josh
12-20-2007, 01:29 AM
Did you add the plots into the Properties? Check out the Properties section in the reference sample. You will need those.
jeremymgp
12-20-2007, 07:34 AM
Thanks Josh, I entered the plots into the Indicator wizard, but apart from that the only "Properties" section I can find is the large "Properties" section at the very bottom of the code which is by default hidden from the user. As I understand it the samples make no reference to editing this area directly. My misunderstanding, thanks for your patience,
Jeremy
NinjaTrader_Josh
12-20-2007, 03:10 PM
You will need to expand that big Properties section. If you don't mind you could post up the current rendition of your code. After I see what you have right now I can provide you with some pointers to get you going. Cheers.
jeremymgp
12-29-2007, 09:19 AM
Hi Josh,
Thanks for the help, good news is I've finally managed to make a smoothed StochRSI and plot it in color. Before I was looking at the entire indicator code, but then discovered the [+] buttons at the side of the code to popup the Properties section only, so I've made some progress.
Only thing now is in my color version the smooth line is not plotted, it's the StochRSI line that is both plotted and colored.
I'd like the smooth line to be plotted and colored, and StochRSI line plotted only.
Here's my code:
namespace NinjaTrader.Indicator
{
[Description("Sample SMA plotted with three colors.")]
[Gui.Design.DisplayName("StochRSI_SmoothedColor")]
public class StochRSI_SmoothedColor : Indicator
{
#region Variables
private int period = 14;
private int smooth = 4;
#endregion
protected override void Initialize()
{
Add(new Plot(Color.Green, "StochRSI"));
Add(new Plot(Color.LimeGreen, PlotStyle.Line, "Rising"));
Add(new Plot(Color.Red, PlotStyle.Line, "Falling"));
Add(new Plot(Color.Yellow, PlotStyle.Line, "Neutral"));
CalculateOnBarClose = true;
Overlay = false;
}
protected override void OnBarUpdate()
{
if (CurrentBar < 1)
return;
if (Rising(StochRSI_Smoothed(Period, Smooth)))
{
RisingPlot.Set(1, StochRSI_Smoothed(Period, Smooth)[1]);
RisingPlot.Set(StochRSI_Smoothed(Period, Smooth)[0]);
}
else if (Falling(StochRSI_Smoothed(Period, Smooth)))
{
FallingPlot.Set(1, StochRSI_Smoothed(Period, Smooth)[1]);
FallingPlot.Set(StochRSI_Smoothed(Period, Smooth)[0]);
}
else
{
NeutralPlot.Set(1, StochRSI_Smoothed(Period, Smooth)[1]);
NeutralPlot.Set(StochRSI_Smoothed(Period, Smooth)[0]);
}
}
#region Properties
[Browsable(false)]
[XmlIgnore()]
public DataSeries RisingPlot
{
get { return Values[1]; }
}
[Browsable(false)]
[XmlIgnore()]
public DataSeries FallingPlot
{
get { return Values[2]; }
}
[Browsable(false)]
[XmlIgnore()]
public DataSeries NeutralPlot
{
get { return Values[3]; }
}
[Description("Numbers of bars used for calculations")]
[Category("Parameters")]
public int Period
{
get { return period; }
set { period = Math.Max(1, value); }
}
[Description("Smoothing period for SMA")]
[Category("Parameters")]
public int Smooth
{
get { return smooth; }
set { smooth = Math.Max(1, value); }
}
#endregion
}
}
Many thanks for your help and Happy New Year :),
Kind Regards,
Jeremy
NinjaTrader_Josh
12-29-2007, 01:14 PM
Hi jeremymgp,
I am unfamiliar with the implementation of StochRSI since it is probably a custom indicator you have.
When you do the .Set stuff you want it done on the plot you want. So for instance (I am just guessing what it is for your indicator), if you wanted to plot the smooth line you might do something like this:
RisingPlot.Set(StochRSI_Smoothed(Period, Smooth).Smooth[0])I am assuming to access the smooth line you use .Smooth for your indicator.
Now to just simply plot StochR_Smoothed you need to add another Values set in the Properties.
[Browsable(false)]
[XmlIgnore()]
public DataSeries StochRSmooth
{
get { return Values[0]; }
}Then now in your OnBarUpdate() you want to do:
StochRSmooth.Set(StochRSI_Smoothed(Period, Smooth)[0]);
jeremymgp
01-04-2008, 10:05 AM
Yippee, looks like I've done it. Only weird thing is when I save the indicator, copy it into a zip file, then try to import the zipped indicator, I can't get the indicator to show in the:
Control Center > Tools > Edit NinjaScript > Indicator box.
However if I right click a chart and click Indicators, I can select the indicator fine.
Just don't want to distribute this if the zip file isn't 100% OK.
Thanks,
Jeremy
NinjaTrader_Ray
01-04-2008, 10:15 AM
To distribute...
http://www.ninjatrader-support.com/HelpGuideV6/Export1.html
jeremymgp
01-05-2008, 07:10 AM
Hello everyone,
Please find attached a color Stochastics indicator, it seems several people have shown interest in this and it also serves as a handy template for anyone wanting to color code indicators with more than one plot.
A huge thanks to Ray and Josh for their prompt and accurate response to my questions, hope this helps and good luck trading everyone,
Kind Regards,
Jeremy
NinjaTrader_Josh
01-05-2008, 01:27 PM
Thanks for the contribution jeremymgp. We appreciate it.