View Full Version : Limiting a Plot
08-24-2007, 09:30 PM
Is there a way I can limit the plot of say an SMA to display for just the last 20 bars of the chart?
If so, would someone please post some sample code that would allow this.
08-24-2007, 11:20 PM
This is not supported by default. There probably is a way to custom code it in NinjaScript, but unfortunately we don't have a sample a hand.
08-25-2007, 06:21 PM
rt-trader you can add this code at the start of the OnBarUpdate() section of the indicator code as a simple workaround. Now this code does not completely do what you are trying to achieve because it does not automatically remove old plotted points. If you hit F5 and refresh the chart it will remove old points though.
BarsRequired = Bars.Count-20;Edit: To achieve the exact behavior you wanted please check out the reference sample I have added. The magic is done in the Plot Override section. Basically what is happening is I am creating a Path object that traces only the SMA value for the last 20 bars. Then I tell it to draw that path and voila you have an indicator that only draws for the last 20 bars.