Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

BarColor of current realtime forming bar only

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

    BarColor of current realtime forming bar only

    Please can someone help me. I am trying to change the bar color and outline color of the current forming bar only.

    I use the following code:
    protected override void OnBarUpdate()
    {
    if (CurrentBar == Count -1) //Current Bar Only
    {
    CandleOutlineColor = Color.LightGray;
    BarColor = Color.LightGray;
    }
    }


    However when the current bar closes, it keeps the color that I am setting rather than returning to the default data series bar and outline colors as defined in the data series. I need to recalculate the indicator to repaint the bars that have closed since the last time the indicator was inserted or recalculated.

    How do I make it so that only the current bar has a different color and when it closes it gets the default data series color?

    Many thanks.

    #2
    OK I managed to fix it using the series variables instead and resetting the previous bar to the default.

    Not sure if this is the most efficient way, but it works.


    protected override void OnBarUpdate()
    {
    if (CurrentBar == Count -1) //Current Bar Only
    {
    CandleOutlineColorSeries[0] = Color.LightGray;
    CandleOutlineColorSeries[1] = Color.Empty; //Resets previous bar to default
    BarColorSeries[0] = Color.LightGray;
    BarColorSeries[1] = Color.Empty; //Resets previous bar to default
    }
    }

    Comment


      #3
      Hello petermb,

      Thanks for your post(s) and welcome to the NinjaTrader forums!

      Your solution is the best.

      Comment

      Latest Posts

      Collapse

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