Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Getting ArgumentOutOfRangeException for OrderFlowCumulativeDelta

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

    Getting ArgumentOutOfRangeException for OrderFlowCumulativeDelta

    Hello. I am adding support for the Cumulative Delta indicator into my bot, it seems to be the same setup as VWAP which I have working without issue. But for the Cumulative Delta, I'm getting the below stacktrace.

    Code:
    System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index
    at System.ThrowHelper.ThrowArgumentOutOfRangeExceptio n(ExceptionArgument argument, ExceptionResource resource)
    at NinjaTrader.NinjaScript.Series`1.get_Item(Int32 barsAgo)
    at NinjaTrader.NinjaScript.Strategies.TradingBot.Init ()
    at NinjaTrader.NinjaScript.Strategies.TradingBot.OnBa rUpdate()
    Strategy 'Trading Bot': Error on calling 'OnBarUpdate' method on bar -1:
    Below is the relevant snippets of the code. They basically follow the example in your docs and is the same as I'm using for VWAP which didn't have this issue. Hopefully it's a simple fix of something I overlooked. Thanks!

    Configuring 1-tick data series.
    Code:
    ...
    else if (State == State.Configure) {
            AddDataSeries(Data.BarsPeriodType.Tick, 1);
    }
    ...
    Calling the sync code.
    Code:
    ...
    
    if (BarsInProgress == 1) {
            vwap.SyncVWAP();
            cumulativeDelta.SyncCumulativeDelta();
    }
    ...
    Sync code
    Code:
    ...
    public void SyncCumulativeDelta() {
            tradingBot.OrderFlowCumulativeDelta(tradingBot.BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0)
                    .Update(tradingBot.OrderFlowCumulativeDelta(tradin gBot.BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).BarsArray[1].Count - 1, 1);
    }
    ...
    Constructor
    Code:
    ...
    public CumulativeDelta(TradingBot tradingBot) {
            this.tradingBot = tradingBot;
            this.barsAgo = 0;
            UpdateDelta();
    }
    ...
    UpdateDelta. Exception is thrown when calling delta.DeltaOpen[barsAgo]
    Code:
    ...
    public void UpdateDelta() {
            OrderFlowCumulativeDelta delta = tradingBot.OrderFlowCumulativeDelta(tradingBot.BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0);
    
            if (delta != null) {
                    sessionDelta = new OHLC(
                            delta.DeltaOpen[barsAgo],[COLOR=#e74c3c] <-- Where exception is thrown.[/COLOR]
                            delta.DeltaHigh[barsAgo],
                            delta.DeltaLow[barsAgo],
                            delta.DeltaClose[barsAgo]);
            }
    }
    ...
    Last edited by _jb__; 02-16-2021, 11:55 AM.

    #2
    Hello, thanks for your post.

    I made a test script that's able to get the last 10 bars of the Cumulative Delta information. Please compare my example to what is being done in your test script to see why your script throws the exception.

    Please let me know if I can assist any further.
    Attached Files

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    88 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    134 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    68 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    119 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    69 views
    0 likes
    Last Post PaulMohn  
    Working...
    X