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 on Chart OnBarUpdate not firing

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

    Last Bar on Chart OnBarUpdate not firing

    I have a 2 minute chart for ES futures with CME US INDEX FUTURES RTH session selected. The RTH close is at 1:15 PM PST. I see this OnBarUpdate fire for every day end except the last bar on the chart. Today is 10/25/2020, the last RTH bar is on 10/23/2020 and I only see an OBU 10/23/2020 1:14:00 PM, but not for 10/23/2020 1:15:00. When I load multiple days I can see that the 1:15:00 PM bar is processed (for example 10/22/2020 1:15:00 PM). Is this a bug?

    #2
    Hello habibalex,

    The last bar on the chart closes when a new bar opens.

    Is this Calculate.OnPriceChange or .OnEachTick?

    If not, are you waiting until a new bar is created?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      it is set to Calculate.OnBarClose, I guess I misunderstood what onbarclose meant. My problem is that when i am between sessions (ie: Sunday evening) my indicators are not updating RTH values for Friday volume profiles because the last bar on the chart's OBU is not being called. How would I solve this?

      Comment


        #4
        Hello habibalex,

        You could run the script with Calculate.OnPriceChange so you are not waiting for the bar to close for the values to update.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          The profiles are based on the bar close and only the last bar on the chart is messed up. I might try to include some logic in State == State.Transition to check , although this would mean that OBU probably gets called again for the previous session's last bar when the next RTH session starts?

          Comment


            #6
            Hello habibalex,

            You can have logic that runs when a bar closes and a new bar opens by checking IsFirstTickOfBar to be true, and then allow everything else to update in real-time.


            Yes, the last bar of session closes as a new session opens and opens a new bar.

            The State.Transition is when a strategy has finished processing historical data in State.Historical, and is transitioning to State.Realtime and is getting real-time orders and actions ready.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              How do I update the last bar on the chart in this variable? using -1 used to work in NT7

              Code:
              dsMSopen = new Series<double>(this, MaximumBarsLookBack.Infinite);
              Code:
              if(State == State.Historical){//once indicator is loaded will not continue to update profiles
              if(CurrentBar >= Time.Count - 2){//do for last bars
              
              int i = -1;//ninja doesn't call OBU for last bar, so update it here
              try{    
                  dsMSopen[i] = Open[i] + priceoffset;
                  dsMShigh[i] = High[i] + priceoffset;
                  dsMSlow[i] = Low[i] + priceoffset;
                  dsMSclose[i] = Close[i] + priceoffset;
                  //Values[0][i] = Close[i];
                  if(negative && dsMSopen[i] > 0){
                      dsMSopen[i] *= -1;
                      dsMShigh[i] *= -1;
                      dsMSlow[i] *= -1;
                      dsMSclose[i] *= -1;
                  //Values[0][i] *= -1;
                  }
              }catch(Exception ex){}
              }
              
              
              }

              Comment


                #8
                Hello habibalex,

                When Calculate is OnPriceChange or OnEachTick the currently updating bar will be 0 bars ago. For example Open[0].

                Below is a link to the help guide on how bar information is referenced.
                Chelsea B.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by gravdigaz6, Today, 11:40 PM
                1 response
                7 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by MarianApalaghiei, Today, 10:49 PM
                3 responses
                10 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by XXtrader, Today, 11:30 PM
                0 responses
                4 views
                0 likes
                Last Post XXtrader  
                Started by love2code2trade, Yesterday, 01:45 PM
                4 responses
                28 views
                0 likes
                Last Post love2code2trade  
                Started by funk10101, Today, 09:43 PM
                0 responses
                9 views
                0 likes
                Last Post funk10101  
                Working...
                X