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

Indicator fails to load apparently randomly

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

    Indicator fails to load apparently randomly

    I made a relatively simple moving average indicator using CMO and ATR and the darn thing loads most of the time but not all the time under the same operating conditions.

    If it doesn't load, I can sometimes it to work I reload NJ8, or increase or decrease the days to load in the data series, or change the payback day on market replay. Other times it will work in the same situation. Also, sometimes it will work on one chart but not another, and other times it works on both, again, under the same conditions.

    Can anyone help?

    #2
    Hello Tagliareni,

    Thanks for your post.

    Do you see any error messages occur in the Log tab of the Control Center when the indicator is not working as expected?

    Ultimately, prints would need to be added to the script to understand how the script is behaving and processing logic.

    In the script, add prints (outside of any conditions) that print the values of every variable used in every condition along with the time of that bar. Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

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

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

    Comment


      #3
      Thank you for another awesome rocking reply. I'm digging into what you wrote.

      The Log says:
      • Time and date, Default, Indicator". Error on calling 'CalculateMinMax' on bar 43428: The calculation results in unrenderable values.
      • And an additional default at a different time and date: Indicator 'XXX'. Error on calling 'OnBarUpdate' method on bar 288: You are accessing an index with a value that is invalid since it is out-of-range.
      I appreciate your work.

      Comment


        #4
        Hello Tagliareni,

        Thanks for your note.

        "Error on calling 'OnBarUpdate' method on bar 288: You are accessing an index with a value that is invalid since it is out-of-range."

        This error will be displayed if you try to use a BarsAgo value when it is not valid. 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.

        A CurrentBar check could be used in your indicator's logic to ensure that a certain number of bars have processed before the indicator begins calculation.

        See the help guide documentation below for more information and sample code.
        CurrentBar - https://ninjatrader.com/support/help...currentbar.htm
        CurrentBars - https://ninjatrader.com/support/help...urrentbars.htm
        Make sure you have enough bars - https://ninjatrader.com/support/help...nough_bars.htm

        Alternatively, you would need to locate where exactly in the script this is failing by doing more targeted debugging with Prints.

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

        "Error on calling 'CalculateMinMax' on bar 43428: The calculation results in unrenderable values."

        The error would suggest an invalid value is being passed to a plot or one of the drawing objects being used in your script.

        You could refer to this post where a user was getting the same error from dividing by zero on accident, this could be the source of the problem in your script.

        When working with any issue, it is important to take steps to isolate the issue so that the exact line causing the behavior can be found. This is a process of elimination and a process of debugging by adding prints.

        First, it's great to create a copy of the script so that the original work is kept safe. Once the copy is created, the copy can be modified in any way without losing the original work.

        Here is a link to a video that demonstrates making a copy of script: https://www.youtube.com/watch?v=BA0W...utu.be&t=8m15s

        The next step is to start commenting out code. Its helpful to think about when the error is occurring to target areas, and comment code from everywhere else quickly. If at any point after removing some code, the error stops, add the last removed item back.

        If the error is occurring while the script is loading, the issue is likely somewhere in OnStateChange(). In this situation its best to remove any logic in OnBarUpdate, remove any custom methods and classes, and remove as may properties as possible, while still being able to reproduce the error.

        If the error is occurring when saving a template, the issue is likely with a private or public variable declaration. First, remove all logic leaving the variable declarations behind. (Empty State.Configure, State.Dataloaded, State.Historical, OnBarUpdate, OnMarketData, and remove any custom methods.) Then start removing the variables one by one and testing until the error stops. When the error stops add the last removed item back. Ensure that this item is private or property serialized or using the Browsable(false) attribute. (More about the Browsable attribute below)

        If the error only occurs while the strategy is trading, this is likely a run time method. For this its best to use prints to understand the behavior.

        Let us know if we may assist further.
        Brandon H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CortexZenUSA, Today, 12:53 AM
        0 responses
        2 views
        0 likes
        Last Post CortexZenUSA  
        Started by CortexZenUSA, Today, 12:46 AM
        0 responses
        1 view
        0 likes
        Last Post CortexZenUSA  
        Started by usazencortex, Today, 12:43 AM
        0 responses
        5 views
        0 likes
        Last Post usazencortex  
        Started by sidlercom80, 10-28-2023, 08:49 AM
        168 responses
        2,266 views
        0 likes
        Last Post sidlercom80  
        Started by Barry Milan, Yesterday, 10:35 PM
        3 responses
        13 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Working...
        X