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

How to get opening price of new bar in OnBarUpdate?

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

    How to get opening price of new bar in OnBarUpdate?

    Hi,

    I understand that in OnBarUpdate() we can access the property values of the bar that just closed and it is called when a new bar opens. Now, since it is called when the new bar opens, can we somehow get the opening price of the new bar without resorting to CalculateOnBarClose = false?

    I have some logic which needs to be executed immediately based on the opening price and it should work in a similar way with historical data too (hence, I use CalculateOnBarClose = true). So, is it possible to get the opening price of the new bar in OnBarUpdate()?

    Thanks,
    Ishwar.

    #2
    Hello,
    You would not be able to get the Open of the new bar with CalculateOnBarClose set to true. CalculateOnBarClose set to true will only allow you to calculate the data at the close of the last bar, the new bar information would be unavailable.
    Through custom programming you could add a secondary dataseries and use its granularity to calculate data. This secondary data series could be a smaller granularity that closes more often then the primary dataseries. This method would be very similar to how you add intrabar granularity for backtesting. If you have not already I would recommend to review the following reference sample on this subject: http://ninjatrader.com/support/forum...ead.php?t=6652

    Please let us know if you have any further questions.
    Cody B.NinjaTrader Customer Service

    Comment


      #3
      Hi Cody,

      Yes, I have already added a secondary dataseries of granularity 1-minute, which is the minimum possible currently. But, one minute of delay is sometimes too much for gap up / gap down scenarios between previous bar close and new bar open, especially during market session opening time. I would like to react more quickly in such cases without having to use CalculateOnBarClose = false.

      Since this is not yet available, could you please take this up as a feature request?

      Thanks a lot,
      Ishwar.

      Comment


        #4
        Hello,
        You can add granularity that is smaller than 1 minute such as ticks that would allow you to get these values without disabling CalculateOnBarClose.
        Another option would be to simulate CalculateOnBarClose by setting it to false and having logic entered in within a condition for if(FirstTickOfBar) More information on FirstTick of Bar can be found at the following link: http://ninjatrader.com/support/helpG...ttickofbar.htm

        I will submit a feature request to our development for consideration on having the ability to be able to natively get the Open of the current bar with CalculateOnBarClose set to True.
        Cody B.NinjaTrader Customer Service

        Comment


          #5
          Hi Cody,

          I tried with a smaller dataseries granularity as Ticks / Seconds as you suggested. Though it works in real-time, I won't be able to use this with historical data as my data feed provider does not provide historical tick data. I need at least one year of intraday data at the required granularity to run my strategies. Besides, I believe backtesting would become much more CPU resource / time intensive with this level of granularity.

          So, it would be great if we can have this feature of getting the Open of the current bar with CalculateOnBarClose = true, because it would help us run logic at opening time based on this Opening price, for dataseries of any granularity.

          Thanks & Regards,
          Ishwar.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by algospoke, Yesterday, 06:40 PM
          2 responses
          19 views
          0 likes
          Last Post algospoke  
          Started by ghoul, Today, 06:02 PM
          3 responses
          14 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by jeronymite, 04-12-2024, 04:26 PM
          3 responses
          45 views
          0 likes
          Last Post jeronymite  
          Started by Barry Milan, Yesterday, 10:35 PM
          7 responses
          20 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by AttiM, 02-14-2024, 05:20 PM
          10 responses
          181 views
          0 likes
          Last Post jeronymite  
          Working...
          X