Announcement

Collapse
No announcement yet.

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 Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          574 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          331 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
          550 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          551 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X