Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Max look bar and Min bars required

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

    Max look bar and Min bars required

    I'm developing a point-and-figure strategy

    On BackTest Menu I could set
    1) Maximum bars look back
    2) Min bars required.

    However, is there a way to set
    a) maximum bars look back - to 2 days ago
    b) Min bars required - to 2 days

    if yes, how?
    Thank you

    #2
    30percent, the max bars lookback property is more for memory optimizations and it can only be set to 256 or infinity.

    The min bars required can only be set by bars, and not by days.
    AustinNinjaTrader Customer Service

    Comment


      #3
      I'm trying my hand on Ninjascript.
      I wonder if this would work...
      setting BarsRequired to s, exactly 2 days of bars before processing the strategy and max lookback using DataSeries.


      protected override void Initialize()
      {
      BarsRequired = s;
      dataSeriesHigh = new DataSeries(this);
      }

      protected override void OnBarUpdate()
      {
      dataSeriesHigh.Set(s, High);
      time t;
      t = Time(0) + 00000002 ;
      int s = 0;
      while (Time(s) != t)
      {
      if Time(s) == t
      {
      return s
      }
      else
      {
      s += 1
      }
      }
      }

      Comment


        #4
        30percent, you must know how many bars you want required before setting the variable in Initialize(). If you want to skip over calculations until there is enough data, I would suggest looking into the TimeSpan property of C# and returning out of OnBarUpdate() until there you have enough data:
        Code:
        if (time passed < time required)
        return;
        else
        //continue with your strategy
        This link goes to our reference sample for manipulating DateTime objects - http://www.ninjatrader.com/support/f...ad.php?t=19176.
        AustinNinjaTrader Customer Service

        Comment


          #5
          Hi,

          I read into TimeSpan of C#. I was thinking writing the following code, and returning out of OnBarUpdate until duration passed => 00000002 (2 days). However, now come the issue of getting the ToDay(Time[x]) --- the very first day/date of the session when the strategy is started. How can I get the x bars ago of the very first day/date when the strategy is started?

          TimeSpan timePassed = ToDay(Time[0]) - ToDay(Time[x]);
          if (timePassed.Duration < 00000002)
          {
          return;
          }
          I was thinking of storing ToDay(Time[0]) in Initialize() or OnStartUp() and retrieve it in OnBarUpdate later to get the first day/date-- however, both of these functions don't return values

          Comment


            #6
            Originally posted by 30percent View Post
            Hi,

            I read into TimeSpan of C#. I was thinking writing the following code, and returning out of OnBarUpdate until duration passed => 00000002 (2 days). However, now come the issue of getting the ToDay(Time[x]) --- the very first day/date of the session when the strategy is started. How can I get the x bars ago of the very first day/date when the strategy is started?

            I was thinking of storing ToDay(Time[0]) in Initialize() or OnStartUp() and retrieve it in OnBarUpdate later to get the first day/date-- however, both of these functions don't return values
            Set the startDate in OnStartUp(), then use it to filter in OnBarUpdate().

            Code:
            private DateTime StartDate;
            Code:
            protected override void OnStartUp()
            {
            // statements
            StartDate = Time[0].Date;
            }
            Code:
            protected override void OnBarUpdate()
            {
            if (Time[0].Date < StartDate.AddDays(2)) return;
            
            // statements
            }

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            562 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            325 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
            547 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X