Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How do I get my indicator start at the last 200 candles?

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

    How do I get my indicator start at the last 200 candles?

    It seems as though the maxbarslookback function holds values up to 256 or infinite, but starts at the first candle on screen and as 256 ( if selected)bars begin to be calculated, it begins to drop them off until arriving at the currenbar, in whch case it will effectively be 256 barlookback.

    However, if this is the case then this is not what I want. This method takes too long for my inidicator.

    Is there any solution to *start* the calculation on half the bars on screen? for example......a count of 2,500 bars on screen, yet the first calculation will start at bar 1,250. Not any bars before.

    #2
    Hello lakersfan,

    Thanks for your post and welcome to the Ninjatrader forums.

    Without knowing the workings of your indicators and what its needs are we can only give general advise and that may be enough for your needs.

    To clarify something. When you add any script to a chart, the script will start processing on the very first historical bar meaning it will execute your code on that bar. It will then pull the next bar and again process your code, the 3rd bar, etc. etc until it is add the right edge.

    If you want to avoid that processing you could compare the CurrentBar (which is the systems bar index that is being processed by your code) to the property Bars.Count which holds the number of bars in the chart.

    Reference: https://ninjatrader.com/support/help...currentbar.htm

    So if you want to wait until only 200 bars then you could do something like:

    if (CurrentBar < Bars.Count - 200) return; // do not process code below this line until we are less than 200 bar left.

    I've attached an example applied to a lot of bars. When there are 200 bars left it will start placing a blue dot (processing the code) above the bar.

    Click image for larger version

Name:	lakersfan-1.PNG
Views:	358
Size:	109.0 KB
ID:	1100031

    Comment


      #3
      Originally posted by NinjaTrader_PaulH View Post
      Hello lakersfan,

      Thanks for your post and welcome to the Ninjatrader forums.

      Without knowing the workings of your indicators and what its needs are we can only give general advise and that may be enough for your needs.

      To clarify something. When you add any script to a chart, the script will start processing on the very first historical bar meaning it will execute your code on that bar. It will then pull the next bar and again process your code, the 3rd bar, etc. etc until it is add the right edge.

      If you want to avoid that processing you could compare the CurrentBar (which is the systems bar index that is being processed by your code) to the property Bars.Count which holds the number of bars in the chart.

      Reference: https://ninjatrader.com/support/help...currentbar.htm

      So if you want to wait until only 200 bars then you could do something like:

      if (CurrentBar < Bars.Count - 200) return; // do not process code below this line until we are less than 200 bar left.

      I've attached an example applied to a lot of bars. When there are 200 bars left it will start placing a blue dot (processing the code) above the bar.

      Click image for larger version

Name:	lakersfan-1.PNG
Views:	358
Size:	109.0 KB
ID:	1100031
      Thank you, It worked. Are you guys not available during the weekend? I posted about the wav file.

      Comment


        #4
        Hello lakersfan,

        Thanks for your reply.

        We do have weekend coverage although it is limited.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        80 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        46 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        29 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        32 views
        0 likes
        Last Post TheRealMorford  
        Started by Mindset, 02-28-2026, 06:16 AM
        0 responses
        66 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Working...
        X