Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Bars.GetBars() doesnt work on multiple dataseries

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

    Bars.GetBars() doesnt work on multiple dataseries

    Hi,

    I have a syntax below for me to get the Bars Ago using Time, I have multiple dataseries in the program. I am getting negative value for the barsAgo. How do I fix this?

    DateTime convertedTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 8, 30, 00);
    int barsAgo = Bars.GetBars(convertedTime);



    Additionally, getting BarNumber using below code works in 5 Minute Chart but not in my 1 Minute chart so I was trying above code. I am also getting negative value.

    clickPoint.X = ChartingExtensions.ConvertToHorizontalPixels(e.Get Position(ChartControl as IInputElement).X, ChartControl.PresentationSource);
    clickPoint.Y = ChartingExtensions.ConvertToVerticalPixels(e.GetPo sition(ChartControl as IInputElement).Y, ChartControl.PresentationSource);​
    barsAgo = CurrentBars[0] - (int)ChartControl.GetSlotIndexByX((int)clickPoint. X);

    Thanks
    Last edited by kezyclaire; 06-28-2023, 09:12 AM.

    #2
    Hello kezyclaire,

    You will need to specify the bars you want to get a bar from.
    https://ninjatrader.com/support/help.../barsarray.htm

    BarsArray[1].GetBar(convertedTime) would get the bars from the added series.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,

      Now that works, thanks!

      Comment


        #4
        Hi Chelsea,

        I have an additional data series and want to calculate the barnumber of a specific date and time of the primary data stream on the chart.

        I tried the following code, but unfortunately, it does not seem to work based on your example above. Can you please advise?

        Code:
            public class DateToBarNumber : Indicator
            {
                protected override void OnStateChange()
                {
                    if (State == State.SetDefaults)
                    {
                        Description                                    = @"Enter the description for your new custom Indicator here.";
                        Name                                        = "DateToBarNumber";
                        Calculate                                    = Calculate.OnBarClose;
                        IsOverlay                                    = false;
                        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(BarsPeriodType.Minute, 60);    
                    }
                }
        
                protected int DatumToBarNumber(DateTime BarDateTGime)
                {
                    int BarNumberOfDateTime=BarsArray[0].GetBars(Time[0]);
                    return BarNumberOfDateTime;
                }
                protected override void OnBarUpdate()
                {
                    //Add your custom indicator logic here.
                    if (BarsInProgress==1)
                    {
                        int BarNummer=DatumToBarNumber(Time[0]);
                    }
                }
            }​

        Comment


          #5
          Hello Gerik,

          BarsArray[0] is the primary bar.

          If you want the 60 minute series use BarsArray[1].
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Hello Chelsea,

            unfortunately,

            int BarNumberOfDateTime=BarsArray[0].GetBars(Time[0]);

            does not compile. Why?

            Kind regards
            Gerik

            Comment


              #7
              Hello Gerik,

              Apologies, that should be BarsArray[0].GetBar(Time[0]).
              (Not plural)
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Thank you Chelsea. That works now!

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by NullPointStrategies, 03-13-2026, 05:17 AM
                0 responses
                86 views
                0 likes
                Last Post NullPointStrategies  
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                151 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                79 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                53 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Started by TheRealMorford, 03-05-2026, 06:15 PM
                0 responses
                61 views
                0 likes
                Last Post TheRealMorford  
                Working...
                X