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

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.
    JesseNinjaTrader Customer Service

    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 algospoke, Today, 06:40 PM
      0 responses
      10 views
      0 likes
      Last Post algospoke  
      Started by maybeimnotrader, Today, 05:46 PM
      0 responses
      7 views
      0 likes
      Last Post maybeimnotrader  
      Started by quantismo, Today, 05:13 PM
      0 responses
      7 views
      0 likes
      Last Post quantismo  
      Started by AttiM, 02-14-2024, 05:20 PM
      8 responses
      168 views
      0 likes
      Last Post jeronymite  
      Started by cre8able, Today, 04:22 PM
      0 responses
      10 views
      0 likes
      Last Post cre8able  
      Working...
      X