Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi time frame indicators

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

    Multi time frame indicators

    Hi,

    I'm trying to create an indicator that calculates some volatility metrics based on ES daily High/Low/Open/Close. I'd ideally like to have these metrics on a rolling basis - for instance perhaps the last 5 and 10 trading days. However, I'd like to display these calculated values on my more granular charts that only displays the last session or two. I thought this was possible but I'm having trouble loading more data than the primary bars. I know I could have a separate daily chart open and write those values to a file and then load them on the short term chart, but I think I am missing a more elegant way of doing this?

    Thanks

    #2
    Have you looked at using BarsRequest?
    Last edited by bltdavid; 02-20-2023, 11:27 PM.

    Comment


      #3
      It looks like BarsRequest is only available in AddOn code? Making it all an AddOn, or at least putting the higher time frame calculations into an AddOn, is a leap my brain hadn't made yet, thanks for suggesting.

      Comment


        #4
        Originally posted by NickyD View Post
        It looks like BarsRequest is only available in AddOn code?
        Nope.

        BarsRequest is available for all NinjaScript object types: AddOn, Indicator,
        and Strategy. (Says so right there in the documentation.)

        You have a lot of studying to do.

        Through that Google search, I found this, which seems especially relevant
        to what you're doing.

        -=o=-

        Ya gotta search the forums, it's a gold mine full of example code.

        How to search?
        Just prefix your Google search query with 'NinjaTrader ...', like I
        did above.

        I'm telling you, BarsRequest is your guy.

        Good luck!

        Last edited by bltdavid; 02-20-2023, 11:31 PM.

        Comment


          #5
          Hello, thanks for writing in. The AddDataSeries method has an overload that lets you specify the number of bars to load, while this does not allow a number of days to load, you can load, for example, 7,200 1 minute bars to load 5 days of minute bars:
          AddDataSeries(string instrumentName, BarsPeriod barsPeriod, int barsToLoad, string tradingHoursName, bool? isResetOnNewTradingDay)

          Comment


            #6
            Woah, that sounds even better!

            Can AddDataSeries load, say, 100 bars of Day data (to get 100 days of Day data)
            despite the primary series only loading, say, 3 days?

            Assume the 3 days is the amount specified when the chart was first created.

            To get Day data, this could be pretty sweet alternative to BarsRequest.

            Comment


              #7
              Originally posted by NinjaTrader_ChrisL View Post
              Hello, thanks for writing in. The AddDataSeries method has an overload that lets you specify the number of bars to load, while this does not allow a number of days to load, you can load, for example, 7,200 1 minute bars to load 5 days of minute bars:
              AddDataSeries(string instrumentName, BarsPeriod barsPeriod, int barsToLoad, string tradingHoursName, bool? isResetOnNewTradingDay)
              Thanks, I saw that overload and was trying to use it but wasn't getting the results I expected. I guess I had a bug in there, I'll try it again.

              Comment


                #8
                bltdavid Google and forum searches aside - how can one tell from the documentation that BarsRequest is in the NinjaTrader.Data namespace?

                Comment


                  #9
                  Hi Nicky, I have an example here showing how to do a bars request from an indicator if you do want to manage the data "manually":
                  I have been using BarsRequest for months in an Indicator and had zero issues. On Sunday I updated to 16 and it totally crapped out. I went thru the Help guide to

                  Comment


                    #10
                    Originally posted by NickyD View Post
                    bltdavid Google and forum searches aside - how can one tell from the documentation that BarsRequest is in the NinjaTrader.Data namespace?
                    I don't think the documentation states that specifically,
                    so the answer is "you can't".

                    -=o=-

                    If you know how to use Intelliprompt, open the NinjaScript
                    Editor, edit an existing indicator or strategy, and inside
                    some known working code area (I usually do this in an
                    existing method, like OnStateChange), type 'NinjaTrader'
                    followed immediately by a period '.' character.

                    NinjaTrader. <-- the period brings up Intelliprompt

                    Now type,

                    NinjaTrader.Data. <-- different Intelliprompt



                    It is the last period '.' character that shows an Intelliprompt
                    window showing subordinate code.

                    Scrolling the Intelliprompt window for 'NinjaTrader.Data.' you
                    will soon see BarsRequest. Make sure and close the indicator
                    window (without saving it!) so your experimenting doesn't cause
                    any compile errors.

                    Comment


                      #11
                      This seems to be doing what I want it to. I'm getting all the daily closes from BIP = 1 before the simultaneous processing begins of whatever shorter time frame and history I've chosen for BIP = 0.

                      Thanks to all.


                      Code:
                      public class LoadLotsOfDays : Indicator
                          {
                              protected override void OnStateChange()
                              {
                                  if (State == State.SetDefaults)
                                  {
                                      Description                                    = @"Loads 30 Days of daily bars for the instrument in the primary bars.";
                                      Name                                        = "LoadLotsOfDays";
                                      Calculate                                    = Calculate.OnBarClose;
                                      IsOverlay                                    = true;
                                      DisplayInDataBox                            = true;
                                      DrawOnPricePanel                            = true;
                                      DrawHorizontalGridLines                        = true;
                                      DrawVerticalGridLines                        = true;
                                      PaintPriceMarkers                            = true;
                                      ScaleJustification                            = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                                      //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                                      //See Help Guide for additional information.
                                      IsSuspendedWhileInactive                    = true;
                                  }
                                  else if (State == State.Configure)
                                  {            
                                      AddDataSeries(BarsArray[0].Instrument.ToString(), new BarsPeriod { BarsPeriodType = BarsPeriodType.Day, Value = 1}, 30, BarsArray[0].TradingHours.Name, true);
                                  }
                      
                              }
                      
                              protected override void OnBarUpdate()
                              {
                                  //Add your custom indicator logic here.
                      
                                  if ( BarsInProgress == 1 ) {
                                      Print("We are processing BIP = 1 closing at: " + Time[0].ToString() );    
                                      Print("OHLC: " + Open[0] + ", " + High[0] + ", " + Low[0] + ", " + Close[0]);
                                  }
                                  if ( BarsInProgress == 0 ) {
                                      Print("We are processing BIP = 0 closing at: " + Time[0].ToString() );    
                                  }
                              }
                          }​

                      Comment


                        #12
                        For the sake of anyone reading this after the fact, my code sample above is incorrect. You shouldn't be using Bars/BarsArray as a parameter in AddDataSeries.

                        "Arguments supplied to AddDataSeries() should be hardcoded and NOT dependent on run-time variables which cannot be reliably obtained during State.Configure (e.g., Instrument, Bars, or user input). Attempting to add a data series dynamically is NOT guaranteed and therefore should be avoided. Trying to load bars dynamically may result in an error similar to: Unable to load bars series. Your NinjaScript may be trying to use an additional data series dynamically in an unsupported manner.​"

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                        0 responses
                        631 views
                        0 likes
                        Last Post Geovanny Suaza  
                        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                        0 responses
                        364 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by Mindset, 02-09-2026, 11:44 AM
                        0 responses
                        105 views
                        0 likes
                        Last Post Mindset
                        by Mindset
                         
                        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                        0 responses
                        566 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by RFrosty, 01-28-2026, 06:49 PM
                        0 responses
                        568 views
                        1 like
                        Last Post RFrosty
                        by RFrosty
                         
                        Working...
                        X