I cannot seem to get rid of this vertical line when my indicator starts plotting. Run out of ideas with OnRender and other attempts. Any thoughts?
Hi @cochenuo, One option is to use the Reset() method of the Series object that is probably “Values[0]” (note the plural “Values”, not “Value[0]”) in your indicator on the first data point if your indicator only has one data series.
So for the first data point of your indicator only (if the problem is only with the first data point, and there is not a horizontal line going from the vertical line to the left above where your screenshot ends), the one with the bad Y-Value, you could call this line of code:
Values[0].Reset();
Here is the documentation on this method, which also lines to the help doc for the related method called “IsValidDataPoint()”:
https://ninjatrader.com/support/helpGuides/nt8/reset.htm
When you do this for a data point, the plot won’t be visible.
Here is a contrived example that shows how to not plot an indicator on every 50th price bar. A dot is drawn on the price bar before the bar where the indicator is not plotted so it is easy to identify the bars with the unplotted indicator.
You can do the same kind of “Reset()” logic, but only for the first data point (or first data points) of your indicator until the first bar whose value is a real, valid value.
protected override void OnBarUpdate()
{
if (CurrentBar % 50 == 0)
Draw.Dot(this, "IndicatorDotEvery50Bars" + CurrentBar.ToString(System.Globalization.CultureInfo.InvariantCulture), true, 0, Highs[0][0], Brushes.Aqua, false);
Value[0] = Input[0];
if (CurrentBar % 50 == 1)
Values[0].Reset();
}
Addendum: Here is a screenshot of how the contrived indicator I described above does not plot on a price bar after the price bar with the dot:
@Quagensia - thanks for the help. Worked perfectly. My next work is to be able to click on a price bar and have the AVWAP created from that point. This is useful for creating a AVWAP from a new event like a Fed meeting or data release. Thanks!
That’s great to hear @cochenuo, you are most welcome. An anchored or resettable VWAP is definitely useful. I like the idea of being able to click on a price bar to interactively set a new anchor.