Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

GetCurrentAsk error

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

    GetCurrentAsk error

    I have trouble with using GetCurrentAsk in OnMarketData.
    I have a simple Indicator that must calculate current Ask Price from two instruments (f.e. GC and CL).

    My code is:
    Code:
    protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
     {
     if(marketDataUpdate.MarketDataType == MarketDataType.Last)
     {
    curAsk = GetCurrentAsk(0);
    nextAsk = GetCurrentAsk(0);
    }
    }
    Also I added secondary Series in State.Configure.

    In OnBarUpdate method I have only:
    Print("Cur Ask" + curAsk);
    Print("Next Ask" + nextAsk);


    When I'm trying to apply this indicator on the chart i have an error
    Indicator 'askNext': Error on calling 'OnMarketData' method on bar -1: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

    How to fix this? Thank you!

    #2
    Hello YevhenShynkarenko,

    The error is likely coming because you are trying to use bar data before it is available, GetCurrentAsk and Bid would not be expected to be used in this override as it already provides that data.

    Is there a reason why you are not just using the Ask event from OnMarketData here? You are assigning the curAsk variable, you could do the same logic by using the data the override provides. The BarsInProgress can be used to determine what data was sent into the override to further filter setting your variables. Here is a quick print to highlight that:


    Code:
    protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
    {    
        if (marketDataUpdate.MarketDataType == MarketDataType.Ask)
            Print(string.Format("Ask BIP= {0} Price= {1} ", BarsInProgress, marketDataUpdate.Price));  
    }

    I look forward to being of further assistance.

    Comment


      #3
      Originally posted by NinjaTrader_Jesse View Post
      Hello YevhenShynkarenko,

      The error is likely coming because you are trying to use bar data before it is available, GetCurrentAsk and Bid would not be expected to be used in this override as it already provides that data.

      Is there a reason why you are not just using the Ask event from OnMarketData here? You are assigning the curAsk variable, you could do the same logic by using the data the override provides. The BarsInProgress can be used to determine what data was sent into the override to further filter setting your variables. Here is a quick print to highlight that:


      Code:
      protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
      {
      if (marketDataUpdate.MarketDataType == MarketDataType.Ask)
      Print(string.Format("Ask BIP= {0} Price= {1} ", BarsInProgress, marketDataUpdate.Price));
      }

      I look forward to being of further assistance.
      Thank you! It works great! One more question - can I get this data historical? Now it shows me only realtime data (for history it shows always 0). If yes, how to do this? Thanks.
      P.s.: i'm using Tick Replay enabled.

      Comment


        #4
        Hello YevhenShynkarenko,

        Technically no but you can use the TickReplay to simulate this. The GetCurrentAsk/Bid methods also cannot be used historically, they just return the Close price if you do use them there.

        When using TickReplay you need to develop your code specifically for that purpose, TickReplay cannot just be enabled and expected to work. https://ninjatrader.com/support/help...ick_replay.htm

        With TickReplay you are observing snapshots of the ask/bid at the time of the Last event so your logic needs to change to using the Last event and then determining volume requires the logic as shown in the help guide.


        I look forward to being of further assistance.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        599 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        344 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        103 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        558 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        557 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X