• 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.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Change only first bar color that meets criteria

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

    Change only first bar color that meets criteria

    Hello

    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.

    #2
    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.

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



    You may view our Help Guide for more examples of this at the following link.
    http://www.ninjatrader.com/support/h...crossabove.htm
    JCNinjaTrader Customer Service

    Comment


      #3
      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.

      Comment


        #4
        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

        Comment


          #5
          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

          Comment


            #6
            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

            Comment


              #7
              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

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by ntbone, 07-13-2019, 11:37 PM
              9 responses
              27 views
              0 likes
              Last Post Spaggetti Ninjja  
              Started by nicknamed, Today, 05:10 PM
              1 response
              15 views
              0 likes
              Last Post NinjaTrader_EricB  
              Started by pstrusi, Today, 04:57 PM
              0 responses
              6 views
              0 likes
              Last Post pstrusi
              by pstrusi
               
              Started by williamzz, Today, 04:18 PM
              0 responses
              6 views
              0 likes
              Last Post williamzz  
              Started by ct, Today, 01:57 PM
              2 responses
              14 views
              0 likes
              Last Post ct
              by ct
               
              Working...
              X