Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Using only the most recent 50 bars

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

    Using only the most recent 50 bars

    hi,

    still getting used to programming and ninja script so here is a simple question - how do I work backwards in my custom indicator to start from the most recent bar and go back to only 50 bars to perform certain calculations, instead of starting from the extreme left of the chart and working it's way through all the bars to the most recent one. this I'd like to achieve in the interest of saving time.

    also, if I assign a certain indicator value to a bar' during that most recent 50bars rolling window and the bar falls out of it with passage of time, does the chart lose that indicator value or does it keep it as long as that particular chart is open ?

    sorry I have no script for this, only a generic question and I hope I'm clear in what I'm asking here...

    many thanks in advance for your help

    #2
    buylosellhi, the easiest way would be simply limiting the # of bars you load on the chart which you can et in the Format Data Series box, then for example if you choose to load 500 bars you can start your OnBarUpdate() section of code with if (CurrentBar < 450) return;

    This following code lines in your script would then calculate on the last 50 bars of the chart only as the calls for OnBarUpdate() are limited to start from chartbar 450 on going forward.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Bertrand,

      thanks for your reply. quick follow up question - on a realtime streaming chart how do I 'load' only 500 bars. is that using the BarsLookBack ?

      thanks much

      Comment


        #4
        Yes, you would load 500 bars for example only when creating the chart (Bars to load property). But this would only be for loading up the chart, additional bars as the build in realtime are then added.

        To add to what I previously wrote, this below snippet would for example calculate an SMA on the last 50 bars only and not be called for other bars on the chart for that you would normally call OnBarUpdate() as well -

        Code:
        protected override void OnBarUpdate()
        {
        	if (Count - CurrentBar < 50)
        	    Value.Set(SMA(Period)[0]);
        }
        BertrandNinjaTrader Customer Service

        Comment


          #5
          great thanks. and as bars that were in the 50 period window and were assigned SMA values roll off that window with passage of time, do they retain their associated SMA values ?

          thanks again :-)

          Comment


            #6
            Yes, in my example below those values calc'ed would be retained.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              thanks a lot for your help

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by wzgy0920, Yesterday, 09:53 PM
              2 responses
              49 views
              0 likes
              Last Post wzgy0920  
              Started by Kensonprib, 04-28-2021, 10:11 AM
              5 responses
              191 views
              0 likes
              Last Post Hasadafa  
              Started by GussJ, 03-04-2020, 03:11 PM
              11 responses
              3,230 views
              0 likes
              Last Post xiinteractive  
              Started by andrewtrades, Today, 04:57 PM
              1 response
              14 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Started by chbruno, Today, 04:10 PM
              0 responses
              7 views
              0 likes
              Last Post chbruno
              by chbruno
               
              Working...
              X