Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How do I pass and Enum to an indicator

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

    How do I pass and Enum to an indicator

    I've reviewed a few posts related to this topic, but can't quite get it.

    I have a simple Enum

    public class Enums : Indicator
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Indicator here.";
    Name = "Enums";
    Calculate = Calculate.OnBarClose;
    IsOverlay = false;
    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;
    }
    else if (State == State.Configure)
    {
    }
    }

    protected override void OnBarUpdate()
    {
    //Add your custom indicator logic here.
    }
    }
    }

    namespace ENUMS
    {
    public enum INDICATORS
    {
    UO,
    MACD,
    RSI,
    Stoch,
    StochRSI,
    Multi
    }
    }​

    I use that as the first input into my Indicator, BBDivergence. This works great. There are 3 other inputs, all bool.

    region Properties

    [Display(GroupName = "Parameters", Description="Choose an Indicator.")]
    public ENUMS.INDICATORS IndyType
    {
    get { return indyType; }
    set { indyType = value; }
    }


    [NinjaScriptProperty]
    [Display(Name="ShowDivergenceLines", Description="", Order=2, GroupName="Parameters")]
    public bool ShowDivergenceLines
    { get; set; }

    [NinjaScriptProperty]
    [Display(Name="ShowPriceDots", Description="", Order=3, GroupName="Parameters")]
    public bool ShowPriceDots
    { get; set; }

    [NinjaScriptProperty]
    [Display(Name="UseLightBackground", Description="", Order=4, GroupName="Parameters")]
    public bool UseLightBackground
    { get; set; }

    [Browsable(false)][XmlIgnore()]
    public Series<int> Divergence {get {return divergence;}}

    #endregion

    }​

    I have another indicator where I want to use the output of BBDivergence. But when i try to pass the Enum as a parameter so that I can use the output of BBDivergence, I get an error
    protected override void OnBarUpdate()
    {
    //Add your custom indicator logic here.

    divergence = BBDivergence(ENUMS.INDICATORS.UO, false, true, false).Divergence[0];

    if(Math.Abs(divergence) == 1)
    {
    DrawDivergence();
    }

    }
    Click image for larger version

Name:	image.png
Views:	198
Size:	7.1 KB
ID:	1275206

    If I leave the enum out of the paameters and only pass the 3 bools, it works, but only for the first choice from the enum list. I'd like to call BBDivergence for each Enum value.

    What am I doing wrong.

    #2
    Add NinjaScriptProperty attribute like this:

    [Display(GroupName = "Parameters", Description = "Choose an Indicator."), NinjaScriptProperty]
    ​public ENUMS.INDICATORS IndyType
    {
    get { return indyType; }
    set { indyType = value; }
    }​

    Comment


      #3
      Perfect
      Thank you

      Comment


        #4
        Hello cre8able,

        Thanks for your notes.

        Leeroy_Jenkins is correct in the information that they provided.

        You would need to make sure you are using the NinjaScriptProperty Attribute on your public enum property.

        See this help guide page for more information on NinjaScriptProperty Attribute: https://ninjatrader.com/support/help...yattribute.htm
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        598 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        343 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        103 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        557 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        555 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X