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

Last Bar only?

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

    Last Bar only?

    Hi
    how can I set a value of an indicator only on the last bar? typcially all bars (or at least) a range is processed. But assumed I simply want to set the indicator for the last 10 bars only, but all values depending on the last bar istself, how can I detect that the current bar is really the last one?
    Rolf

    #2
    rolfwidmer,

    Could you please clarify?

    Indicators start at some point in the past and calculate for each bar up to the most current closed bar if CalculateOnBarClose = true. They don't recalculate for past bars.

    By last bar, do you mean the last bar for the session, or are you trying to detect whether you are on the most current closed bar?

    I look forward to assisting you.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      I am programming an indicator showing a forecast, which is based on the last x (assume 50) bars and forecasts a range of y (assume 10) bars. By nature, this only makes sense for the most actual bar, as otherwise the indicator will be mix of different forecasts.

      So my idea is having an indicator which calculates the last x and the next y bars (so 60 in total), but this only for the most actual bar on the chart.

      But OnBarUpdate is called for every bar initially (when I refresh the chart or assign a new instrument). So I would have to check whether OnBarUpdate is called from the last bar. Doing this in Initialize does work as I get an error.

      Rolf

      Comment


        #4
        rolfwidmer,

        You could try using DateTime.Now.TimeOfDay and compare it to Time[0]. For an example that would work on an hourly chart :

        Code:
        private Datetime CurrentTime;
        
        protected override void Initialize()
        {
          // code here
        
          CurrentTime = Datetime.Now.TimeOfDay;
        }
        
        protected override void OnBarUpdate()
        {
           if( Time[0].Hour < (CurrentTime.Hour - LookBack) )
           {  
              return;
           }
           else
          {
             //do whatever
          }
        
        
        }
        You will need to account for the day as well most likely since this example will probably return some negative integers for comparison in the if statement if your session has early enough times.

        For more information on using Datetime objects, please see the following link : http://msdn.microsoft.com/en-us/libr....datetime.aspx

        Please let me know if I may assist further.
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          thanks, that probably works. I detected now that I can use a count cnt and comparing
          if
          (cnt == Count-1)
          will do it for the last bar only...

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by ScottWalsh, Today, 06:52 PM
          3 responses
          19 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by trilliantrader, Today, 03:01 PM
          2 responses
          17 views
          0 likes
          Last Post helpwanted  
          Started by cre8able, Today, 07:24 PM
          0 responses
          1 view
          0 likes
          Last Post cre8able  
          Started by Haiasi, Today, 06:53 PM
          1 response
          4 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by ScottW, Today, 06:09 PM
          1 response
          6 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Working...
          X