Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi timeframes and multi instruments

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

    Multi timeframes and multi instruments

    I am using NT7 in building an indicator. I want to compare moving average on a particular instrument across different time frames. I have it working but there is a problem that I need some help with.

    I added the different time frames by using the Add()
    Add (PeriodType.Minute, 5);
    Add (PeriodType.Minute, 15);
    Add (PeriodType.Minute, 60); etc


    In the OnBarUpdate section

    if (BarsInProgress == 0) // process only when the primary bar is updated
    {

    in this section I determine the SMA for each time frame using
    Slope5 = SMA(BarsArray[1},18); // sma for the 5 minute
    Slope15 = SMA(BarsArray[2},18); // sma for the 15 minute
    Slope60 = SMA(BarsArray[3},18); // sma for the 60 minute

    ....
    ...
    }

    When I run this opening the chart in the 60 Minute period type it works fine. But when I try to load it in a lower time period, such as the 5 Minute, it doesn't work and give a message something like index not in range. I understand that the period type that you open a chart in becomes the primary and is index = 0 but if I open a chart in the lower time frame, how to I determine the SMA for the higher time frames.

    Second part, say my primary instrument is the ES 06-11. In the same indicator above, how would I bring in and reference the ES ##-## (continuous contract) instrument to determine a moving average?

    Thanks for any hints or help that you can provide.

    Regards,

    #2
    Hello rgb_wins,

    You can use this statement generally to prevent NT from attempting to access invalid objects for multiple series scripts.

    if (CurrentBar < 0 || CurrentBars[1] < 0)
    return;

    You may have to play with the values depending how your script is coded and add additional CurrentBars[ ] indexes to include all series.

    You can add continuous contracts using Add() statements in Initialize() method. An example is:
    Add("ES ##-##", PeriodType.Minute, 15);

    Ryan M.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    653 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    370 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
    577 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X