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

Plotting a custom dataseries

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

    Plotting a custom dataseries

    Hi,

    how do I plot a custom dataseries?

    I create the dataseries with
    myDataSeries = new DataSeries(this,MaximumBarsLookBack.Infinite);
    just fine.And I've checked with Print that I actually get values into the dataseries. But how do I get the dataseries to plot as well?

    Thx,
    Eelofi

    #2
    Hello Eelofi,

    Thank you for your inquiry.

    In order to plot out values in your DataSeries, you would need to first use the Add() method to create a new plot in your Initialize() method. For example:

    Code:
    Add(new Plot(Color.Blue, PlotStyle.Line, "myDataSeriesPlot"));
    In order for you to assign values to this new Plot and have things plot out,you will use the Set() method. For example:

    Code:
    myDataSeriesPlot.Set(myDataSeries[x]);
    You would be able to access the values in myDataSeries with an indexer and use the Set() method in your Plot to place those values into your plot.

    Also, please ensure that you have created a property for myDataSeriesPlot as well. For example:
    Code:
    [Browsable(false)]
    [XmlIgnore()]
    public DataSeries myDataSeriesPlot
    {
          get { return Values[x]; }
    }
    Where x would reference the indexer of myDataSeriesPlot. In this case, it would be 1 if you created your DataSeries object before the Plot.
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      Thanks Zachary,

      I'm still too new to NJ to really understand what I'm missing here.

      This is the simplified code I tried out, which doesn't compile. It doesn't compile even if I add "private DataSeries myDataSeriesPlot;". The code was simplified to the level that I'm only setting a static value to be plotted, just understand plotting a dataseries.

      What am I doing wrong?

      Thx,
      Eelofi

      namespace NinjaTrader.Strategy
      {
      /// <summary>
      /// Testing plotting from a custom dataseries
      /// </summary>
      [Description("Testing plotting from a custom dataseries")]
      public class Eelofitest20150701 : Strategy
      {
      //#region Variables
      //#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()
      {
      CalculateOnBarClose = true;

      Add(new Plot(Color.Blue, PlotStyle.Line, "myDataSeriesPlot"));
      }

      /// <summary>
      /// Called on each bar update event (incoming tick)
      /// </summary>
      protected override void OnBarUpdate()
      {
      myDataSeriesPlot.Set(1);
      Print (Time+" "+myDataSeriesPlot[0]);
      }

      #region Properties
      [Browsable(false)]
      [XmlIgnore()]
      public DataSeries myDataSeriesPlot
      {
      get { return Values[0]; }
      }
      #endregion
      }
      }

      Comment


        #4
        Hello eelofi,

        The methods and syntax I have provided are for an indicator, not a strategy. It looks like you are trying to use this in a strategy.

        You would need to create an indicator first. If you would like to add this indicator to your strategy, you will use this in the Initialize() method:
        Code:
        Add(indicatorName(parameters));
        Please, let us know if we may be of further assistance.
        Zachary G.NinjaTrader Customer Service

        Comment


          #5
          Thx Zachary,

          got it to work! Created a custom indicator and am able to plot it in the strategy completely ok.

          Br,
          Eelofi

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Max238, Today, 01:28 AM
          2 responses
          26 views
          0 likes
          Last Post NinjaTrader_ChristopherJ  
          Started by Shansen, 08-30-2019, 10:18 PM
          25 responses
          949 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Started by JonesJoker, 04-22-2024, 12:23 PM
          8 responses
          41 views
          0 likes
          Last Post JonesJoker  
          Started by timko, Today, 06:45 AM
          0 responses
          4 views
          0 likes
          Last Post timko
          by timko
           
          Started by Waxavi, 04-19-2024, 02:10 AM
          2 responses
          39 views
          0 likes
          Last Post poeds
          by poeds
           
          Working...
          X