• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.


No announcement yet.

Partner 728x90


BarsRequest question

  • Filter
  • Time
  • Show
Clear All
new posts

    BarsRequest question


    I am using pit session trading to run my indicators but I also need to always download the last Overnight session from my code.

    I have done some research and I think that BarsRequest is the best way to achieve that.
    Am I right ?

    If so sometimes I will need to download historical data as well as real time data if I open my indicator in the middle of the overnight session for example.

    Is the bars back download from the BarsRequest constructor only apply to historical data and real time will be updated through my custom OnBarUpdate method as long as there is real time data ?

    Need some guidance
    Thank you

    Hello blar58,

    Just to confirm, you are looking for data that is not already loaded on the chart, is this correct?

    Is this from a different instrument or a different bar type or interval?

    Using a BarsRequest to get a small period of data from a different instrument would be a way to reduce the amount of resources needed for the script as opposed to adding the other instrument as a secondary series using the AddDataSeries() call.

    The barsRequest.Request() does the request for the historical data.
    Adding a method as a handler to the barsRequest.Update event allows you to create a subscription for real-time data for that instrument.
    Chelsea B.NinjaTrader Customer Service


      Hello ChelseaB

      Yes I am looking for data not already loaded on the chart because I am using the Pit session only for the chart and I am loading last overnight session from the BarsRequest.

      The interval and the instrument is the same obviously.

      Example :

      Main Instrument ES CME US Index Futures RTH 30 Minute

      From BarsRequest : ES Overnight Session (custom session that I created) 30 Minute


        Hi blar58,

        The barsRequest object will have a property for the trading hours template that can be set.

        barsRequest.TradingHours = TradingHours.Get("Default 24 x 7");
        Chelsea B.NinjaTrader Customer Service


          I have coded the BarsRequest like the example provided on this forum but all of a sudden NT8 stops working. Seems to be in conflict with something else.

          No error message from the the trace and log files but I get a message box stating that that NinjaTrader has stopped working.


            Hi blar58,

            I've attached an example that does a dynamic bars request for a selected instrument.

            The trading hours template chosen is the default 24 / 7 template.

            Does this script also cause NinjaTrader to crash?
            Attached Files
            Chelsea B.NinjaTrader Customer Service


              Yes it does


                Hello blar58,

                I've tested this script on my end and I am not experiencing any crashing.

                Do you have other scripts running?

                What version of the Beta are you using?
                (Help -> About...)
                Chelsea B.NinjaTrader Customer Service


                  Yes it is part of a big indicator and I am using beta 11.

                  What I am noticing right now though is that when crash happens and I reload the indicator seems that the BarsRequest object is still in memory.

                  I have reloaded the indicator. it was working fine so I immediately saved and closed my workspace. I reloaded the indicator and seems to be fine now.

                  I will keep this thread updated ...


                    Hello blar58,

                    The example I have provided removes the secondaryBarsRequest.Update event handler in State == State.Terminated. This stops the event handler. The .NET garbage collector would then remove this from memory as memory is needed.

                    Please close all workspaces and open a new blank workspace. Then restart NinjaTrader to ensure no other scripts are running. Then try running the example script I have provided you once more by itself. Does the script still cause NinjaTrader to crash?
                    Chelsea B.NinjaTrader Customer Service


                      No this script doesn't cause NT to crash.

                      But if NT crashes does the state terminated executed ?

                      It seems not according to the way that it behaved.
                      My script still working fine for the time being.
                      Will let you know how it goes


                      Latest Posts


                      Topics Statistics Last Post
                      Started by iq200, 11-09-2019, 08:26 AM
                      5 responses
                      Last Post koganam
                      by koganam
                      Started by johng964, Today, 02:57 PM
                      1 response
                      Last Post NinjaTrader_RyanS  
                      Started by spamula, Today, 03:00 PM
                      2 responses
                      Last Post spamula
                      by spamula
                      Started by MARTIN MARTIN, Today, 01:01 PM
                      0 responses
                      Last Post MARTIN MARTIN  
                      Started by bouncetherubble, Today, 10:21 AM
                      2 responses
                      1 like
                      Last Post bouncetherubble