• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.


No announcement yet.

Partner 728x90


Change only first bar color that meets criteria

  • Filter
  • Time
  • Show
Clear All
new posts

    Change only first bar color that meets criteria


    I have created most of my bar color indicator but am lacking two items that i can not figure out how to do.

    We will use an SMA for the example.

    I want only the first bullish candle that closes above the SMA to change color.

    At this point, every bar that is above the SMA changes color.

    The next issue is that after the candle closes below the SMA, I would like the indicator to "reset" and then change the candle color when it closes above the SMA again.

    I have tried using BarColorSeries[] but this has not produced the results that I am looking for.
    Thank you for your help.
    Last edited by jg123; 03-04-2014, 02:24 PM.

    Hello jg123,

    You may want to use the CrossAbove() for this as it will only be true on the bar that it crosses above and then will not be true until it goes below the value and above once again.

    if (CrossAbove(Close, SMA(20), 1))
        // Change Bar Color

    You may view our Help Guide for more examples of this at the following link.
    JCNinjaTrader Customer Service


      Thank you

      That worked like a charm...up until I added other indicators.

      Here is what I have:

      if(CrossAbove(Close, SMA(smaPeriod),1)
      && Close[0] > Open[0]
      && CrossAbove(Close, MAEnvelopes(1,3,25).Upper,1))
      BarColorSeries[0] = Color.Blue;

      I have no problems with just having it highlight the CrossAbove SMA and the Close>Open...but as soon as I try to add in the MAE then it stops working.


        Hello jg123,

        That means that all 3 conditions would have to be true on the same bar before it will change the Bar Color, which I can see never happening since the MAEnvelopes Upper series is generally going to be much larger than the Close.

        You may want to plot your Indicator that you are checking for your condition on the chart as well to check your conditions.
        JCNinjaTrader Customer Service


          Thanks for the reply. I am probably not being very clear on what I am trying to accomplish and therefore there is a bit of confusion.

          I am attaching a picture where there is a square around two candles. These candles are bullish, above the PSAR, above the upper band of the envelopes and above the SMA. They are also the first ones to meet those criteria after they closed below the SMA.
          Attached Files


            Hello jg123,

            The candles you have outlined the MAEnvelopes crosses above the Close but your other indicators are already below the Close a few bars ago which is not making your condition true.

            You may want to only use one CrossAbove() method and then check to make sure that the value of the Close is above your MAEnvelopes or SMA for this.
            JCNinjaTrader Customer Service


              I just realized where the confusion is coming in.

              It is not necessarily one single candle that fits all of those criteria - and that also shows me that I am trying to code this all incorrectly - but I am not too sure how to still make it work.

              The point is, the bullish candle is supposed to be above Moving Average Envelope and above the SMA and it is supposed to highlight the first candle that meets both criteria.

              I am attaching a picture to show what I mean.

              The first candle that is highlighted is a proper signal candle because it has closed bullish, it is above the MAE, and it is the first candle to meet both of those after it has crossed back above the SMA.

              The second highlighted candle is not a proper signal candle. It is bullish. It closed above the MAE and it is above the SMA, but it did not close back below the SMA before going back up. This keeps it from being a proper signal candle.

              I am now using only one CrossAbove, and then attempting to reference the other two criteria - but it is not working because, as you mentioned earlier, it is expecting to meet all of those criteria in one single candle - which will virtually never happen. (good job spotting that).

              So that leaves me to where I need to make the adjustments accordingly.

              Thank you very much for your help. People should become NinjaTrader customers simply for the type of incredible support that is available on the forums, if for no other reason - thank you.
              Attached Files


              Latest Posts


              Topics Statistics Last Post
              Started by rontronimous, Today, 06:12 PM
              1 response
              Last Post NinjaTrader_ShawnB  
              Started by Vinhasa, Today, 03:15 PM
              3 responses
              Last Post NinjaTrader_Manfred  
              Started by 1001111, Today, 03:03 PM
              1 response
              Last Post NinjaTrader_Tyler  
              Started by Seedbird, Today, 03:06 PM
              1 response
              Last Post NinjaTrader_BrendanC  
              Started by mtamaku, Today, 02:46 PM
              1 response
              Last Post NinjaTrader_Kate