Indicator ‘DeltaVolume’: Error on calling ‘OnBarUpdate’ method on bar 0: ‘AddPlot’ cannot be called from this state. Please see the Help Guide Article.
I have tried a number of solutions from the help guid and forum and nothing seems to work.
###########
namespace NinjaTrader.NinjaScript.Indicators
{
public class DeltaVolume : Indicator
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "DeltaVolume";
Calculate = Calculate.OnEachTick;
IsOverlay = false;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLin es = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
//Disable this property if your indicator requires custom values that cumulate with each new market data event.
//See Help Guide for additional information.
}
else if (State == State.Configure)
{
}
}
protected override void OnBarUpdate()
{
//Add your custom indicator logic here.
double currentBidVolume;
double currentAskVolume;
currentBidVolume = GetCurrentBidVolume();
currentAskVolume = GetCurrentAskVolume();
// Calculate the bid/ask volume delta //
double volumeDelta = (currentBidVolume - currentAskVolume) / (currentBidVolume + currentAskVolume);
// Check if the volume delta is over 25% or below -25% //
{
// Check if the volume delta is over 25% or below -25% //
if (volumeDelta > 0.25)
{
// Plot a green bar //
AddPlot(new Stroke(Brushes.LawnGreen, 1), PlotStyle.Bar, "Green");
}
else if (volumeDelta < -0.25)
{
AddPlot(new Stroke(Brushes.Red, 1), PlotStyle.Bar, "Red");
}
else
{
// Don't plot a bar //
AddPlot(new Stroke(Brushes.Transparent, 1), PlotStyle.Bar, "None");
}
}
}
Comment