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:	273
Size:	109.0 KB
ID:	1100031
    Paul H.NinjaTrader Customer Service

    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:	273
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.
        Paul H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by chbruno, Today, 04:10 PM
        0 responses
        3 views
        0 likes
        Last Post chbruno
        by chbruno
         
        Started by josh18955, 03-25-2023, 11:16 AM
        6 responses
        436 views
        0 likes
        Last Post Delerium  
        Started by FAQtrader, Today, 03:35 PM
        0 responses
        6 views
        0 likes
        Last Post FAQtrader  
        Started by rocketman7, Today, 09:41 AM
        5 responses
        19 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by frslvr, 04-11-2024, 07:26 AM
        9 responses
        127 views
        1 like
        Last Post caryc123  
        Working...
        X