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

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.
      Paul H.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Kraken29, Today, 12:32 PM
      1 response
      6 views
      0 likes
      Last Post NinjaTrader_Erick  
      Started by codeowl, 02-11-2019, 05:47 AM
      23 responses
      678 views
      0 likes
      Last Post stockbux  
      Started by arangocj, Today, 12:37 PM
      0 responses
      11 views
      0 likes
      Last Post arangocj  
      Started by joselube001, Today, 12:17 PM
      1 response
      10 views
      0 likes
      Last Post NinjaTrader_Erick  
      Started by marcus2300, Today, 10:21 AM
      5 responses
      13 views
      0 likes
      Last Post RaddiFX
      by RaddiFX
       
      Working...
      X