Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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
    Chris L.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by aussugardefender, Today, 01:07 AM
    0 responses
    3 views
    0 likes
    Last Post aussugardefender  
    Started by pvincent, 06-23-2022, 12:53 PM
    14 responses
    238 views
    0 likes
    Last Post Nyman
    by Nyman
     
    Started by TraderG23, 12-08-2023, 07:56 AM
    9 responses
    384 views
    1 like
    Last Post Gavini
    by Gavini
     
    Started by oviejo, Today, 12:28 AM
    0 responses
    4 views
    0 likes
    Last Post oviejo
    by oviejo
     
    Started by pechtri, 06-22-2023, 02:31 AM
    10 responses
    125 views
    0 likes
    Last Post Leeroy_Jenkins  
    Working...
    X