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 Mizzouman1, Today, 07:35 AM
      4 responses
      18 views
      0 likes
      Last Post Mizzouman1  
      Started by philmg, Today, 01:17 PM
      1 response
      4 views
      0 likes
      Last Post NinjaTrader_ChristopherJ  
      Started by cre8able, Today, 01:01 PM
      1 response
      6 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by manitshah915, Today, 12:59 PM
      1 response
      3 views
      0 likes
      Last Post NinjaTrader_Erick  
      Started by ursavent, Today, 12:54 PM
      1 response
      4 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Working...
      X