Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Get price from database

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

    Get price from database

    I understand a bar is not closed until opening of next bar, and strategy gets the latest close price only after next bar opens.
    My question is about the last bar of session. Its close price is always available in historical database before next session due to after-hours and pre-market trading. Is there a way to get this price in my strategy before session start, without changing session template?
    Last edited by cliffhu; 04-08-2024, 03:49 AM.

    #2
    Hello cliffhu,

    "I understand a bar is not closed until opening of next bar, and strategy gets the latest close price only after next bar opens."

    This is only true with Calculate.OnBarClose and is not true when using Calculate.OnEachTick or .OnPriceChange (with TickReplay for historical).




    "My question is about the last bar of session. Its close price is always available in historical database before next session due to after-hours and pre-market trading."

    Historical data is not stored in the database. This is stored in historical data files in the Documents\NinjaTrader 8\db folder.

    The close price of the bar isn't available until the bar closes as the last tick received from the market while the bar is open becomes the close price of the bar.
    (Which is provided with every bar update when using Calculate.OnEachTick/.OnPriceChange before the bar closes)

    You can always do a BarsRequest to fetch historical or real-time data out of sync from the bars objects.


    "Is there a way to get this price in my strategy before session start, without changing session template?"

    You could use Calculate.OnEachTick/.OnPriceChange or do a BarsRequest.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,

      BarsRequest doesn't help in my case as "BarsRequest data CANNOT be used as input for a NinjaTrader indicator".

      The screenshot shows what I mean with last bar of session 'close price is always available in historical database before next session'. I don't understand why can't get it before next session start.

      My strategy works on 1-minute bars of multiple instruments, which are synced to the most liquid one. But in real time, their sessions don't start together. When the first tick of the most liquid one comes in, NT can't get the close price of other ones even they are there as shown in the picture. I doubt this last session's price is in market data, as I start NT before each session.

      Comment


        #4
        Hello cliffhu,

        If the data is in an Series<double> this would be the same issue as the Close series, in that the Series would only update to the last tick or bar update with Calculate.OnBarUpdate/.OnEachTick.

        The BarsRequest would allow you to fetch the close price of the session however.

        Below is a link to an example that puts BarsRequest data in a series.



        "The screenshot shows what I mean with last bar of session 'close price is always available in historical database before next session'"

        The window in your screenshot is the Historical Data window which shows the historical data downloaded in historical data files (not in the database).

        This data is available, and updates for each bar as the bar updates.

        "I don't understand why can't get it before next session start."

        This is because when using Calculate.OnBarClose, the bar does not close until a new bar opens. (A tick has to be received that would be part of a new bar for the previous bar to know it's closed) Meaning you would have to use Calculate.OnEachTick/.OnPriceChange to get the final close price of the bar before next session opens.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi Chelsea,

          Thanks for the information. This looks more complicated than I expect from NT. For now, I may just do it in a stupid way - click F5.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          80 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          46 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          29 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          32 views
          0 likes
          Last Post TheRealMorford  
          Started by Mindset, 02-28-2026, 06:16 AM
          0 responses
          66 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Working...
          X