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

Convert DownloadMarginsFromInteractiveBrokersWeb indicator to NT8

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

    Convert DownloadMarginsFromInteractiveBrokersWeb indicator to NT8

    Hello,

    on futures.io I found an indicator from user asfax that should display IB margins. I tried to convert it to NT8 (I attach both versions, the original and my amateur attempt). I have successfully compiled the indicator, but it throws me an error message:
    "Indicator 'DownloadMarginsFromInteractiveBrokersWebNT8': Error on calling 'OnStateChange' method: 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."

    I'm a bit stumped because it seems to me that the indicator doesn't actually need any bars to function, so I have no idea how to proceed. Thanks in advance for the help.
    emuns
    Attached Files

    #2
    Hello emuns,

    Thanks for your post.

    "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."

    This error message means that an invalid index is being used in the script. A more simple example using one series would be on bar 5 you check for 6 BarsAgo. There are not yet 6 bars so the CurrentBar minus 6 would be a negative number or a non-existent bar.

    Debugging prints should be added to the script that prints out the index values that are being accessed in the script to see what the highest index is.

    Below is a link to a forum post that demonstrates how to use prints to understand behavior.
    https://ninjatrader.com/support/foru...121#post791121

    Once you determine what the highest index being accessed is, you could add a CurrentBar condition at the top of the OnBarUpdate() method in the script to make sure you have enough bars in the data series you are accessing.

    Note that the index cannot be higher than the CurrentBar number of the data series you are accessing or this error would occur.

    See this help guide page for more information about making sure you have enough bars: https://ninjatrader.com/support/help...nough_bars.htm

    Please let me know if I may assist further.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Hello Brandon,

      thank you for your answer. Print statements shows that the problematic part is as follows:

      // trim the string to contain only the desired symbol data (symbol + 4x margins + some html tags)
      webData = webData.Substring(webData.LastIndexOf(webSymbol)); // cut everything before the last occurrence of the desired symbol
      webData = webData.Substring(0, webData.IndexOf(webCurrency)); // cut everything after the first occurrence of the currency (inclusive) that follows the last occurrence of the desired symbol​

      But to be true I have no idea how to fix it...?!

      Comment


        #4
        Hello emuns,

        Thanks for your note.

        How did you confirm that this is in fact the cause of the error?

        What index value is printing to the Output window when you added prints to this section of code?

        Did you add prints for the loop in the script that prints out the index being used for the loop? If so, what value prints to the Output window?

        Note that using custom C# logic to access html webpages in a custom NinjaScript goes beyond the level of support we would be able to provide you with in the Support department.

        I look forward to assisting further.
        Brandon H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by TraderBCL, Today, 04:38 AM
        2 responses
        10 views
        0 likes
        Last Post TraderBCL  
        Started by martin70, 03-24-2023, 04:58 AM
        14 responses
        105 views
        0 likes
        Last Post martin70  
        Started by Radano, 06-10-2021, 01:40 AM
        19 responses
        606 views
        0 likes
        Last Post Radano
        by Radano
         
        Started by KenneGaray, Today, 03:48 AM
        0 responses
        4 views
        0 likes
        Last Post KenneGaray  
        Started by thanajo, 05-04-2021, 02:11 AM
        4 responses
        471 views
        0 likes
        Last Post tradingnasdaqprueba  
        Working...
        X