PDA

View Full Version : Moving Average with gaps in it?


noevictorian
11-02-2009, 10:40 PM
How can I turn a plot on and off from drawing based on conditions. I would like to have a moving average line plot... then if things don't qualify certain tests, I'd like to stop the plot in its tracks from drawing. If the tests pass in 5 bars, the plot would show up again without connecting the two smoothed lines. Make sense?

It would basically look like a moving average with a gap in it.

noevictorian
11-02-2009, 10:53 PM
Can it be as simple as just writing a "return;" step based on a condition?

That seems easy but is that the right way to do it? Or is there another way to assign a blank to the plot rather than exiting the script entirely?

mrlogik
11-03-2009, 05:06 AM
neo,

This depends on how you are drawing the moving average.

If you are doing something like, MaPlot.Set(value), simply don't do this for the bar you don't want to plot.

If you can give a little code on the average I may be able to help a little more.

NinjaTrader_Bertrand
11-03-2009, 05:23 AM
Are you looking for something like this? Only plotting the SMA if we have an ADX > 20 -


protected override void OnBarUpdate()
{
if (ADX(Input, 14)[0] > 20)
Plot0.Set(SMA(Input, 14)[0]);
}

noevictorian
11-05-2009, 10:10 PM
Yes and thanks. I was assuming it'd be more difficult. I'm a convert from Thinkorswim and in that scripting language you have to declare the plot as a nan (not a number) value for any bars that don't meet your criteria.

This couldn't be easier in NinjaScript - which I'm loving by the way.

thanks again!