Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

CCI (or any indicator) with changing color

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

    CCI (or any indicator) with changing color

    I'm trying to develop an indicator (specifically CCI) that will change colors depending on whether it's increasing, decreasing, or the same compared to the previous bar. I put together this code from other code I found in different places but this seems to look at the price bar instead of the previous CCI bar to determine color. Does anyone know how I may change this to make the color change due to the previous CCI bar? BTW, I am not an expert at all in programming, so all help would be GREATLY appreciated... Thanks.

    #region Variables
    // Wizard generated variables
    // User defined variables (add any user defined variables below)
    #endregion

    /// <summary>
    /// This method is used to configure the indicator and is called once before any bar data is loaded.
    /// </summary>
    protected override void Initialize()
    {
    Add(new Line(Color.DarkGray, 180, "Level 1"));
    Add(new Line(Color.DarkGray, 0, "Zero line"));
    Add(new Line(Color.DarkGray, -180, "Level -1"));

    Add(new Plot(Color.Green, PlotStyle.Bar, "UpCCI"));
    Add(new Plot(Color.Red, PlotStyle.Bar, "DnCCI"));
    Add(new Plot(Color.Brown, PlotStyle.Bar, "UnchCCI"));
    CalculateOnBarClose = false;
    Overlay = false;
    PriceTypeSupported = false;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Use this method for calculating your indicator values. Assign a value to each
    // plot below by replacing 'Close[0]' with your own formula.
    if (Close[0] > Open[0]) UpCCI.Set(CCI(45)[0]);
    if (Close[0] < Open[0]) DnCCI.Set(CCI(45)[0]);
    if (Close[0] == Open[0]) UnchCCI.Set(CCI(45)[0]);
    }

    #2
    The first line of code should be:

    If (CurrentBar < 1)
    return;

    if (CCI(45)[0] > CCI(45)[1]) UpCCI.Set(CCI(45)[0]);
    RayNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Ray View Post
      The first line of code should be:

      If (CurrentBar < 1)
      return;

      if (CCI(45)[0] > CCI(45)[1]) UpCCI.Set(CCI(45)[0]);
      Thanks for your response Ray. I input the code as you described and it gives me an error stating that I need a ';' after the line ' If (CurrentBar < 1)'. What should I do here...?

      Comment


        #4
        The code I provided is a sample of the concept and to demonstrate how to access the CCI indicator value of the current bar and compare to the prior bar. You will need to take it from that point.
        RayNinjaTrader Customer Service

        Comment


          #5
          I adjusted the code as shown below, but I still receive the ';' error. Could you please point me in the right direction with this? Thank you..

          If (CurrentBar < 1)
          return;
          if (CCI(45)[0] > CCI(45)[1]) UpCCI.Set(CCI(45)[0]);
          if (CCI(45)[0] < CCI(45)[1]) DnCCI.Set(CCI(45)[0]);
          if (CCI(45)[0] = CCI(45)[1]) UnchCCI.Set(CCI(45)[0]);

          Comment


            #6
            Likely should read:
            if (CCI(45)[0]== CCI(45)[1])

            Also: clicking on the error message brings you to the erroneous code line.

            Comment


              #7
              Thanks Dierk. I did change that to == also, but it seems to be pointing the error message to the 'If (CurrentBar < 1)' line. The message is '; expected'

              Comment


                #8
                Likely needs to be:
                if (CurrentBar < 1)
                Note: "if" and not "If".

                You might consider getting in touch with a NinjaScript consultant: http://www.ninjatrader-support.com/v...ght=consultant

                Comment


                  #9
                  Originally posted by NinjaTrader_Dierk View Post
                  Likely needs to be:
                  if (CurrentBar < 1)
                  Note: "if" and not "If".

                  You might consider getting in touch with a NinjaScript consultant: http://www.ninjatrader-support.com/v...ght=consultant
                  That fixed the problem! Thanks Dierk!

                  Comment


                    #10
                    Hi,

                    Would you mind sharing the indicator. I am after such a CCI but I have no idea where to begin regarding coding.

                    Best regards,

                    Comment


                      #11
                      Have you already looked at those scripts related from our sharing section?



                      At least they would give you a good starting point for yours hopefully.

                      Comment


                        #12
                        Originally posted by Jibu V View Post
                        I'm trying to develop an indicator (specifically CCI) that will change colors depending on whether it's increasing, decreasing, or the same compared to the previous bar. I put together this code from other code I found in different places but this seems to look at the price bar instead of the previous CCI bar to determine color. Does anyone know how I may change this to make the color change due to the previous CCI bar? BTW, I am not an expert at all in programming, so all help would be GREATLY appreciated... Thanks.

                        #region Variables
                        // Wizard generated variables
                        // User defined variables (add any user defined variables below)
                        #endregion

                        /// <summary>
                        /// This method is used to configure the indicator and is called once before any bar data is loaded.
                        /// </summary>
                        protected override void Initialize()
                        {
                        Add(new Line(Color.DarkGray, 180, "Level 1"));
                        Add(new Line(Color.DarkGray, 0, "Zero line"));
                        Add(new Line(Color.DarkGray, -180, "Level -1"));

                        Add(new Plot(Color.Green, PlotStyle.Bar, "UpCCI"));
                        Add(new Plot(Color.Red, PlotStyle.Bar, "DnCCI"));
                        Add(new Plot(Color.Brown, PlotStyle.Bar, "UnchCCI"));
                        CalculateOnBarClose = false;
                        Overlay = false;
                        PriceTypeSupported = false;
                        }

                        /// <summary>
                        /// Called on each bar update event (incoming tick)
                        /// </summary>
                        protected override void OnBarUpdate()
                        {
                        // Use this method for calculating your indicator values. Assign a value to each
                        // plot below by replacing 'Close[0]' with your own formula.
                        if (Close[0] > Open[0]) UpCCI.Set(CCI(45)[0]);
                        if (Close[0] < Open[0]) DnCCI.Set(CCI(45)[0]);
                        if (Close[0] == Open[0]) UnchCCI.Set(CCI(45)[0]);
                        }
                        Hi Jibu V,
                        Does the cci indicator with changing color work. I'm also looking for this as well. Thanks bdg820

                        Comment


                          #13
                          Check this.I`m sure Tony wouldn`t mind,as he`s posted it himself in this very forum.

                          Have fun!
                          Attached Files

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                          0 responses
                          595 views
                          0 likes
                          Last Post Geovanny Suaza  
                          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                          0 responses
                          343 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by Mindset, 02-09-2026, 11:44 AM
                          0 responses
                          103 views
                          0 likes
                          Last Post Mindset
                          by Mindset
                           
                          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                          0 responses
                          556 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by RFrosty, 01-28-2026, 06:49 PM
                          0 responses
                          554 views
                          1 like
                          Last Post RFrosty
                          by RFrosty
                           
                          Working...
                          X