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 NullPointStrategies, Today, 05:17 AM
    0 responses
    49 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    126 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    67 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    42 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    46 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X