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 DawnTreader, Yesterday, 05:58 PM
    2 responses
    12 views
    0 likes
    Last Post DawnTreader  
    Started by quicksandatl, Today, 11:11 AM
    1 response
    5 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Started by OllieFeraher, Today, 11:14 AM
    1 response
    2 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by aman jain, 10-01-2020, 09:25 PM
    3 responses
    293 views
    0 likes
    Last Post Legiboka  
    Started by reynoldsn, Today, 07:23 AM
    5 responses
    12 views
    1 like
    Last Post NinjaTrader_Gaby  
    Working...
    X