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

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 CortexZenUSA, Today, 12:53 AM
              0 responses
              1 view
              0 likes
              Last Post CortexZenUSA  
              Started by CortexZenUSA, Today, 12:46 AM
              0 responses
              1 view
              0 likes
              Last Post CortexZenUSA  
              Started by usazencortex, Today, 12:43 AM
              0 responses
              5 views
              0 likes
              Last Post usazencortex  
              Started by sidlercom80, 10-28-2023, 08:49 AM
              168 responses
              2,266 views
              0 likes
              Last Post sidlercom80  
              Started by Barry Milan, Yesterday, 10:35 PM
              3 responses
              13 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Working...
              X