Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi TimeFrame Strategy

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

    Multi TimeFrame Strategy

    Hi-

    I want to understand what I need to do to manage values across 3 time frames. I'm using a 5 min, a 15 min, and a daily chart. All I need is to print the values of 2 items (1) the price of each time frame and (b) the value of a SMA(14) for each of them. However, I always get an index error. I have gone through the NinjaTrader documentation and I can get it to work on Price but not on the indicator. Hopefully someone can help me. Thanks in advance!

    Here is my code:
    if (State == State.Configure)
    {
    AddDataSeries(BarsPeriodType.Minute, 15);
    AddDataSeries(BarsPeriodType.Day, 1);
    }
    else if (State == State.DataLoaded)
    {
    myEMA9_15Min = EMA(BarsArray[1], 9);
    myEMA9_Daily = EMA(BarsArray[2], 9);
    }​

    protected override void OnBarUpdate()
    {
    double My5minClose=0;
    double MyDailyClose=0;
    double My15minClose=0;
    double My5minEMA9 = 0;
    double My15minEMA9 = 0;
    double MyDailyEMA9 = 0;

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

    if (BarsInProgress == 2 )
    {
    MyDailyEMA9 = myEMA9_Daily[1];
    MyDailyClose = Close[1];
    }

    if (BarsInProgress == 1 )
    {
    My15minEMA9 = myEMA9_15Min[1];
    My15minClose = Close[1];
    }

    if (BarsInProgress == 0 )
    {
    My5minClose = Close[0];
    My5minEMA9 = EMA(Close, 50)[0];
    Print("My5minClose: " + My5minClose + " | My15minClose: " + My15minClose + " | MyDailyClose: " + MyDailyClose + " | My5minEMA9: " + My5minEMA9 + " | My15minEMA9: " + My15minEMA9 + " | MyDailyEMA9: " + MyDailyEMA9);
    }
    }​​

    #2
    Hello aarons34,

    Thanks for your post.

    You could pass in Closes[1] and Closes[2] when instantiating your EMA indicators. Closes[1] refers to the Close of the first added series. Closes[2] refers to the Close of the second added series.

    Closes[1][0] and Closes[2][0] could be used to get the current close price of the first and second added series.

    See this help guide page for more information about Closes: https://ninjatrader.com/support/help...nt8/closes.htm

    See this help guide page for more information about working with Multi-TimeFrame/Instrument strategies: https://ninjatrader.com/support/help...nstruments.htm

    And, see the attached example script.

    Let me know if I may assist further.​
    Attached Files
    <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

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, 03-13-2026, 05:17 AM
    0 responses
    86 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    151 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    79 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    53 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    61 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X