Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Referencing another chart/timeframe to create an if statement

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

    Referencing another chart/timeframe to create an if statement

    Hi there,

    I'm trying to backtest a strategy that includes referencing a chart on a different timeframe. Effectively, I would only like certain positions to be taken long if price is over the daily 100 EMA, and shorts for below the daily 100 EMA. I would like to trigger the strategy on a chart on a different timeframe and even chart type.

    Thank you.

    #2
    You'll likely need to add a secondary data series to your Strategy using AddDataSeries(BarsPeriodType.Day, 1) (or whatever other timeframe you want to use as your entry filter)

    Then, in your onBarUpdate you want to add conditional code to evaluate this timeframe first before entering trades. Using BarsInProgress is where you're going to be able to access your multiple data series.

    The documentation has a few very good articles/pages on this, here's one

    https://ninjatrader.com/support/help...inprogress.htm


    Hope that helps
    jaybedreamin
    NinjaTrader Ecosystem Vendor - Zion Trading Algos

    Comment


      #3
      Hello quicksandatl,

      Thanks for your post.

      jaybedreamin is correct. You would need to add a secondary data series to your strategy by calling the AddDataSeries() method in State.Configure. Then, you would submit the orders to that added series by using the Entry() method overload that lets you specify a barsInProgressIndex argument.

      EnterLong(int barsInProgressIndex, int quantity, string signalName)

      The primary data series the script is running on will have a BarsInProgressIndex of 0. The first added series in the script will have a BarsInProgressIndex value of 1. The second added series will have a BarsInProgressIndex value of 2, and so on.

      AddDataSeries(): https://ninjatrader.com/support/help...dataseries.htm
      BarsInProgress: https://ninjatrader.com/support/help...inprogress.htm
      Working with Multi-Timeframe/Multi-Instrument NinjaScripts: https://ninjatrader.com/support/help...nstruments.htm

      Here is a reference sample that demonstrates submitting orders to an added data series which you might find helpful: https://ninjatrader.com/support/help...ipt_strate.htm
      <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

      Comment


        #4
        Thank you both for these responses! Very helpful, I think can put something together with this.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Mindset, 04-21-2026, 06:46 AM
        0 responses
        93 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by M4ndoo, 04-20-2026, 05:21 PM
        0 responses
        138 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by M4ndoo, 04-19-2026, 05:54 PM
        0 responses
        68 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by cmoran13, 04-16-2026, 01:02 PM
        0 responses
        123 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        73 views
        0 likes
        Last Post PaulMohn  
        Working...
        X