Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Error on calling OnBarUpdate method on bar 0

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

  • Metal15
    replied
    Thank you very much sir.

    Leave a comment:


  • RJay
    replied
    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];

    Leave a comment:


  • Metal15
    started a topic Error on calling OnBarUpdate method on bar 0

    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;
    }

    }
    }
    }

Latest Posts

Collapse

Topics Statistics Last Post
Started by StockTrader88, 03-06-2021, 08:58 AM
44 responses
3,967 views
3 likes
Last Post jhudas88  
Started by rbeckmann05, Today, 06:48 PM
0 responses
4 views
0 likes
Last Post rbeckmann05  
Started by rhyminkevin, Today, 04:58 PM
4 responses
55 views
0 likes
Last Post dp8282
by dp8282
 
Started by iceman2018, Today, 05:07 PM
0 responses
6 views
0 likes
Last Post iceman2018  
Started by lightsun47, Today, 03:51 PM
0 responses
8 views
0 likes
Last Post lightsun47  
Working...
X