Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Color main price plot

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

    Color main price plot

    I am trying to color the main price bars based on conditions but can't find the code to do so. I have tried all of the following but I don't think I have the syntax right. Any help would be appreciated.

    if ( condition == true)
    {
    Plots[0].Pen = new Pen(Color.Gold);
    Plots[1][0].Pen = Brushes.Gold;
    BarBrush = Plots[1].Color.Gold;

    }

    #2
    Hello EthanHunt,

    Thanks for opening the thread.

    You can programatically change the color of each bar by changing the Brush associated with BarBrush.

    Here is the sample code taken from the help guide:
    Code:
    protected override void OnBarUpdate()
    {
        // Sets the bar color to yellow
        BarBrush = Brushes.Yellow;
     
        // Sets the brush used for the bar color to its default color as defined in the chart properties dialog
        BarBrush = null;
     
        // Sets the bar color to yellow if the 20 SMA is above the 50 SMA and the closing
        // price is above the 20 SMA (see image below)
        if (SMA(20)[0] > SMA(50)[0] && Close[0] > SMA(20)[0])
            BarBrush = Brushes.Yellow;
    }
    https://ninjatrader.com/support/help.../?barbrush.htm

    If you have any additional questions, please don't hesitate to ask.

    Comment


      #3
      That's exactly what I was looking for, thank you.


      Originally posted by NinjaTrader_Jim View Post
      Hello EthanHunt,

      Thanks for opening the thread.

      You can programatically change the color of each bar by changing the Brush associated with BarBrush.

      Here is the sample code taken from the help guide:
      Code:
      protected override void OnBarUpdate()
      {
          // Sets the bar color to yellow
          BarBrush = Brushes.Yellow;
       
          // Sets the brush used for the bar color to its default color as defined in the chart properties dialog
          BarBrush = null;
       
          // Sets the bar color to yellow if the 20 SMA is above the 50 SMA and the closing
          // price is above the 20 SMA (see image below)
          if (SMA(20)[0] > SMA(50)[0] && Close[0] > SMA(20)[0])
              BarBrush = Brushes.Yellow;
      }
      https://ninjatrader.com/support/help.../?barbrush.htm

      If you have any additional questions, please don't hesitate to ask.

      Comment

      Latest Posts

      Collapse

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