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

What is the AddPlot() function for?

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

    What is the AddPlot() function for?

    Hi,

    I have been trading and programming with Ninjatarder for a couple of weeks now. And have been able to implement quite a lot successfully (building my own indicators and stategies).
    Though I was able to draw any graphic elements, so far I have never used the AddPlot () feature.
    I read the description on the page https://ninjatrader.com/support/help...8/?addplot.htm. But unfortunately that didn't really help.


    What exactly is the AddPlot() function for?
    Maybe someone can give me an example of what you need the AddPlot() function for? (Sth that cannot be done with any other function)
    And explain it beginner-friendly.

    Thanks alot!

    #2
    Hello,

    Thanks for your post.

    In a nutshell, AddPlot() provide a means to create a line with a selected plotstyle, dashstyle, color and width for your indicator. The plot would be directed either to its own indicator panel (Based on IsOverLay = false) or in the price panel (IsOverLay = true).

    In the OnBarUpdate(), you can assign values to the plot name directly. Using the ninjascript indicator wizard I created a single plot and assigned the value of Close[0] + 3 * TickSize; to the plot. as each bar closes the plot will be updated on the chart.

    The indicator wizard also created the public series under region properties, this plot can then be read by the market analyzer, the strategy builder , or other scripts. The properties will also automatically show on the UI so the user can make any changes to the plot they wish.

    Here is the entire script generated by the wizard (except for the one line in OnBarUpdate() I added for demo.

    Code:
    #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.Gui.Tools;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion
    
    //This namespace holds Indicators in this folder and is required. Do not change it. 
    namespace NinjaTrader.NinjaScript.Indicators
    {
        public class PlotExample : Indicator
        {
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                                    = @"Enter the description for your new custom Indicator here.";
                    Name                                        = "PlotExample";
                    Calculate                                    = Calculate.OnBarClose;
                    IsOverlay                                    = true;
                    DisplayInDataBox                            = true;
                    DrawOnPricePanel                            = true;
                    DrawHorizontalGridLines                        = true;
                    DrawVerticalGridLines                        = true;
                    PaintPriceMarkers                            = true;
                    ScaleJustification                            = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                    //Disable this property if your indicator requires custom values that cumulate with each new market data event. 
                    //See Help Guide for additional information.
                    IsSuspendedWhileInactive                    = true;
                    AddPlot(Brushes.OrangeRed, "MyPlot");
                }
                else if (State == State.Configure)
                {
                }
            }
    
            protected override void OnBarUpdate()
            {
                MyPlot[0] = Close[0] + 3 * TickSize;
            }
    
            #region Properties
    
            [Browsable(false)]
            [XmlIgnore]
            public Series<double> MyPlot
            {
                get { return Values[0]; }
            }
            #endregion
    
        }
    }
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thanks. That helped me

      Comment


        #4
        Hello,

        To confirm addPlot doesn't allow you to plot dynamic values according to the tutorial. The way i understand it, if my plot = 2855,2856, 2857 and 5 seconds later it change for 2859, 2861, 2863 it wont work unless numbers stay static and there is no update? Is that right?

        It says
        Alternatively, you may use custom public Brush, Stroke, or PlotStyleproperties which are accessible in State.SetDefaultsand pass those values to AddPlot() duringState.Configure.

        Any exemple of that i could copy or get inspiration?

        Ty

        Comment


          #5
          Hello frankduc,

          Thanks for your post.

          You didn't provide a link for the tutorial you are referencing so I cannot answer on that context.

          The example provided earlier in this thread is based on the plot being driven by OnBarUpdate(). OnBarUpdate() is called based on the setting of the scripts Calculate setting: https://ninjatrader.com/support/help...?calculate.htm

          The current value of the plot depends on the setting of Calculate. If using Calculate.OnEachTick (or Calculate.OnPriceChange), the current bar of the plot is updated with each tick (or price change) and it will "dynamically" change. If Using Calculate.OnBarClose, then the plot does not draw to the currently forming bar until that bar closes.

          It is possible to change previous plot values by using the bars ago index.



          Here is an example: AddPlot(new Stroke(Brushes.Gold, DashStyleHelper.Solid, 2), PlotStyle.Line, "R4");
          Paul H.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by maybeimnotrader, Today, 05:46 PM
          0 responses
          6 views
          0 likes
          Last Post maybeimnotrader  
          Started by quantismo, Today, 05:13 PM
          0 responses
          6 views
          0 likes
          Last Post quantismo  
          Started by AttiM, 02-14-2024, 05:20 PM
          8 responses
          166 views
          0 likes
          Last Post jeronymite  
          Started by cre8able, Today, 04:22 PM
          0 responses
          8 views
          0 likes
          Last Post cre8able  
          Started by RichStudent, Today, 04:21 PM
          0 responses
          5 views
          0 likes
          Last Post RichStudent  
          Working...
          X