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 Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    605 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    351 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
    560 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    561 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X