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

Custom Indicator Example

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

    Custom Indicator Example

    I can't find or figure out to add a custom indicator overlay to an existing indicator like you've done for VolSMA example in your help guide. When I add VolSMA to my chart it creates a bottom pane with with VolSMA plot but the volume (VOL()) itself is not displayed.

    #2
    Hello d.allen101,
    I will include an example of adding multiple indicators to the same panel through NinjaScript below. The example below uses the SMA indicator and the VOL indicator and plots two lines in the same panel based off of these indicators.

    Code:
    protected override void Initialize()
    {
    // First you need to add how many plots you are going to be using in the panel and adjust color and the Name of the plot for later use in the script
    
    Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
    Add(new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Line, "Plot1"));
    
    //if you do not want this overlaid on the current chart but rather in its own window set Overlay = false
    Overlay				= false;
    }
    
    protected override void OnBarUpdate()
    {
    //Now we set the plots values for each bar
    //This sets Plot0 to a 14 period SMA
    Plot0.Set(SMA(Close, 14)[0]);
    //This sets Plot1 to a Volume indicator for the Close
    Plot1.Set(VOL(Close)[0]);
    ///
    /// you can also do combinarions of indicators that create a whole new value like this below
    /// 
    /// Plot0.Set(VOL(SMA(Close, 14))[0]);
    /// 
    /// this would make a line that the value is the volume based off of the SMA values. 
    }
    
    #region Properties
    		
    //You need to specify there are two data series included in this indicator with the following lines
    [Browsable(false)]
    [XmlIgnore()]
    public DataSeries Plot0
    {
    get { return Values[0]; }
    }
    
    [Browsable(false)]
    [XmlIgnore()]
    public DataSeries Plot1
    {
    get { return Values[1]; }
    }
    
    #endregion
    As you can see in the example first we need to specify there will be two plots in the Initialize section.
    Next we set the values of these two plots, one to the SMA, one to the VOL indicators.
    Finally we place the public statements in the Properties region.

    One final note, If the indicators values are too far apart I.E. the SMA value is lets say 10 but your VOL is 100, the auto scaling of this chart may make it look strange or "stretched".
    Unfortunately there is not a setting for Scale Justification(Where the price markers are displayed(right or left or overlay)) through NinjaScript. If this is the case you may need to use some math to reduce the higher or increase the lower value to get it closer to the other so the chart is not "stretched". Otherwise you could put them in separate indicators and apply them to the same panel then you can adjust the scale justification for each.

    Please let me know if I may be of additional assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hi d.allen101:

      In the example, when you are adding the Indi to your chart, you need to add both the new VolSMA Indi, and the VOL Indi. You can see in the example screenshot that both have been added to the same panel: be sure when you add both indicators that in the settings, "Panel" is set to the same value for both.

      This brings up an interesting question that I've had: in the case where one Indi is using another, just like this one, could you programmatically have the VolSMA indicator ALSO plot the values from the VOL that it is using?

      I wonder about memory usage: is the Indi holding an instance of VOL; ... and then when you ALSO add VOL to the chart are there actually 2 running instances of VOL now in memory?

      ... Good luck d.allen101: feel free to ask more questions if you have ...

      Comment


        #4
        Question: does each element of Values represent each Plot that is added?

        Comment


          #5
          Hello

          You are correct, The Values[0] would be referring to the first data series added to the indicator then Values[1] would be the second.

          Values is a collection of DataSeries that are in the current Indicator.

          This is a link to the help guide reference for Values


          Looking at the example from the help guide you can see how they have accessed one indicators value to make a condition that compares it to another value

          Code:
          if (Values[1][1] < High[0] - Low[0])
          In the previous example I have posted by adding in the Public statements you are calling each of the plots by its name rather than using the index, Values selects the dataseries by its index.

          Please let me know if I may be of additional assistance
          JesseNinjaTrader Customer Service

          Comment


            #6
            Ninja Support,
            Would you please post an updated version of this ninja script example (https://ninjatrader.com/support/foru...741#post620741) for NT 8?

            I think I need a namespace , public class, and other things included for a default indicator.

            Thanks,
            v

            Comment


              #7
              Hello vlakmire5,

              The sample in the other post would be more easily created using the Indicator wizard now. In the NinjaScript editor right click the indicator folder and click new indicator. In the Plots page add two plots with the names you wanted. After generating the file it will have the same structure as the code in the other post. The only item you would need to add is setting the plots in OnBarUpdate.

              That would now look like this, I am assuming the custom plot names were SmaPlot and VolPlot.




              Code:
              SmaPlot[0] = SMA(Close, 14)[0];
              VolPlot[0] = VOL(Close)[0];
              JesseNinjaTrader Customer Service

              Comment


                #8
                thanks it worked; appreciate the help

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by wzgy0920, 04-20-2024, 06:09 PM
                2 responses
                27 views
                0 likes
                Last Post wzgy0920  
                Started by wzgy0920, 02-22-2024, 01:11 AM
                5 responses
                32 views
                0 likes
                Last Post wzgy0920  
                Started by wzgy0920, 04-23-2024, 09:53 PM
                2 responses
                49 views
                0 likes
                Last Post wzgy0920  
                Started by Kensonprib, 04-28-2021, 10:11 AM
                5 responses
                193 views
                0 likes
                Last Post Hasadafa  
                Started by GussJ, 03-04-2020, 03:11 PM
                11 responses
                3,235 views
                0 likes
                Last Post xiinteractive  
                Working...
                X