Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Data from another timeframe

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

    Data from another timeframe

    Hello,

    New to Ninja. I want to create a generic function like moving average but I want to be able to access it for different timeframes. How would I do that?

    #2
    Data from another timeframe

    Hello sunman4008,

    Thanks for writing in to our Support team.

    You can use the BarsArray method to access data series that were added via the AddDataSeries() method.

    Code:
    protected override void OnStateChange()
    {
     
      if (State == State.SetDefaults)
      {
        Name = "Examples Indicator";     
      }
      else if (State == State.Configure)
      {
        // Add a 5 minute Bars object which is added to the BarArray 
        // which will take index 1 since the primary Bars object of the strategy 
        // will be index 0 
        AddDataSeries(BarsPeriodType.Minute, 5); 
      }
    } 
     
    protected override void OnBarUpdate() 
    { 
      // Ignore bar update events for the supplementary Bars object added above 
      if (BarsInProgress == 1) 
        return; 
     
      // Pass in a Bars object as input for the simple moving average method 
      // Evaluates if the 20 SMA of the primary Bars is greater than 
      // the 20 SMA of the secondary Bars added above 
      if (SMA(20)[0] > SMA(BarsArray[1], 20)[0]) 
        EnterLong(); 
    }
    For further reference, you can refer to this link to our help guide that goes over the BarsArray object:
    http://ninjatrader.com/support/helpG.../barsarray.htm

    You can also refer to this forum post that goes over how to submit orders to different bar objects/time frames:
    http://ninjatrader.com/support/forum...ead.php?t=5787

    You should also keep in mind that when accessing a secondary data series it is sometimes necessary to wait for data using
    Code:
    if(CurrentBars[0] < 1 || CurrentBars[1] < 1) 
    return;
    Please let me know if I may be of any further assistance.
    Alan S.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    67 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    96 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    53 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    108 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    63 views
    0 likes
    Last Post PaulMohn  
    Working...
    X