Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Access Bars to another timeframe instrument

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

    Access Bars to another timeframe instrument

    Hello

    Quick one, I have a multi timeframe instruments strategy , and OnBarUpdate I want to have access to indicator on another timeframe instrument.

    Example, say I have instrument ABC - 1 minute updates and DEF 30 minutes update, on the on bar update for ABC I want to access current indicators for DEF , even though DEF bar is not closed yet.

    Is that possible? How can I do it?

    Second question is, do we have an event for when bar starts? I know we have OnBarUpdate, do we have any other event where I can get when the bar just started?

    Thanks,

    Rodrigo

    #2
    Hello Rodrigo,

    Yes, that is possible. The first thing you will need to do is call the Add() method to add the secondary data series. Then you can pass BarsArray[1] as an IDataSeries object into the constructor of the indicator method that you are using.

    To ensure that you are performing the calculation on the bar update of the primary data series, you can check to see whether BarsInProgress is equal to 0 (index 0 will be the primary data series, and index 1 will be the data series that you added via the Add() method). To check to see when a new bar begins, you can test for the value of FirstTickOfBar, which will return true on the first tick of a new bar.

    Following is a simplified example of each of these items at work:

    private double SMAValue = 0;

    protected override void Initialize()
    {
    Add("ES 03-15", PeriodType.Tick, 100);
    }

    protected override void OnBarUpdate()
    {
    if(BarsInProgress != 0) return;

    if(FirstTickOfBar)
    {
    SMAValue = SMA(BarsArray[1], 50);
    }
    }

    For your reference, I've included links to the NinjaScript language reference for each of these items below:

    BarsArray: http://www.ninjatrader.com/support/h...?barsarray.htm
    BarsInProgress: http://www.ninjatrader.com/support/h...inprogress.htm
    Add(): http://www.ninjatrader.com/support/h....html?add3.htm
    FirstTickOfBar: http://www.ninjatrader.com/support/h...ttickofbar.htm
    Using Multiple Timeframes and Instruments: http://www.ninjatrader.com/support/h...nstruments.htm

    There is also a strategy called "SampleMultiTimeFrame" that is built into NinjaTrader that you can take a look at to see these concepts at work.

    Please let me know if I can assist further.
    Dave I.NinjaTrader Product Management

    Comment


      #3
      Thanks Davel, your example makes all sense, I just wanna make sure it's going to work for my purposes.

      The indicator that I need on the primary instrument is from a 30 mins intraday bar. But I I need to look at this indicator right after the bar starts, in other words I need the OnBarUpdate event to be called on ticks frequency so I can get the first tick but I need the indicator value (eg RSI) based on a 30 min. plotted bar.

      Should I add the instrument twice one as tick for the event catching sake and the other as 30 mins for the indicator value sake?

      Or maybe should I just set CalculateOnBarClose to false, would that trigger the OnBarEvent on every ticket, even though I'm calculating bars for a 30 min time period?

      I just need to enter the market on the first tick from the market opening but looking at 30 mins bar chart indicator so I decide whether long or short. In other words, get a indicator even though the bar is not yet closed.

      Trying to understand how does it work and the better way to accomplish what I need.

      Thank you,

      Rodrigo
      Last edited by rgaleote; 12-28-2014, 06:15 PM. Reason: adding more details

      Comment


        #4
        Hello Rodrigo,

        Thank you for your response.

        On Historical bars the OnBarUpdate() method will be called at the close of the bar. On real-time bars with CalculateOnBarClose set to False the OnBarUpdate() will be called for each incoming tick.

        Comment


          #5
          Patrick,

          Let me ask you a couple of question so I understand how NT works for CalculateOnBarClode and ticks:

          1- If use Add to another instrument and selects periodtype = ticks and value 1? OnBarUpdate will be called on each new tick, right?

          2- Still on the question above, On Bar update, if I access some indicator like RSI, to which Bar or period of time would it be relating to?

          3- Still on the 1st question, if it is period type value 1, would the FirstTickOfBar make sense?

          Thanks,
          Rodrigo
          Last edited by rgaleote; 12-29-2014, 08:24 AM. Reason: more questions

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          656 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          371 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          109 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          574 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          579 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X