Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 Jonafare, 12-06-2012, 03:48 PM
    5 responses
    3,984 views
    0 likes
    Last Post rene69851  
    Started by Fitspressorest, Today, 01:38 PM
    0 responses
    2 views
    0 likes
    Last Post Fitspressorest  
    Started by Jonker, Today, 01:19 PM
    0 responses
    2 views
    0 likes
    Last Post Jonker
    by Jonker
     
    Started by futtrader, Today, 01:16 PM
    0 responses
    7 views
    0 likes
    Last Post futtrader  
    Started by Segwin, 05-07-2018, 02:15 PM
    14 responses
    1,791 views
    0 likes
    Last Post aligator  
    Working...
    X