Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multiple Time Frame

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

    Multiple Time Frame

    I am using your SampleMultipleTimeFrame strategy and trying to get the 6 SMA to show on a 1 minute chart and get the 5min and 10min to also show on the same chart

    this is the modifications to your script that i have so far

    when place on chart i only get the 1 min SMAs

    could you tell me what am I doing wrong

    Thank you for help in advance

    Richard

    /
    // Copyright (C) 2022, NinjaTrader LLC <www.ninjatrader.com>.
    // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
    //
    #region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.Indicators;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion

    //This namespace holds strategies in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class SampleMultiTimeFrame2 : Strategy
    {
    private SMA sma50B0;
    private SMA sma50B1;
    private SMA sma50B2;
    private SMA sma5B0;
    private SMA sma5B1;
    private SMA sma5B2;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = NinjaTrader.Custom.Resource.NinjaScriptStrategyDes criptionSampleMultiTimeFrame;
    Name = "SampleMultiTimeFrame2";
    // This strategy has been designed to take advantage of performance gains in Strategy Analyzer optimizations
    // See the Help Guide for additional information
    IsInstantiatedOnEachOptimizationIteration = false;
    }
    else if (State == State.Configure)
    {
    // Add a 5 minute Bars object to the strategy
    AddDataSeries(Data.BarsPeriodType.Minute, 5);

    // Add a 15 minute Bars object to the strategy
    AddDataSeries(Data.BarsPeriodType.Minute, 10);
    }
    else if (State == State.DataLoaded)
    {
    // Best practice is to instantiate indicators in State.DataLoaded.
    sma50B0 = SMA(50);
    sma5B0 = SMA(5);

    // Note: Bars are added to the BarsArray and can be accessed via an index value
    // E.G. BarsArray[1] ---> Accesses the 5 minute Bars object added above
    sma50B1 = SMA(BarsArray[1], 50);
    sma50B2 = SMA(BarsArray[2], 50);
    sma5B1 = SMA(BarsArray[1], 5);
    sma5B2 = SMA(BarsArray[2], 5);

    // Add simple moving averages to the chart for display
    // This only displays the SMA's for the primary Bars object on the chart
    // Note only indicators based on the charts primary data series can be added.
    AddChartIndicator(sma5B0);
    AddChartIndicator(sma5B1);
    AddChartIndicator(sma5B2);
    AddChartIndicator(sma50B0);
    AddChartIndicator(sma50B1);
    AddChartIndicator(sma50B2);
    }
    }

    #2
    Hello richbois,

    Thanks for your post.

    AddChartIndicator() can only place indicators on the chart that use the primary series. It cannot place indicators on the chart that use a secondary added series. This could be seen in Notes section of the AddChartIndicator() help guide page.

    From the help guide page: "An indicator being added via AddChartIndicator() cannot use any additional data series hosted by the calling strategy, but can only use the strategy's primary data series. If you wish to use a different data series for the indicator's input, you can add the series in the indicator itself and explicitly reference it in the indicator code (please make sure though the hosting strategy has the same AddDataSeries() call included as well)"

    See the AddChartIndicator() help guide page for more information: https://ninjatrader.com/support/help...tindicator.htm

    Let us know if we may assist further.
    <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


      #3
      Thank you for the info

      Comment


        #4
        1 more question if i may is it possible to hard code the time frame in an indicator ??

        Comment


          #5
          Hello richbois,

          Thanks for your note.

          Yes, as stated in the Notes section of the AddDataSeries() help guide: If you wish to use a different data series for the indicator's input, you can add the series in the indicator itself and explicitly reference it in the indicator code (please make sure though the hosting strategy has the same AddDataSeries() call included as well.

          You could add a data series in the indicator using AddDataSeries() and then have the indicator calculate logic using that added series by referencing the BarsInProgress value of the added series and assigning a value(s) to the plot(s).

          AddDataSeries(): https://ninjatrader.com/support/help...dataseries.htm
          BarsInProgress: https://ninjatrader.com/support/help...inprogress.htm

          And, see this help guide page for information about working with Multi-TimeFrame/Instrument scripts: https://ninjatrader.com/support/help...nstruments.htm

          Let us know if we may assist further.
          <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, Today, 05:17 AM
          0 responses
          23 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          120 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          63 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          41 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          45 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X