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 techgetgame, Yesterday, 11:42 PM
    0 responses
    8 views
    0 likes
    Last Post techgetgame  
    Started by sephichapdson, Yesterday, 11:36 PM
    0 responses
    2 views
    0 likes
    Last Post sephichapdson  
    Started by bortz, 11-06-2023, 08:04 AM
    47 responses
    1,613 views
    0 likes
    Last Post aligator  
    Started by jaybedreamin, Yesterday, 05:56 PM
    0 responses
    10 views
    0 likes
    Last Post jaybedreamin  
    Started by DJ888, 04-16-2024, 06:09 PM
    6 responses
    20 views
    0 likes
    Last Post DJ888
    by DJ888
     
    Working...
    X