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 NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        72 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        143 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        76 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        47 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        51 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X