Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Exception in Ninjatrader core code

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

    Exception in Ninjatrader core code

    Hello,

    I've run the debugger on this many times in a few different pieces of code.

    If you use a line such as the following in OnRender, eventually, you will get an index not found exception

    PHP Code:
    stationaryXpos = chartControl.GetXByBarIndex(ChartBars, !Bars.IsTickReplay ? ChartBars.FromIndex : fbtp); // This occasionally causes an exception, yet is OK when in break mode! 
    
    If you run the code in a debugger, NT will break on the exception. Drilling down, the exception comes from NT8 internal code, not a third party (or mine). What I mean by OK in break mode, is you can print the content of every single variable in that line of code in the immediate window and NOT get any exceptions.

    So, the question is, what is unsafe about using this code in OnRender? Is it not valid to access the Bars or ChartBars objects inside OnRender? (That is where I see the issue quite regularly). Obviously, I am unable to debug this further as the exception is in the NT code, which is not available to me. Wrap it in a Try /Catch and ignore the event when it randomly occurs, and all is well, but that really is not a very good solution.

    Thanks.
    Last edited by pjsmith; 07-22-2023, 05:19 AM.

    #2
    Hello pjsmith,

    Thanks for your post.

    Please send me a simple reduced exported script that demonstrates the behavior you are reporting and send me the exact steps and settings you use to reproduce the behavior.

    I will use the example script and steps you detail to try and reproduce the behavior on my end and investigate this matter further.

    Note that a reduced copy refers to a copy of the script that contains the minimum amount of code needed to reproduce the issue and no third-party scripts. All other code is commented out or removed. To create a copy of your script to modify, open a New > NinjaScript Editor, select your script, right-click in the Editor, select 'Save as', name the script, and click OK.​

    To export a NinjaScript, go to Tools > Export > NinjaScript AddOn.

    Exporting: https://ninjatrader.com/support/help...scriptAsSource Files
    <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
    647 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    368 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    108 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    571 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    573 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X