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

OnBarUpdate error

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

    OnBarUpdate error

    Hi
    I am doing some testing and looking at volume.
    The code below is a tiny modification of your example script blockvolume .


    private void CalculateMyBlockVolume(bool forceCurrentBar)
    {
    bool inTransition = State == State.Realtime && BarsArray[1].Count - 1 - CurrentBars[1] > 1;
    int whatBar = State == State.Historical || inTransition || Calculate != Calculate.OnBarClose || forceCurrentBar ? CurrentBars[1] : Math.Min(CurrentBars[1] + 1, BarsArray[1].Count - 1);

    if ((Instrument.MasterInstrument.InstrumentType == Cbi.InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume((long)BarsArra y[1].GetVolume(whatBar)) : BarsArray[1].GetVolume(whatBar)) >= BlockSize)
    {
    if (!inTransition && hasCarriedOverTransitionTick && !forceCurrentBar && Calculate == Calculate.OnBarClose)
    CalculateMyBlockVolume(true);

    hasCarriedOverTransitionTick = inTransition;
    blockValue += CountType == CountType.Volume ? (Instrument.MasterInstrument.InstrumentType == Cbi.InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume((long)BarsArra y[1].GetVolume(whatBar)) : BarsArray[1].GetVolume(whatBar)) : 1;



    if(Volume[0] != 0)// I tried also changing this to != null
    {
    mystr = Volume[0].ToString();
    mystr.Remove(2);
    Print(Volume[0].ToString() + " " + mystr);

    }

    Error on calling 'OnBarUpdate' method on bar -1: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

    Can you assist with where I am going wrong with this?
    If i change mystr.Remove to (1) - it works but doesn't alter the no of digits in the Print stmt.?

    edit - also what is bar -1; I am unsure how that can exist?
    Last edited by Mindset; 06-24-2020, 01:15 AM.

    #2
    Hello Mindset,

    Thanks for the post.

    The error is likely because of the length of the string, you are trying to remove starting at index 2, if the string does not have enough indexes for that it would fail. What specifically was the intention with the Remove(2)?

    The -1 means that happened before a primary bar processed. The current bar starts at -1 and will be 0 on the first processed bar. The logic is being called from the secondary series and likely had a problem before the primary bar processed.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Tin34, Today, 03:30 AM
    2 responses
    20 views
    0 likes
    Last Post Tin34
    by Tin34
     
    Started by sastrades, Yesterday, 09:59 AM
    2 responses
    33 views
    0 likes
    Last Post brucerobinson  
    Started by ETFVoyageur, Today, 12:52 AM
    1 response
    17 views
    0 likes
    Last Post Leeroy_Jenkins  
    Started by lollers, Today, 03:26 AM
    0 responses
    12 views
    0 likes
    Last Post lollers
    by lollers
     
    Started by aliyahany, Today, 03:16 AM
    0 responses
    4 views
    0 likes
    Last Post aliyahany  
    Working...
    X