Announcement

Collapse
No announcement yet.

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.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    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.
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment

        Latest Posts

        Collapse

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