Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error on calling OnBarUpdate method on bar 0

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Error on calling OnBarUpdate method on bar 0

    Hello,

    i am new to ninja trader 8 and its programming platform.

    kindly guide me how to resolve this error.

    Error on calling OnBarUpdate method on bar 0 ,you are accessing an index with a value
    that is invalid since it is out of range.

    My aim is to get green vol bar when current candle close is above previous candle,
    and similarly red vol bar when candle close is below previous candle close and
    blue volume bar when above two conditions does not match.

    code :
    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class updownplot : Indicator
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Indicator here.";
    Name = "updownplot";
    Calculate = Calculate.OnBarClose;
    IsOverlay = false;
    DisplayInDataBox = true;
    DrawOnPricePanel = false;
    DrawHorizontalGridLines = true;
    DrawVerticalGridLines = true;
    PaintPriceMarkers = false;
    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.
    IsSuspendedWhileInactive = true;
    AddPlot(new Stroke(Brushes.Green, 2), PlotStyle.Bar, "UpVol");
    AddPlot(new Stroke(Brushes.Red, 2), PlotStyle.Bar, "DownVol");
    AddPlot(new Stroke(Brushes.Blue, 2), PlotStyle.Bar, "DVol");
    }
    else if (State == State.Configure)
    {
    }
    }

    protected override void OnBarUpdate()
    {
    //Add your custom indicator logic here.
    double curC = Close[0];

    double curP = Close[1];

    double curV = Volume[1];


    if (curC > curO )
    {
    UpVol[0]=curV;
    }
    else if (curC < curO )
    {
    DownVol[0]=curV;
    }

    else // (curC = curO)
    {
    DVol[0]=curV;
    }

    }
    }
    }

    #2
    Originally posted by Metal15 View Post
    Hello,

    i am new to ninja trader 8 and its programming platform.

    kindly guide me how to resolve this error.

    Error on calling OnBarUpdate method on bar 0 ,you are accessing an index with a value
    that is invalid since it is out of range.

    My aim is to get green vol bar when current candle close is above previous candle,
    and similarly red vol bar when candle close is below previous candle close and
    blue volume bar when above two conditions does not match.

    code :
    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class updownplot : Indicator
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Indicator here.";
    Name = "updownplot";
    Calculate = Calculate.OnBarClose;
    IsOverlay = false;
    DisplayInDataBox = true;
    DrawOnPricePanel = false;
    DrawHorizontalGridLines = true;
    DrawVerticalGridLines = true;
    PaintPriceMarkers = false;
    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.
    IsSuspendedWhileInactive = true;
    AddPlot(new Stroke(Brushes.Green, 2), PlotStyle.Bar, "UpVol");
    AddPlot(new Stroke(Brushes.Red, 2), PlotStyle.Bar, "DownVol");
    AddPlot(new Stroke(Brushes.Blue, 2), PlotStyle.Bar, "DVol");
    }
    else if (State == State.Configure)
    {
    }
    }

    protected override void OnBarUpdate()
    {
    //Add your custom indicator logic here.
    double curC = Close[0];

    double curP = Close[1];

    double curV = Volume[1];


    if (curC > curO )
    {
    UpVol[0]=curV;
    }
    else if (curC < curO )
    {
    DownVol[0]=curV;
    }

    else // (curC = curO)
    {
    DVol[0]=curV;
    }

    }
    }
    }
    Add code in bold.

    protected override void OnBarUpdate()
    {

    if( CurrentBar < 2 )return;

    //Add your custom indicator logic here.
    double curC = Close[0];

    double curP = Close[1];

    double curV = Volume[1];
    RJay
    NinjaTrader Ecosystem Vendor - Innovative Trading Solutions

    Comment


      #3
      Thank you very much sir.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      630 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      364 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      105 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      566 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      568 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X