• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Custom Indicator Example

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

  • d.allen101
    started a topic Custom Indicator Example

    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.

  • NinjaTrader_Jesse
    replied
    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
    http://www.ninjatrader.com/support/h...tml?values.htm

    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

    Leave a comment:


  • d.allen101
    replied
    Question: does each element of Values represent each Plot that is added?

    Leave a comment:


  • steevcoco
    replied
    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 ...

    Leave a comment:


  • NinjaTrader_Jesse
    replied
    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.

    Leave a comment:

Latest Posts

Collapse

Topics Statistics Last Post
Started by seagraph, Today, 03:27 PM
0 responses
11 views
0 likes
Last Post seagraph  
Started by dedouglas, Today, 02:54 PM
1 response
14 views
0 likes
Last Post NinjaTrader_Jesse  
Started by elkhatabi, 08-01-2019, 06:36 PM
5 responses
53 views
0 likes
Last Post NinjaTrader_RyanL  
Started by mr_trade, Today, 01:01 PM
4 responses
19 views
0 likes
Last Post mr_trade  
Started by Renorail, Today, 12:31 PM
1 response
14 views
0 likes
Last Post NinjaTrader_PaulH  
Working...
X