Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Determine barID of basic timeframe within multitimeframe

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

    Determine barID of basic timeframe within multitimeframe

    Dear everyone,

    struggeling with accessing a series of a lower timeframe while progressing the higher timeframe.
    Hope anyone could help.


    So I'm building an indicator with multitimeframe.

    E.g. this indicator is basicly running in an 1 minute chart.
    And I've added a custom series within the 1min chart.

    if (State == State.DataLoaded)
    {
    myseries = new Series<double>(this, MaximumBarsLookBack.TwoHundredFiftySix);
    }

    and added a second higher timeframe

    if (State == State.Configure)
    {
    AddDataSeries(this.Bars.Instrument.FullName, barType, <higher>, Data.MarketDataType.Last);
    }

    Now I'm progressing an this additional higher timeframe in the onBarUpdate event:

    if (BarsInProgress == 1)
    {
    var mydata = myseries[how to get the last corresponding bar of the lower timeframe?];
    }


    How do I get the last barId to access the data of the series of the corresponding bar with the same date/time?

    Hope I could explain what I'm searching for.

    Thanks in advance.

    Cheers

    #2
    Hello Airwave,

    Thank you for your reply.

    As you have it now, your myseries series is synchronized to the primary data series, not the secondary series. A Series<T> variable can only be synchronized to one data series.

    To synchronize it to the secondary series so you can get the value for a specific bar of that series, you'd need to pass it the BarsArray for the series to synchronize to instead of "this":

    myseries = new Series<double>(BarsArray[1], MaximumBarsLookBack.TwoHundredFiftySix);

    BarsArray[0] would be the primary series, BarsArray[1] would be the first additional series added with AddDataSeries, and so on.

    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Hi Kate,

      Yes Thank you.
      But I want to plot this series later as a line. Think then I have gaps when its aligned with the second higher timeframe.

      So I wanted to sync the series with the base array in a minute and then when I'm progressing
      BarsInProgress == 1 (the higer timeframe)
      identify how many bars, in the series, I need to fill with data since the last one (in the higer timeframe).
      But unsure how to identify how many minute candles I have between the candles.

      Maybe sth. like
      1. Get datetime of last bar in higher timeframe 2. Get barid of bar with upper datetime in lower basic timeframe
      3. Get ids of currentbars[0]
      4. Progress the bars between current and the identified one
      ​​​​​​
      Or maybe there is an easier way?

      Does this makes sense for you how I explain?

      Thanks in advance.
      ​​​​​​cheers

      Last edited by Airwave; 05-11-2021, 03:31 PM.

      Comment


        #4
        Hello Airwave,

        Thank you for your reply.

        Here's an example. The tricky bit here is that NinjaTrader will process the current bar for the primary data series before it processes the current bar for the secondary series. I've created an example that uses a series synced to the secondary series that gets the high of that series, and then assigns the most recent updated value to the plot for each bar of the primary series.

        Code:
        namespace NinjaTrader.NinjaScript.Indicators
        {
        public class ExampleHigherTimeFrameSeries : Indicator
        {
        private Series<double> MyHigherTimeFrameSeries;
        protected override void OnStateChange()
        {
        if (State == State.SetDefaults)
        {
        Description = @"Enter the description for your new custom Indicator here.";
        Name = "ExampleHigherTimeFrameSeries";
        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;
        AddPlot(Brushes.Orange, "MyPlot");
        }
        else if (State == State.Configure)
        {
        AddDataSeries(Data.BarsPeriodType.Minute, 20);
        }
        else if (State == State.DataLoaded)
        {
        MyHigherTimeFrameSeries = new Series<double>(BarsArray[1], MaximumBarsLookBack.Infinite);
        }
        }
        
        protected override void OnBarUpdate()
        {
        if(BarsInProgress == 1)
        {
        MyHigherTimeFrameSeries[0] = Highs[1][0];
        }
        
        if(CurrentBars[1] < 1)
        return;
        
        if(BarsInProgress == 0)
        {
        if(MyHigherTimeFrameSeries.IsValidDataPoint(0))
        {
        MyPlot[0] = MyHigherTimeFrameSeries[0];
        }
        else
        {
        MyPlot[0] = MyHigherTimeFrameSeries[1];
        }
        }
        }
        
        #region Properties
        
        [Browsable(false)]
        [XmlIgnore]
        public Series<double> MyPlot
        {
        get { return Values[0]; }
        }
        #endregion
        
        }
        }
        Please let us know if we may be of further assistance to you.
        Kate W.NinjaTrader Customer Service

        Comment


          #5
          Ahh, thanks so much for the example.

          That's great and gives me the guidance I needed....

          ​​​​​​Thanks :-)

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by jpapa, Today, 07:22 AM
          1 response
          4 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by kevinenergy, 02-17-2023, 12:42 PM
          116 responses
          2,758 views
          1 like
          Last Post kevinenergy  
          Started by franatas, 12-04-2023, 03:43 AM
          7 responses
          106 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by Jltarrau, Today, 05:57 AM
          3 responses
          8 views
          0 likes
          Last Post Jltarrau  
          Started by f.saeidi, Today, 05:56 AM
          2 responses
          8 views
          0 likes
          Last Post NinjaTrader_Erick  
          Working...
          X