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

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.

    JesseNinjaTrader Customer Service

    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.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Mizzouman1, Today, 07:35 AM
        0 responses
        1 view
        0 likes
        Last Post Mizzouman1  
        Started by i019945nj, 12-14-2023, 06:41 AM
        6 responses
        66 views
        0 likes
        Last Post i019945nj  
        Started by aa731, Today, 02:54 AM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by BarzTrading, Today, 07:25 AM
        0 responses
        3 views
        0 likes
        Last Post BarzTrading  
        Started by ruudawakening, Today, 12:58 AM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X