Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator ploted on CCI zero line

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

    Indicator ploted on CCI zero line

    Hello,
    If I took the standard CCI indicator in Ninja and wanted to make the zero line change colors when another condition was true or false...how would I do this?
    The CCI zero line already has a color attached to it that you can change but this would go over it or on top of it.

    Example 1: If the condition...3 period ema is above the 34 period ema...paint the CCI zero line Green. If the condition...3 period ema is below the 34 period ema...paint the CCI zero line Red.

    OR

    Example 2: If the condition...RSI 14,3 is above the 70 line...paint the CCI zero line Green. If the condition...RSI 14,3 is below the 30 line...paint the CCI zero line Red.

    Thanks for your help

    #2
    dwalls,

    You will need to custom code the color change. Please see this reference sample for multi-colored plots: http://www.ninjatrader-support.com/v...ead.php?t=3227
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Hi Josh,
      Thanks for the response. Could you look at this , please.


      protectedoverridevoid OnBarUpdate()
      {
      if (CurrentBar == 0)
      Value.Set(
      0);
      else
      {
      double mean = 0;
      for (int idx = Math.Min(CurrentBar, Period - 1); idx >= 0; idx--)
      mean += Math.Abs(Typical[idx] - SMA(Typical, Period)[
      0]);
      Value.Set((Typical[
      0] - SMA(Typical, Period)[0]) / (mean == 0 ? 1 : (0.015 * (mean / Math.Min(Period, CurrentBar + 1)))));
      }

      if (EMA(3)[0] >= EMA(34)[0])

      {
      DrawHorizonalLine(
      "CCI, Zero Line, Color.LimeGreen);
      }
      if (EMA(3)[0] <= EMA(34)[0])

      {
      DrawHorizonalLine(
      "CCI, Zero Line, Color.Red);
      }


      }
      Properties





      Error: Newline in constant CS1010

      Comment


        #4
        Hi dwalls,

        You forgot the ending " for the string CCI on your DrawHorizontalLine(). Also, you need to adhere to the proper syntaxing.

        DrawHorizontalLine(string tag, double y, Color color)

        so...
        DrawHorizontalLine("CCI", 0, Color.LimeGreen);
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          I cant seem to get this to work.
          There must be something I'm missing.
          Is there something that I need to have in theprotectedoverridevoid Initialize()...area to make this work?

          Or could someone please post a working code for changing the color of the CCI zero line using conditions like the one shown below.

          Thanks

          Comment


            #6
            dwalls,

            Are you trying to modify the original CCI indicator? If that is what you are doing you will first need to rename your indicator to a different name for the changes to be saved.

            After that and you want color changing zero line you will need to replace the Add(new Line....) with an Add(new Plot(....)) and then use the techniques demonstrated in this reference sample for multi-colored plots. http://www.ninjatrader-support.com/v...ead.php?t=3227
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by dwalls View Post
              If I took the standard CCI indicator in Ninja and wanted to make the zero line change colors when another condition was true or false...how would I do this?
              Me, I'd create two plots for the zero line and plot them as hash marks.

              (Initialize)
              Add(new Plot(Color.Green, PlotStyle.Hash, "ZeroGreen"));
              Add(new Plot(Color.Red, PlotStyle.Hash, "ZeroRed"));

              (OnBarUpdate)
              if (condition) ZeroGreen.Set(0); else ZeroRed.Set(0);

              The zero line will appear as a dashed line with red or green dashes, depending on the condition above. Also, remember to add the appropriate properties code for ZeroGreen and ZeroRed in the properties region, else you'll have to use Values[2].Set(0) and Values[3].Set(0), assuming ZeroGreen and ZeroRed are plots 2 and 3, respectively.
              -Alex
              Last edited by anachronist; 10-13-2008, 05:04 PM.

              Comment


                #8
                Thanks for your help.
                I got that to work.

                Thanks

                Comment


                  #9
                  anachronist,
                  Thanks for your help on the zeroline.
                  While were at it, how about the Ploting for something on the 100,-100 or 200,-200 lines using the same type color changes but for a different condition. I tried to by using the same code and just changed the
                  ZeroGreen.Set(0); else ZeroRed.Set(0); to (200) and (-200) but it wouldn't work. Do you mind sharing a working code for this as well if you have one.

                  Thanks for you help.

                  Comment


                    #10
                    Were you also setting ZeroGreen and ZeroRed to zero in the same code? You will need to allocate more plots if you want additional multicolor lines.
                    -Alex

                    Comment


                      #11
                      Yes, and I was setting ZeroGreen and ZeroRed to 200, -200 in the same code. That must be a conflict. I created two new plots called TwoHundredGreen and TwoHundredRed and then used TwoHundredGreen (200) & TwoHundredRed (200) and then did TwoHundredGreen (-200)and TwoHundredRed (-200) but that didnt work either.
                      How do you think it should be done?
                      Thanks

                      Comment


                        #12
                        Yes, you probably had a conflict. The value plotted would be the last one you set.

                        I would do it like this:

                        (Initialize)
                        Add(new Plot(Color.Green, PlotStyle.Hash, "ZeroGreen"));
                        Add(new Plot(Color.Red, PlotStyle.Hash, "ZeroRed"));
                        Add(new Plot(Color.Green, PlotStyle.Hash, "TwoHundredGreen"));
                        Add(new Plot(Color.Red, PlotStyle.Hash, "TwoHundredRed"));

                        (OnBarUpdate)
                        if (condition1) ZeroGreen.Set(0); else ZeroRed.Set(0);
                        if (condition2) TwoHundredGreen.Set(200);
                        else TwoHundredRed.Set(-200);

                        You're saying you tried that and it didn't work? Is the scale on the right side of the plot at least spanning 200 to -200?
                        -Alex

                        Comment


                          #13
                          Thanks Alex,
                          I got this to work.
                          It will change the color from green to red on the 200 line and will also work if I set it to the -200 line.

                          (Initialize)
                          Add(new Plot(Color.Green, PlotStyle.Hash, "ZeroGreen"));
                          Add(new Plot(Color.Red, PlotStyle.Hash, "ZeroRed"));
                          Add(new Plot(Color.Green, PlotStyle.Hash, "TwoHundredGreen"));
                          Add(new Plot(Color.Red, PlotStyle.Hash, "TwoHundredRed"));

                          (OnBarUpdate)
                          if (condition1) ZeroGreen.Set(0); else ZeroRed.Set(0);
                          if (condition2) TwoHundredGreen.Set(200);
                          else TwoHundredRed.Set(200);

                          Now I want to duplicate this so the 200 line and the-200 line show the same green and red colors at the same time...so the 200 line colors and
                          the -200 line colors actually match each other.
                          I tried using the same TwoHundredGreen.Set on the (200) & (-200) and TwoHundredRed.Set on the (200) & (-200) but it wouldnt plot so I added a third set of color plots but still coulnt get it to plot on the 200 and the -200 lines at the same time...dont know why...it looks like it should work...again, I must be missing something. There seems to be a conflict.
                          Do you see anything wrong here:

                          (Initialize)
                          Add(new Plot(Color.Green, PlotStyle.Hash, "ZeroGreen"));
                          Add(new Plot(Color.Red, PlotStyle.Hash, "ZeroRed"));
                          Add(new Plot(Color.Green, PlotStyle.Hash, "TwoHundredGreen"));
                          Add(new Plot(Color.Red, PlotStyle.Hash, "TwoHundredRed"));
                          Add(new Plot(Color.Green, PlotStyle.Hash, "MinusTwoHundredGreen"));
                          Add(new Plot(Color.Red, PlotStyle.Hash, "MinusTwoHundredRed"));


                          (OnBarUpdate)
                          if (condition1) ZeroGreen.Set(0); else ZeroRed.Set(0); //works
                          if (condition2) TwoHundredGreen.Set(200);
                          else TwoHundredRed.Set(200); //works
                          if (condition3 same as condition2) MinusTwoHundredGreen.Set(-200);
                          else MinusTwoHundredRed.Set(-200); //doesnt work

                          Thanks

                          Comment


                            #14
                            dwalls,

                            I have not been following this thread intimately, but please describe what does not work. Have you created the plots properly in the Properties region of the code too? Each plot has its own unique Values[] index?
                            Josh P.NinjaTrader Customer Service

                            Comment


                              #15
                              You're right, sorry, I meant that you had to create two new plots for each new color-changing line you want to add.

                              Originally posted by dwalls View Post
                              (Initialize)
                              Add(new Plot(Color.Green, PlotStyle.Hash, "ZeroGreen"));
                              Add(new Plot(Color.Red, PlotStyle.Hash, "ZeroRed"));
                              Add(new Plot(Color.Green, PlotStyle.Hash, "TwoHundredGreen"));
                              Add(new Plot(Color.Red, PlotStyle.Hash, "TwoHundredRed"));
                              Add(new Plot(Color.Green, PlotStyle.Hash, "MinusTwoHundredGreen"));
                              Add(new Plot(Color.Red, PlotStyle.Hash, "MinusTwoHundredRed"));

                              (OnBarUpdate)
                              if (condition1) ZeroGreen.Set(0); else ZeroRed.Set(0); //works
                              if (condition2) TwoHundredGreen.Set(200);
                              else TwoHundredRed.Set(200); //works
                              if (condition3 same as condition2) MinusTwoHundredGreen.Set(-200);
                              else MinusTwoHundredRed.Set(-200); //doesnt work
                              Don't use a condition 3, just use

                              if (condition2) {
                              TwoHundredGreen.Set(200);
                              MinusTwoHundredGreen.Set(-200);
                              } else {
                              TwoHundredRed.Set(200);
                              MinusTwoHundredRed.Set(-200);
                              }

                              I don't know why that wouldn't work. As Josh says above, you need to make sure you have the correct properties set in the properties region, with each plot returning a different value (Value[0], Value[1], Value[2], etc.).

                              -Alex

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              592 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