View Full Version : Custom Plot Colours for SMA
clippertm
02-21-2010, 08:50 PM
Hello,
Could anyone refer me to a tutorial for a custom plot colour simple moving average, with the following conditions:
if sma[0] > close[0] then plot green
if sma[0] < close[0] then plot red
Many thanks,
NinjaTrader_Bertrand
02-22-2010, 02:57 AM
Welcome to our forums - you can modify the conditions used to color the SMA in this reference sample we have - http://www.ninjatrader-support2.com/vb/showthread.php?t=3227
Jaylock
03-29-2010, 02:46 PM
This Custom Plot was applied to a SMA. Can it be possible to use a Linear Regression line instead.
NinjaTrader_Josh
03-29-2010, 02:52 PM
You can replace it with any indicator you want. The sample only shows you the framework you can employ to achieve what you want.
Thing to note about Linear Regression is that it can look different on every single bar so you will need to specify in your code exactly what you want in terms of values for it.
Jaylock
03-29-2010, 08:20 PM
Thanks for your reply. The Linear regression line referred to is a Ninja installed indicator called LinReg. My knowledge of how to do this is quite limited. Could you refer me to instructions for this purpose
NinjaTrader_Bertrand
03-30-2010, 04:03 AM
Jaylock, you would need to make a copy of the download SampleMultiColoredPlot indicator using the SMA per default.
The modify the calls it's using (SMA) to use the LinearRegression, so to start with a snippet right into the code you would need to use -
// Plot green if the LinearRegression is rising
// Rising() returns true when the current value is greater than the value of the previous bar.
if (Rising(LinReg(Period)))
{
// Connects the rising plot segment with the other plots
RisingPlot.Set(1, LinReg(Period)[1]);
// Adds the new rising plot line segment to the line
RisingPlot.Set(LinReg(Period)[0]);
}
Proceed for the other scenarios (Falling and Flat) and you should be there.