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

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:	90
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
        Brandon H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by JoMoon2024, Today, 06:56 AM
        0 responses
        6 views
        0 likes
        Last Post JoMoon2024  
        Started by Haiasi, 04-25-2024, 06:53 PM
        2 responses
        17 views
        0 likes
        Last Post Massinisa  
        Started by Creamers, Today, 05:32 AM
        0 responses
        5 views
        0 likes
        Last Post Creamers  
        Started by Segwin, 05-07-2018, 02:15 PM
        12 responses
        1,786 views
        0 likes
        Last Post Leafcutter  
        Started by poplagelu, Today, 05:00 AM
        0 responses
        3 views
        0 likes
        Last Post poplagelu  
        Working...
        X