Announcement

Collapse
No announcement yet.

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.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    67 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    95 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    53 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    108 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    63 views
    0 likes
    Last Post PaulMohn  
    Working...
    X