Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

working with addplot and colors in parameters

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

    working with addplot and colors in parameters

    I created an ema that changes colors but in the parameter section I still have the original addplot. how to I access in order to change it in my parameters. this is what I have


    //this is in State.SetDefaults
    AddPlot(eEMALongBrushColor, NinjaTrader.Custom.Resource.NinjaScriptIndicatorNa meEMA);


    // this is in my parameters

    //TASK:SET THE SHORT/PUT DOT COLOR
    //DEFAULT: BLUE
    //VALUE: ENUMERATION
    private Brush eEMAShortBrushColor = Brushes.Red;
    [XmlIgnore()]
    [NinjaScriptProperty]
    [Display(Name = "EMA Short Color", Description = "", GroupName = "Plots")]
    public Brush EMAShortBrushColor
    {
    get { return eEMAShortBrushColor; }
    set { eEMAShortBrushColor = value; }
    }

    // Serialize Color object
    [Browsable(false)]
    public string EMAShortBrushColorSerialize
    {
    get { return Serialize.BrushToString(eEMAShortBrushColor); }
    set { eEMAShortBrushColor = Serialize.StringToBrush(value); }
    }

    //TASK:SET THE SHORT/PUT DOT COLOR
    //DEFAULT: BLUE
    //VALUE: ENUMERATION
    private Brush eEMALongBrushColor = Brushes.Green;
    [XmlIgnore()]
    [NinjaScriptProperty]
    [Display(Name = "EMA Long Color", Description = "", GroupName = "Plots")]
    public Brush EMALongBrushColor
    {
    get { return eEMALongBrushColor; }
    set { eEMALongBrushColor = value; }
    }

    // Serialize Color object
    [Browsable(false)]
    public string eEMALongBrushColorSerialize
    {
    get { return Serialize.BrushToString(eEMALongBrushColor); }
    set { eEMALongBrushColor = Serialize.StringToBrush(value); }
    }




    Do I have to make a custom addplot and create all custom brushes line sizes etc or is there a way to access the custom indicator?

    AddPlot(Brushes.Black,"PlotEMA");

    I want to get rid of the goldenrod color and access the dashlines
    Attached Files

    #2
    Hello ballboy11,

    Thanks for your post.

    When you add a plot it will automatically create the UI parameters so the user can change the plot color and line size, etc. etc. If you would prefer to control those yourself you can add this line in state.SetDefaults: ArePlotsConfigurable = false; Reference: http://ninjatrader.com/support/helpG...nfigurable.htm

    You do not need to create private Brushes and can save yourself some code effort. Here is an example of all you would need:

    In state.SetDefaults is: MARisingColor = Brushes.Green;

    In the properties section is:
    [XmlIgnore]
    [Display(Name="MA Rising Color", Description="Color of MA when rising", Order=6, GroupName="Options")]
    public Brush MARisingColor
    { get; set; }

    [Browsable(false)]
    public string MARisingColorSerializable
    {
    get { return Serialize.BrushToString(MARisingColor); }
    set { MARisingColor = Serialize.StringToBrush(value); }
    }


    That is all you need for each brush. Note that the example does not use [NinjaScriptProperty] This is optional if you want to be able to set this brushcolor via a strategy for example. Reference: http://ninjatrader.com/support/helpG...yattribute.htm

    In OnBarUpdate() you could use the brush for example like: PlotBrushes[0][0] = MARisingColor;

    If you want the user to be able to set other plot properties you would need to create additional public properties for those. For example the width of the plot would be a simple int:

    [Range(1, 19)]
    [Display(Name="MA Plot Line width", Description="Set thickness of plot line", Order=1, GroupName="Options")]
    public int MALineWidth
    { get; set; }


    To set the dashstyle you could use for example:

    [Display(Name="MA Line DashStyle", Description="Set dash style of line", Order=3, GroupName="Options")]
    public DashStyleHelper MADashStyle
    { get; set; }


    To set the plot style of the line:

    [Display(Name="MA Line PlotStyle", Description="Set type of line/cross/bar/square/etc", Order=2, GroupName="Options")]
    public PlotStyle MAPlotStyle
    { get; set; }


    Keep in mind that each of these would also need a statement in the State.SetDefaults, for example:

    MALineWidth = 2;
    MAPlotStyle = PlotStyle.Line;
    MADashStyle = DashStyleHelper.Solid;


    In state.Configure you can then set the plot parameters, for example:
    else if (State == State.Configure)
    {
    Plots[0].Width = MALineWidth;
    Plots[0].PlotStyle = MAPlotStyle;
    Plots[0].DashStyleHelper = MADashStyle;
    }

    Comment


      #3
      i think I understand.
      To get this straight I can not change the parameter names on the addPlot list for example
      when you look at the parameters it states Color.
      I can not change Color to the name Long Color.
      I would have to create each one color line size dash etc.

      If I create all the parameters how would I plot?
      .

      Comment


        #4
        I do have the plot working for the colors I want to use all I wanted to do was change the name from Color to to Long Color.

        I used this

        if(EMA(nEMADays)[0]>EMA(nEMADays)[1])
        PlotBrushes[0][0] = eEMALongBrushColor;
        else
        PlotBrushes[0][0] = eEMAShortBrushColor;

        Values[0][0] = EMA(nEMADays)[0];

        but because I used

        AddPlot(eEMALongBrushColor,"PlotEMA" ); in the State.SetDefaults

        I still have and extra
        Color parameter that is never used as in the picture below.
        Attached Files
        Last edited by ballboy11; 07-06-2017, 10:37 AM.

        Comment


          #5
          Originally posted by NinjaTrader_Paul View Post
          Hello ballboy11,

          Thanks for your post.

          When you add a plot it will automatically create the UI parameters so the user can change the plot color and line size, etc. etc. If you would prefer to control those yourself you can add this line in state.SetDefaults: ArePlotsConfigurable = false; Reference: http://ninjatrader.com/support/helpG...nfigurable.htm

          [/I]
          Did you use ArePlotsConfigurable = false; ?

          Comment


            #6
            Yes



            if (State == State.SetDefaults) //INTITAL STARTUP PARAMETERS FOR THE UI
            {
            Description = @"";
            Name = "testPilot";
            Calculate = Calculate.OnBarClose;
            IsOverlay = true;
            DisplayInDataBox = true;
            DrawOnPricePanel = true;
            DrawHorizontalGridLines = false;
            DrawVerticalGridLines = false;
            PaintPriceMarkers = true;
            ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;

            ArePlotsConfigurable = false;

            Comment


              #7
              Hello ballboy11,

              Thanks for your reply.

              With ArePlotsConfigurable set to false, in the UI panel you should not see the PlotEMA at all. Can you confirm that you have compiled the indicator, removed from the chart then reapplied it?

              Here is a short video to demonstrate this: https://Paul-ninjaTrader.tinytake.co...gxOF81Nzc1MTIw

              Comment


                #8
                Thanks that did it. Last quesiton. Can one allow certain plots to be adjusted and others not or if I set it to false I would have to manually add all my parameters for plots

                Comment


                  #9
                  Hello ballboy11,

                  Thanks for your reply.

                  Correct when set to false you would have to expose all the plot properties you choose to for each plot. You might want to take a look at the NT8 version of MACrossBuilder for an example: http://ninjatrader.com/support/forum...hp?&linkid=906

                  Comment


                    #10
                    Thank you. You have been a great help.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    576 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    334 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    101 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    553 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    551 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X