Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using Chart Background Color for Plots

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

    Using Chart Background Color for Plots

    Dear Support,

    In some cases I use the chart background color for plots instead of "Transparent" in NT7.

    When converting to NT8, what is the syntax in NT8 to use the chart background color instead of "Brushes.Green" in this example?


    AddPlot(Brushes.Green, "Plot1");

    Thanks.

    #2
    Originally posted by aligator View Post
    what is the syntax in NT8 to use the chart background color instead of "Brushes.Green" in this example?
    AddPlot(Brushes.Green, "Plot1");
    ChartControl.Properties.ChartBackground. However, you will need to make sure that ChartControl != null first, so you'll probably need a variable for the brush that you assign in State.Historical and then apply to the plot.

    Comment


      #3
      Originally posted by tradesmart View Post
      ChartControl.Properties.ChartBackground. However, you will need to make sure that ChartControl != null first, so you'll probably need a variable for the brush that you assign in State.Historical and then apply to the plot.
      Thanks,

      To use the chart background brush instead of the "Brushes.Green" for Plot1:

      Code:
      AddPlot(Brushes.Green, "Plot1");
      I used the following and did not work.

      Code:
      else if (State == State.Historical)
          {
             if (ChartControl != null)
             {
                AddPlot(ChartControl.Properties.ChartBackground, "Plot1");	
             }
          }
      Do I need to include a parameter such as the following:

      Code:
      private Brush   plotColor   = ChartControl.Properties.ChartBackground;
      and use plotColor instead?

      Comment


        #4
        Hello aligator,

        AddPlot was intended to be called from State.SetDefaults (if you would like the user to be able to configure the plot) or State.Configure.


        I would recommend you add the plots in State.Configure if you would like to hide these, and set the color to either Brushes.Empty or to ChartControl.Properties.ChartBackground in State.DataLoaded.


        Code:
        protected override void OnStateChange()
        {
        if(State == State.SetDefaults)
        {
        Name = "Examples Indicator";
        AddPlot(Brushes.Orange, "Plot1"); // Stored in Plots[0]
        }
        else if (State == State.DataLoaded)
        {
        if (ChartControl != null)
        {
        Plots[0].Brush = ChartControl.Properties.ChartBackground;
        }
        }
        }
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_ChelseaB View Post
          Hello aligator,

          AddPlot was intended to be called from State.SetDefaults (if you would like the user to be able to configure the plot) or State.Configure.


          I would recommend you add the plots in State.Configure if you would like to hide these, and set the color to either Brushes.Empty or to ChartControl.Properties.ChartBackground in State.DataLoaded.


          Code:
          protected override void OnStateChange()
          {
          if(State == State.SetDefaults)
          {
          Name = "Examples Indicator";
          AddPlot(Brushes.Orange, "Plot1"); // Stored in Plots[0]
          }
          else if (State == State.DataLoaded)
          {
          if (ChartControl != null)
          {
          Plots[0].Brush = ChartControl.Properties.ChartBackground;
          }
          }
          }
          Thank you Chelsea,

          I just was following a suggestion in Post#2 to use the State.Historical.

          In your example above, is it possible to just directly use "ChartControl.Properties.ChartBackground" instead of "Orange" in your AddPlot statement without the need for Plot[0].Brush statement?

          Thanks a bunch.

          Comment


            #6
            No, ChartControl is not available when State.SetDefaults, so it's a two-step process: first you add the plot in SetDefaults or Configure, then, when ChartControl is no longer null (DataLoaded or Historical), you adjust the plot color.

            Comment


              #7
              Hi aligator,

              tradesmart is correct. AddPlot() needs to be called in State.SetDefaults. ChartControl is not available until State.DataLoaded.

              If you want to use the background color, you will need to wait until the chart background is ready before using that value.

              Anytime using anything with ChartControl, always wait until State.DataLoaded and always check that ChartControl is not null.
              Chelsea B.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              571 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              331 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
              549 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              549 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X