Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

A weird situation with BarsRequired and CurrentBar

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

    A weird situation with BarsRequired and CurrentBar

    Hi Ninjas,

    I'm trying to understand a confusing situation despite I have some experience and this should be a really point to understand.

    I have a code, pretty simple actually, that has a loop to calculate a simple average in the form:

    for ( int d = 1; d <= length; d++ )
    {
    Do sum
    }

    Previous to this calculation, I have the following requirement:

    if ( CurrentBar< BarsRequired )
    {
    return;
    }

    Ok, here's the deal:

    When I do a backtest, I've always set a BarsRequired >= Length, in order to allow calculations, BUT the weird thing is that results could vary greatly depending on the number of BarsRequired, and it has not sense at all, cause if I submit the minimum necessary, all calculations and result should be the same; so, why is this happening ?

    I've trying to change "Maximum Bars Look Back" but the results are the same; they only will change upon a change in the minimum BarsRequired

    #2
    Hello pstrusi,

    Thank you for your post.

    Are you detailing that the results are different if you use the same BarsRequired on two tests? Or that the results vary when using different BarsRequired?

    Comment


      #3
      Using different BarsRequired, the minimum necessary or greater, and it's thought that if BarsRequired is at least the minimum, rising a bit, it shouldn't vary much. Anyway, it's not an emergency, just a curious issue. Thanks

      Comment


        #4
        Hello pstrusi,

        Thank you for your response.

        What is the calculation that is being performed?

        Comment


          #5
          A simple sum that triggers a Buy or Sell order, that simple

          Comment


            #6
            Hello pstrusi,

            Thank you for your response.

            Is the sum based on any price data or changing variables?

            Comment


              #7
              Actually price data from a simple Range Bar chart

              Comment


                #8
                I'd like to ask you:

                If you want to do a long backtest, which instruction would you use to count a minimum of BarsRequired for each day after the ExitOnClose of everyday?

                Comment


                  #9
                  Hello pstrusi,

                  Thank you for your patience.

                  The Bars Required will be from the left most bar. So changing the BarsRequired parameter to a larger value means you are viewing data starting a different point and thus the calculations will be different.

                  To calculate a number of bars after the session open you can use BarsSinceSession: http://www.ninjatrader.com/support/h...ncesession.htm

                  Comment


                    #10
                    Thank you for that tip Patrick, it works as expected

                    Regards
                    PS

                    Comment

                    Latest Posts

                    Collapse

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