Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Dual TimeFrame & Indicator on DataSeries

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

    Dual TimeFrame & Indicator on DataSeries

    Hi there,

    I am trying to get a mock-up dual-timeframe strategy up & running ... but it crashes NinjaTrader ... All it does is to use an SMA indicator on a DataSeries.

    This works perfectly on a single timeframe (comment-out Add( PeriodType.Second, 1); ) OR when using SMA( Close /* instead of aDataSeries */, 20 ) in dual-timeframe.


    Thanks in advance,
    Dominique



    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Indicator;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Strategy;
    #endregion

    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    /// <summary>
    /// Enter the description of your strategy here
    /// </summary>
    [Description("Enter the description of your strategy here")]
    public class TestDualTFv2 : Strategy
    {
    #region Variables
    // Wizard generated variables
    // User defined variables (add any user defined variables below)
    DataSeries aPriceSeries;
    #endregion

    /// <summary>
    /// This method is used to configure the strategy and is called once before any strategy method is called.
    /// </summary>
    protected override void Initialize()
    {
    // Add 2nd timeframe
    Add( PeriodType.Second, 1);

    // Add( SMA( Close, 20) );

    aPriceSeries = new DataSeries( this, MaximumBarsLookBack.Infinite);
    Add( SMA( aPriceSeries, 20) );

    CalculateOnBarClose = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {

    if (BarsInProgress == 1)
    {
    }

    if (BarsInProgress == 0)
    {
    aPriceSeries.Set( Close[0] );
    }

    } // OnBarUpdate()

    #region Properties
    #endregion
    }
    }

    #2
    Hello,

    What are you trying to plot with the aPriceSeries data series?

    If you're looking to set the SMA to the Added Second Period type, you would use

    Add(SMA(BarsArray[1], 20));
    MatthewNinjaTrader Product Management

    Comment


      #3
      Matthew,

      This is a mock-up strategy ... ultimately, what I will pass to the indicator will be nothing directly available through Highs / Lows / Closes / Opens / Volumes or simply BarsArrays (which if I am not mistaken is just another name for Closes) - so I need to calculate it & keep track of it in a DataSeries object.

      (and the indicator won't be an SMA either )


      So I would appreciate if you could get this to work using a DataSeries object, because this is what the problem is.

      Thanks in advance

      Comment


        #4
        Hello,

        Thank you for the clarification.

        You would only be able to use a default bar series in Initialize. If you are including a data series you just initiated, it would have no opportunity for the values to be set.

        If you would like to Initialize a data series in this strategy, you would need to do this from an external indicator with this data series exposed that can be referenced.
        MatthewNinjaTrader Product Management

        Comment


          #5
          There isn't much more information I can provide to help you guys figure this out ... I just spent a couple hours in Visual Studio Debugger, the crash is a System.StackOverflow that takes place beyond my strategy Initialize(), but before it ever gets to OnBarUpdate().

          I noticed that the DataSeries non-public members BufferSlots & PlotSlots are not initialized after creating a new DataSeries object (BufferSlots.Count = 0 / PlotSlots.Count), I only can hypothesize that they might be used while setting up the dual TF context before they get initialized?

          Anyway, as I said I cannot provide any more info on this.

          Comment


            #6
            To clarify as we discussed via email as well. Essentially any dynamic Add() call is basically unsupported in NinjaTrader and may or may not work. I asked development to add a count to our tracking database for user requested features for development to review for our next major release.


            What you will need to do is use this StrategyPlot sample to get this done. Basically get out of Initialize() and then initialize a dummy indicator that you will set from inside OnBarUpdate() in the strategy with your custom dataSeries. StrategyPlot does have its own set of limitations but if you just need to plot some strategy calculated data it will get the job done.



            When running a strategy on a chart you may find the need to plot values onto a chart. If these values are internal strategy calculations that are difficult to migrate to an indicator, you can use the following technique to achieve a plot. NinjaTrader 8 With NinjaTrader 8 we introduced strategy plots which provide the ability
            BrettNinjaTrader Product Management

            Comment


              #7
              Brett,

              Thank you ... I quickly tested this workaround, I think it will work for the time being.

              Cheers
              Dominique

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              637 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              366 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              107 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              569 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              571 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X