Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Ridiculously Large values occur at only the first PERIOD number of bars

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

    Ridiculously Large values occur at only the first PERIOD number of bars

    Hello NT8,
    I am ignorant as to why ridiculous values always occur at the first Period length whenever I calculate Ratios?
    I hope I have not discovered some bug and I imagine it's more likely I am just being silly.

    For example in the image below indicator doesn't begin to count bars until its Period length with this line of code.
    Code:
        if (CurrentBar < (Period)) return;
    I this the best practice for initialization of values which will be used in ratios?


    Unfortunately a ridiculously large value of about 4 or 5 is achieved after the first PERIOD number of bars is reached.
    This ridiculously large skewing value occurs only for the very first PERIOD number of bars on the chart and then never occurs again.

    Thank all the experts of NT8 very much for verifying if this has happened to others or if this is some standard issue with a common solution for initialization.
    Last edited by DynamicTest; 05-16-2024, 12:03 AM.

    #2
    In many cases where FOR loops are used in the following format an incorrectly massive value is returned on the BAR that is exactly PERIOD number of bars from once the calculation has begun.
    Code:
    PERIOD    = 55;
    
    protected override void OnBarUpdate()
    {
    
    if (CurrentBar < PERIOD) return;
    
    
    double TOTALfracTrueRange = 0;
        for (int i = 0; i < PERIOD; i++)
        {
           //Some total that iterates inside the for loop
        }
    
    }
    No value is show for the first PERIOD = 55 number of bars.
    Then some values for the next bars until the second PERIOD number of bars produces an impossible inaccurate output???

    Comment


      #3
      Originally posted by NinjaTrader_BrandonH
      Hello DynamicTest,

      Thanks for your post.

      That would be the correct way to check if at least 55 bars have been processed on the chart before the script begins calculations.

      To understand why the script is behaving as it is debugging prints would need to be added to the script to understand exactly how the logic in your script is behaving and calculating values.

      Add prints one line above the loop that prints out the period and the CurrentBar along with the time of the bar. Add prints inside the loop that print out the "i" value being used for the loop, the period, and all other values in the loop that you are using for calculations along with labels and operator comparisons to understand how it is behaving.

      Below is a link to a forum post that demonstrates how to use prints to understand behavior.

      Thank you so much for sharing your debugging experience.
      I have solved the issue and it required a more nuanced test to ensure that enough bars have been processed on the chart before the script begins calculations.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      566 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      329 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
      547 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