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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    45 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    21 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    31 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    50 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    42 views
    0 likes
    Last Post CarlTrading  
    Working...
    X