Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Get Volume lower timeframe

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

    Get Volume lower timeframe

    Hi,

    I have an indicator that is getting the highest volume bar from the beginning of the day, on a M5 timeframe

    I'm calculating like this:

    Code:
    int highestVolumeBarsAgo = HighestBar(Volume, Bars.BarsSinceNewTradingDay);
    double valueHighVolume = Volume[highestVolumeBarsAgo];
    With this code, I get the bar with highest volume of current day.

    Now I need get the highest volume bar of 1Minute timeframe, inside the 5min bar
    If the bar is for example of 10:00 am, maybe the highest volume is in the 1 minute bar of 10:03 am.


    How can I get the lower timeframe data from current timeframe?

    Thanks

    #2
    Hello Powerbucker,

    Add the 1 minute series with AddDataSeries().




    Use Volumes[1] as the input series for HighestBar.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3

      Hi,

      thanks for the response.

      I am doing tests and I have a curious behavior, the M5 and M1 candles are not synchronized.
      I have made a test that, given an M5 candle, it goes through the equivalent M1 candles, but it returns the M5 information of one candle, and the M1 information but of the next M5 candle

      I add the series
      Code:
              else if (State == State.Configure)
              {
                  AddDataSeries(Data.BarsPeriodType.Minute, 1);
              }
      ​
      In the update event, if the candle is a specific one, I run the test
      Code:
              protected override void OnBarUpdate()
              {
                  if (BarsInProgress != 0 || CurrentBars[1] <= 0)
                      return;
      
                  DateTime fecha = new DateTime(2024, 11, 27, 15, 35, 0);
                  if (Time[0] == fecha)
                      test(CurrentBar);
      ​
      Here, given the M5 candle, I get the start date and end date and I search in the M1 series for the candles that are in the date range
      Code:
              void test(int iBar)
              {
                  //get the big bar time range
                  DateTime startTime = Bars.GetTime(iBar);
                  DateTime endTime = startTime.AddMinutes(BarsPeriod.Value);
              
                  //Get the lower bar date
                  int startBar = BarsArray[1].GetBar(startTime);
              
                  NinjaTrader.Code.Output.Process($"M5 - {Bars.GetLow(iBar).ToString()} - {Bars.GetHigh(iBar).ToString()} - {startTime.ToString()} - {endTime.ToString()}", PrintTo.OutputTab1);
              
                  // Iterar sobre las barras de M1 dentro del rango de la vela M5
                  DateTime barTime = BarsArray[1].GetTime(startBar);
              
                  while (barTime >= startTime && barTime < endTime)
                  {
                     NinjaTrader.Code.Output.Process($"  -- lowerBar - {BarsArray[1].GetLow(startBar).ToString()} - {BarsArray[1].GetHigh(startBar).ToString()} - {BarsArray[1].GetTime(startBar).ToString()}", PrintTo.OutputTab1);
          
                      startBar++;
                      barTime = BarsArray[1].GetTime(startBar);
                  }
              }    ​
      As you can see in the log, the M1 candles do not match the M5 one, the opening and closing prices are those of the next M5 candle
      Code:
      M5 - 68,59 - 69,02 - 27/11/2024 15:35:00 - 27/11/2024 15:40:00
        -- lowerBar - 68,83 - 69,02 - 27/11/2024 15:35:00
        -- lowerBar - 68,89 - 69,01 - 27/11/2024 15:36:00
        -- lowerBar - 68,98 - 69,06 - 27/11/2024 15:37:00
        -- lowerBar - 69,01 - 69,09 - 27/11/2024 15:38:00
        -- lowerBar - 69,09 - 69,14 - 27/11/2024 15:39:00
      ​


      I'm attaching a chart with the candle I am testing.

      How can I synchronize the series well? Any idea?

      Thanks

      Attached Files
      Last edited by Powerbucker; 11-28-2024, 03:04 AM.

      Comment


        #4
        If I test with this simpler code, the same happens

        Code:
                protected override void OnBarUpdate()
                {
                    if (BarsInProgress == 0)
                    {
                        DateTime fecha = new DateTime(2024, 11, 27, 15, 35, 0);
                        if (Time[0] == fecha)
                            NinjaTrader.Code.Output.Process($"M5 - {Time[0].ToString()} - {Low[0].ToString()} - {High[0].ToString()}", PrintTo.OutputTab1);
                    }            
                    if (BarsInProgress == 1)
                    {
                        DateTime fecha1 = new DateTime(2024, 11, 27, 15, 35, 0);
                        DateTime fecha2 = new DateTime(2024, 11, 27, 15, 40, 0);
                        if (Time[0] >= fecha1 && Time[0] < fecha2)
                            NinjaTrader.Code.Output.Process($"-- M1 - {Time[0].ToString()} - {Low[0].ToString()} - {High[0].ToString()}", PrintTo.OutputTab1);
                    }            
                    return;​
        Code:
        M5 - 27/11/2024 15:35:00 - 68,59 - 69,02
        -- M1 - 27/11/2024 15:35:00 - 68,83 - 69,02
        -- M1 - 27/11/2024 15:36:00 - 68,89 - 69,01
        -- M1 - 27/11/2024 15:37:00 - 68,98 - 69,06
        -- M1 - 27/11/2024 15:38:00 - 69,01 - 69,09
        -- M1 - 27/11/2024 15:39:00 - 69,09 - 69,14​


        Thanks

        Comment


          #5
          I tried to add M1 dataseries to chart, and the 2 timeframes aren't synchronyzed. As you can see, M1 is advanced compared to M5

          Attached Files

          Comment


            #6
            Hello Powerbucker,

            I'm not clear on the issue.

            The open, high, low, and volume are going to be different because the bar interval is different.
            If the bars are the same instrument and close at the same time, I would only expect the close to be the same.

            Further, if you want information from another series, use the barsInProgress index of that series.

            For example if BarsInProgress is 1, and you want the close of BarsInProgress 0, use Closes[0][0].​
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Basically, on an M5 timeframe I want to get the 5 M1 candles that make up the M5 candle.

              Thanks

              Comment

              Latest Posts

              Collapse

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