Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Chart Bar colors (temporarily hide current bar)

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

    Chart Bar colors (temporarily hide current bar)

    Hello,

    I would like to hide the current bar until it is has reached 50% completion.

    e.g for a 1000 volume bar chart series (candlesticks), i would like to hide the current bar until the volume remaining is 500.

    I have the following code for my indicator, it compiles ok, but nothing happens in the chart.

    protected override void OnBarUpdate()
    {

    if (Bars.PercentComplete < 0.5);
    BarBrush = Brushes.Transparent;
    CandleOutlineBrush = Brushes.Transparent;

    if (Bars.PercentComplete > 0.5);
    BarBrush = null;
    CandleOutlineBrush = null;
    }

    Thanks
    Last edited by arsene007; 09-29-2017, 10:14 AM.

    #2
    Hello,

    Thank you for the post.

    You nearly have the correct syntax to accomplish this, you are only missing one part, and have a syntax error with your if statements.

    First, the important part is the if statements are not formed with a body, you have a semicolon ending the if statements:

    Code:
    if (Bars.PercentComplete < 0.5)[B];   <---[/B]
    You need a body to the if statement instead of a semicolon:

    Code:
    if (Bars.PercentComplete < 0.5) 
    [B]{
    
    }[/B]
    Both if statements need this modification, and after doing this you still need to account for Historical bars being transparent. You noted you only want the current bar colored, this means as soon as the next bar happens you have no logic to reset the bar that was transparent. Right now if you run the script, all bars will be transparent. To correct this, please see the modification using BarBrushes[1] and CandleOutlineBrushes[1].


    Code:
    if(CurrentBar > 1) // needed because a BarsAgo of 1 is used
    {
    	BarBrushes[1] = null;  //reset the prior bars value
    	CandleOutlineBrushes[1] = null;  //reset the prior bars value
    	
            if (Bars.PercentComplete < 0.5){
    		BarBrush = Brushes.Transparent;
    		CandleOutlineBrush = Brushes.Transparent;
    	}
    
    	if (Bars.PercentComplete > 0.5){
    		BarBrush = null;
    		CandleOutlineBrush = null;
    	}
    }
    One final note is that this indicator would need to be run as OnEachTick or OnPriceChange to see the percent complete updated in realtime. Using OnBarClose will not allow the bar to be updated until the bar closes.





    I look forward to being of further assistance.

    Comment


      #3
      Thanks a lot Jesse, that is exactly what i want. Thanks for taking the time to show the correct syntax, i appreciate.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      648 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      369 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      108 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      572 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      574 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X