Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to set Chart Panel Background Color

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

    How to set Chart Panel Background Color

    As I understand, I need to add the following background color code to the Indicator I have opened in a separate Panel. Assuming I should add this to 'OnBarUpdate' section, how would it be added to the below cited code?

    Code:
    // Sets the chart panel back color to pale green
    BackBrush = Brushes.PaleGreen;​
    Code:
            protected override void OnBarUpdate()
            {
                if (CotData.GetCotReportNames(Instrument.MasterInstrument.Name).Count == 0)
                {
                    Draw.TextFixed(this, "Error", Custom.Resource.CotDataError, TextPosition.BottomRight);
                    return;
                }
    
                if (!Core.Globals.MarketDataOptions.DownloadCotData)
                    Draw.TextFixed(this, "Warning", Custom.Resource.CotDataWarning, TextPosition.BottomRight);
    
                if (CotData.IsDownloadingData)
                {
                    Draw.TextFixed(this, "Warning", Custom.Resource.CotDataStillDownloading, TextPosition.BottomRight);
                    return;
                }
    
                for (int i = 0; i < Number; i++)
                {
                    if (!backCalculated && CurrentBar > 0)
                    {
                        for (int j = CurrentBar - 1; j >= 0; j--)
                        {
                            double value1 = reports[i].Calculate(Instrument.MasterInstrument.Name, Time[j]);
                            if (!double.IsNaN(value1)) // returns NaN if Instrument/Report combination is not valid.
                                Values[i][j] = value1;
                        }
                    }
                    double value = reports[i].Calculate(Instrument.MasterInstrument.Name, Time[0]);
                    if (!double.IsNaN(value)) // returns NaN if Instrument/Report combination is not valid.
                        Values[i][0] = value;
                }
                backCalculated = true;
            }​

    #2
    Hello sastrades,

    Thanks for your post.

    Correct, BackBrush should be set in the OnBarUpdate() section of a custom NinjaScript.

    Where exactly BarsBrush should be set in the code you shared would be up to you depending on what your overall goal is and what you are trying to accomplish. For example, if you want to set the BackBrush when you are drawing text on the chart, BackBrush should be set one line above or below where you are calling Draw.TextFixed().


    See this help guide page for more information about BackBrush: https://ninjatrader.com/support/help.../backbrush.htm
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      In your example (cited below), you simply have it added to the OnBarUpdate() section. What I'm asking is where and how would the backbrush code look like in my example code?

      Code:
      protected override void OnBarUpdate()
      {
          // Sets the chart panel back color to pale green
          BackBrush = Brushes.PaleGreen;
      }​

      Comment


        #4
        Hello sastrades,

        Thanks for your notes.

        This would ultimately depend on what you are trying to accomplish.

        To accurately assist you, can you provide us with a brief description of what you are trying to accomplish?

        As stated in post # 2, if you want to change chart panel back color when you are drawing text on the chart you could consider setting BackBrush one line after calling your Draw.TextFixed() method.

        Code:
        if (CotData.GetCotReportNames(Instrument.MasterInstrument.Name).Count == 0)
        {
        Draw.TextFixed(this, "Error", Custom.Resource.CotDataError, TextPosition.BottomRight);
        BackBrush = Brushes.Red;
        return;
        
        }​
        If you want to simply set the BackBrush for each bar update, you could set BackBrush at the top of your OnBarUpdate() logic.

        Code:
        protected override void OnBarUpdate()
        {​
        BackBrush = Brushes.Yellow;
        
        //your custom logic here
        }
        Or, if you want to change the chart panel back color when backCalculated is true, you could create a condition checking if the bool is true and set the BackBrush.

        Code:
        if (backCalculated)
        {
        BackBrush = Brushes.Blue;
        }
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          Thank you for your help. I'm not a programmer, so I am lost with your question/solution, ie. what 'logic' should I be looking for? I just want the panel background to have a different shade (all the time) than my main chart panel area.

          Comment


            #6
            Hello sastrades,

            Thanks for your notes.

            To change the chart panel back color for each bar update, set BarBrush at the top of your OnBarUpdate() code.

            For example, this might look something like this:

            Code:
            protected override void OnBarUpdate()
            {​
            BackBrush = Brushes.Yellow;
            
            //rest of your code here
            }
            Brandon H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by lightsun47, Today, 03:51 PM
            0 responses
            4 views
            0 likes
            Last Post lightsun47  
            Started by 00nevest, Today, 02:27 PM
            1 response
            8 views
            0 likes
            Last Post 00nevest  
            Started by futtrader, 04-21-2024, 01:50 AM
            4 responses
            44 views
            0 likes
            Last Post futtrader  
            Started by Option Whisperer, Today, 09:55 AM
            1 response
            13 views
            0 likes
            Last Post bltdavid  
            Started by port119, Today, 02:43 PM
            0 responses
            8 views
            0 likes
            Last Post port119
            by port119
             
            Working...
            X