Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to add code for custom indicator to have plots be selectable in strategy builder

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

    How to add code for custom indicator to have plots be selectable in strategy builder

    I have created my own custom indicator with variables such as "Bandwidth." I want to be able to have these variables interactable within the strategy builder interface to make putting my strategy together easier. For example when in strategy builder, it would allow one of these plots to be selected as an input to be greater than the same plot 1 bar ago. My indicator displays perfectly and I am able to change inputs/int to a degree, but don't have that direct interaction in the strategy builder interface on being able to have a plot selected. I have tried direct coding the indicator.Bandwidth into strategy code but it does not recognize the plots.
    How would I go about adding code into the line to make sure these are able to be interacted with?

    Code:
    [HASHTAG="t3322"]region[/HASHTAG] 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 VinnyVollyBall : Indicator
    {
    private int length = 20;
    private double numDevDn = 2.0;
    private double numDevUp = 2.0;
    private int bulgeLength = 150;
    private int squeezeLength = 150;
    private int len = 20;
    private int len1 = 50;
    private int len2 = 100;
    private int len3 = 200;
    
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Indicator here.";
    Name = "VinnyVollyBall";
    Calculate = Calculate.OnBarClose;
    IsOverlay = false;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;
    DrawHorizontalGridLines = true;
    DrawVerticalGridLines = true;
    PaintPriceMarkers = true;
    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
    IsSuspendedWhileInactive = true;
    
    AddPlot(Brushes.Cyan, "Bandwidth");
    AddPlot(Brushes.Orange, "Bulge");
    AddPlot(Brushes.Orange, "Squeeze");
    AddPlot(Brushes.DarkRed, "AvgVolatility14");
    AddPlot(Brushes.DarkRed, "AvgVolatility50");
    AddPlot(Brushes.Magenta, "AvgVolatility150");
    AddPlot(Brushes.Magenta, "AvgVolatility200");
    }
    else if (State == State.Configure)
    {
    }
    }
    
    protected override void OnBarUpdate()
    {
    double upperBand = Bollinger(numDevUp, length).Upper[0];
    double lowerBand = Bollinger(numDevDn, length).Lower[0];
    double midLine = Bollinger(numDevUp, length).Middle[0];
    
    Values[0][0] = (upperBand - lowerBand) / midLine * 100;
    
    Values[1][0] = MAX(Values[0], bulgeLength)[0];
    Values[2][0] = MIN(Values[0], squeezeLength)[0];
    
    Values[3][0] = SMA(Values[0], len)[0];
    Values[4][0] = SMA(Values[0], len1)[0];
    Values[5][0] = SMA(Values[0], len2)[0];
    Values[6][0] = SMA(Values[0], len3)[0];
    
    }
    }
    }
    
    [HASHTAG="t3322"]region[/HASHTAG] NinjaScript generated code. Neither change nor remove.
    
    namespace NinjaTrader.NinjaScript.Indicators
    {
    public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
    {
    private VinnyVollyBall[] cacheVinnyVollyBall;
    public VinnyVollyBall VinnyVollyBall()
    {
    return VinnyVollyBall(Input);
    }
    
    public VinnyVollyBall VinnyVollyBall(ISeries<double> input)
    {
    if (cacheVinnyVollyBall != null)
    for (int idx = 0; idx < cacheVinnyVollyBall.Length; idx++)
    if (cacheVinnyVollyBall[idx] != null && cacheVinnyVollyBall[idx].EqualsInput(input))
    return cacheVinnyVollyBall[idx];
    return CacheIndicator<VinnyVollyBall>(new VinnyVollyBall(), input, ref cacheVinnyVollyBall);
    }
    }
    }
    
    namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
    {
    public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
    {
    public Indicators.VinnyVollyBall VinnyVollyBall()
    {
    return indicator.VinnyVollyBall(Input);
    }
    
    public Indicators.VinnyVollyBall VinnyVollyBall(ISeries<double> input )
    {
    return indicator.VinnyVollyBall(input);
    }
    }
    }
    
    namespace NinjaTrader.NinjaScript.Strategies
    {
    public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
    {
    public Indicators.VinnyVollyBall VinnyVollyBall()
    {
    return indicator.VinnyVollyBall(Input);
    }
    
    public Indicators.VinnyVollyBall VinnyVollyBall(ISeries<double> input )
    {
    return indicator.VinnyVollyBall(input);
    }
    }
    }
    
    #endregion
    Attached Files

    #2
    Hello VinnyJalapeno,

    I would suggest creating a new indicator using the new indicator wizard, that's just the new indicator option. In that wizard you can add plots, that will create public properties for the plots. By doing that all plots will be selectable in the builder.

    Comment


      #3
      Study the builtin indicators, something simple like @MACD.cs,
      take a look at the properties region.

      If you make some public properties in your indicator for the
      Values array, (either by hand or following Jesse's suggestion)
      then Strategy Builder will see those Series<double> properties
      and then you can use them.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      648 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      369 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      108 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      572 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      574 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X