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

Indicator background color

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

    Indicator background color

    For this code below, if I wanted the background color on the indicator to plot in bar format how would I add this? I know the command is PlotStyle.Bar but how do I add this in, can't seem to get it to work without an error....


    if (Value > 50 && EmalineF > 50 && EmalineM > 50 && EmalineS > 50)
    {
    BackColor = Color.LimeGreen;
    }

    #2
    Hi, what is Value? Value is usually the default for calling the first plot. In that case you would use Value[0] for the plot at the current bar. The plot style of Bar is set in the Initialize section. BackColor cannot color Bar plots but is used to color the chart background color. The color of the plots are initially set in the Initialize section when they are added also. They can later be changed using PlotColor for each individual bar. Guessing here but in your case changing the bar colors would be like this: PlotColor[0][0] = Color.LimeGreen. If changing the background color you would use: BackColor = Color.LimeGreen or BackColorSeries[0] = Color.LimeGreen.

    Dan
    Last edited by eDanny; 01-15-2012, 01:15 PM.
    eDanny
    NinjaTrader Ecosystem Vendor - Integrity Traders

    Comment


      #3
      The whole section of code is below. This is what im trying to do... if Value, EmalineF, EmalineM, and EmalineS are all greater than 50 I want the indicator to plot a LimeGreen Background vertical bar. Is this possible? Right now as is its just a solid background color and not in vertical bar format.


      protected override void OnBarUpdate()
      {
      if (CurrentBar < Period) return;
      double Value = RSI(period, 3)[0];
      double EmalineF = EMA(RSI(period, 3), Fast)[0];
      double EmalineM = EMA(RSI(period, 3), Mid)[0];
      double EmalineS = EMA(RSI(period, 3), Slow)[0];

      if (Value > 50 && EmalineF > 50 && EmalineM > 50 && EmalineS > 50)
      {
      BackColor = Color.LimeGreen;
      }

      else if (Value < 50 && EmalineF < 50 && EmalineM < 50 && EmalineS < 50)
      {
      BackColor = Color.Black;
      }

      else
      {
      BackColor = Color.DarkGray;
      }

      Comment


        #4
        oops I didn't read your whole post, so your saying its not possible to change the format of the background. There must be someway to plot a color bar in the background of the indicator given a certain condition. Ive seen it in some custom indicators online just don't know how they code it.

        Ive attached a photo of what im trying to get...
        Attached Files
        Last edited by zachj; 01-15-2012, 01:55 PM.

        Comment


          #5
          zachj,

          You could draw a rectangle : http://www.ninjatrader.com/support/h...wrectangle.htm. These are transparent.

          Please let me know if I may assist further.
          Adam P.NinjaTrader Customer Service

          Comment


            #6
            I don't understand how to use this code. I assume I put this under the if statments in place of the background code I had. I tried the first if statment below..what do i put in the "tag" part and the other sections. Nothing is plotting..

            protected override void OnBarUpdate()
            {
            if (CurrentBar < Period) return;
            double Value = RSI(period, 3)[0];
            double EmalineF = EMA(RSI(period, 3), Fast)[0];
            double EmalineM = EMA(RSI(period, 3), Mid)[0];
            double EmalineS = EMA(RSI(period, 3), Slow)[0];


            if (Value > 50 && EmalineF > 50 && EmalineM > 50 && EmalineS > 50)
            {
            DrawRectangle("tag", false, 1, 1, 2, 5, Color.LimeGreen, Color.LimeGreen, 5);
            }

            else if (Value < 50 && EmalineF < 50 && EmalineM < 50 && EmalineS < 50)
            {
            BackColor = Color.Black;
            }

            else
            {
            BackColor = Color.DarkGray;
            }

            Comment


              #7
              zachj,

              You are using this format : DrawRectangle(string tag, bool autoScale, int startBarsAgo, double startY, int endBarsAgo, double endY, Color color, Color areaColor, int areaOpacity)

              The tag is just a reference to that particular drawn object. Start bars ago you set to 1, startY value you set to 1, this will be 1 on your chart, so you may need to use a price or indicator value instead. Likewise for endY.

              Please let me know if I may assist further.
              Adam P.NinjaTrader Customer Service

              Comment


                #8
                This isnt making any sense to me at all. I think your thinking im trying to do something different. Im not trying to plot anything on the chart, but on the indicator. I had set all those values to 1 and several other numbers and its not plotting anything. I put value in for the tag and it still didn't plot anything. The tag your saying is reference to that drawn object, but i have 4! drawn objects. I don't see how this is so hard, all i need is...if 1 2 and 3 then draw a vertical bar, or even a vertical line that i can thicken for the love of god..lol

                So basically if the rsi, and the ema fast medium and slow of the rsi is all above 50 plot a vertical bar.

                Here's code again below, am i putting it in the incorrect spot or what am i doing wrong?....

                protected override void OnBarUpdate()
                {
                if (CurrentBar < Period) return;
                double Value = RSI(period, 3)[0];
                double EmalineF = EMA(RSI(period, 3), Fast)[0];
                double EmalineM = EMA(RSI(period, 3), Mid)[0];
                double EmalineS = EMA(RSI(period, 3), Slow)[0];


                if (Value > 50 && EmalineF > 50 && EmalineM > 50 && EmalineS > 50)
                {DrawRectangle(value, false, 1, 1, 1, 1, Color.LimeGreen, Color.LimeGreen, 5);}

                else if (Value < 50 && EmalineF < 50 && EmalineM < 50 && EmalineS < 50)
                {BackColor = Color.Black;}

                else
                {BackColor = Color.DarkGray;}

                Comment


                  #9
                  I think your best bet is to use a plot to make equally sized (height) bars like in a histogram. You can make the bars any thickness. Add a plot like that found in the MACD indicator for the histogram bars in the Initialize() section:
                  Add(new Plot(new Pen(Color.Empty, 5), PlotStyle.Bar, "Color Bars"));

                  Change these lines and use a different double name:
                  double Value = RSI(period, 3)[0];
                  to something like:
                  double myRSI = RSI(period, 3)[0];

                  Make sure you plot the bar:
                  Value.Set(10); //see why we changed the name of your double?
                  or alternatively:
                  Values[0].Set(10); //this plots a bar from zero to ten, any number could be used.

                  if (Value > 50 && EmalineF > 50 && EmalineM > 50 && EmalineS > 50)
                  to something like this:
                  if (myRSI > 50 && EmalineF > 50 && EmalineM > 50 && EmalineS > 50)

                  Then you can test and change the color of the plots something like this:
                  if (myRSI > 50 && EmalineF > 50 && EmalineM > 50 && EmalineS > 50)
                  {
                  PlotColors[0][0] = Color.LimeGreen; //colors the current plot bar.
                  }
                  etc.

                  Make the changes to other parts of your code as needed and away you go. Then you could also make your code more efficient at a later time.

                  Dan
                  Last edited by eDanny; 01-15-2012, 05:51 PM.
                  eDanny
                  NinjaTrader Ecosystem Vendor - Integrity Traders

                  Comment


                    #10
                    Originally posted by zachj View Post
                    The whole section of code is below. This is what im trying to do... if Value, EmalineF, EmalineM, and EmalineS are all greater than 50 I want the indicator to plot a LimeGreen Background vertical bar. Is this possible? Right now as is its just a solid background color and not in vertical bar format.


                    protected override void OnBarUpdate()
                    {
                    if (CurrentBar < Period) return;
                    double Value = RSI(period, 3)[0];
                    double EmalineF = EMA(RSI(period, 3), Fast)[0];
                    double EmalineM = EMA(RSI(period, 3), Mid)[0];
                    double EmalineS = EMA(RSI(period, 3), Slow)[0];

                    if (Value > 50 && EmalineF > 50 && EmalineM > 50 && EmalineS > 50)
                    {
                    BackColor = Color.LimeGreen;
                    }

                    else if (Value < 50 && EmalineF < 50 && EmalineM < 50 && EmalineS < 50)
                    {
                    BackColor = Color.Black;
                    }

                    else
                    {
                    BackColor = Color.DarkGray;
                    }
                    1. Create a Plot that has a fixed value equal to the height of the bars, as you want them to be, using a bar PlotStyle.
                    2. Color the Plot based on your conditions.

                    Comment


                      #11
                      Originally posted by eDanny View Post
                      I think your best bet is to use a plot to make equally sized (height) bars like in a histogram. You can make the bars any thickness. Add a plot like that found in the MACD indicator for the histogram bars in the Initialize() section:
                      Add(new Plot(new Pen(Color.Empty, 5), PlotStyle.Bar, "Color Bars"));

                      Change these lines and use a different double name:
                      double Value = RSI(period, 3)[0];
                      to something like:
                      double myRSI = RSI(period, 3)[0];

                      Make sure you plot the bar:
                      Value.Set(10); //see why we changed the name of your double?
                      or alternatively:
                      Values[0].Set(10); //this plots a bar from zero to ten, any number could be used.

                      if (Value > 50 && EmalineF > 50 && EmalineM > 50 && EmalineS > 50)
                      to something like this:
                      if (myRSI > 50 && EmalineF > 50 && EmalineM > 50 && EmalineS > 50)

                      Then you can test and change the color of the plots something like this:
                      if (myRSI > 50 && EmalineF > 50 && EmalineM > 50 && EmalineS > 50)
                      {
                      PlotColors[0][0] = Color.LimeGreen; //colors the current plot bar.
                      }
                      etc.

                      Make the changes to other parts of your code as needed and away you go. Then you could also make your code more efficient at a later time.

                      Dan
                      Im not following this but I tried adding in these items regardless and it isn't plotting anything at all still. Why would i need to change Value to myRSI, its just a name place holder. You say its changed because you now have Value.Set(10) but what is Value now associated with. I put PlotColors[0][0] = Color.LimeGreen; in under my if statement, add the new plot and added the .Set item but nothing plotted.

                      Comment


                        #12
                        Originally posted by koganam View Post
                        1. Create a Plot that has a fixed value equal to the height of the bars, as you want them to be, using a bar PlotStyle.
                        2. Color the Plot based on your conditions.
                        How would I go about doing this though.

                        I have so many different people replying to this thread and getting sent in all different directions. Its getting confusing.

                        Comment


                          #13
                          zachj,

                          I am not sure exactly what you want accomplished. Could you clarify? To me it seems like you are wanting to either A) change the background color of a plot, i.e. change the background behind what the indicator plots, or B) Plot some kind of bar behind the indicator.

                          If you could perhaps clarify it would help us tell you the "best" way to handle this.

                          I look forward to helping you resolve your issue.
                          Last edited by NinjaTrader_AdamP; 01-16-2012, 02:02 PM.
                          Adam P.NinjaTrader Customer Service

                          Comment


                            #14
                            This is exactly what post #10 describes and shows how to do it.

                            Originally posted by zachj View Post
                            How would I go about doing this though.

                            I have so many different people replying to this thread and getting sent in all different directions. Its getting confusing.
                            eDanny
                            NinjaTrader Ecosystem Vendor - Integrity Traders

                            Comment


                              #15
                              Originally posted by eDanny View Post
                              I think your best bet is to use a plot to make equally sized (height) bars like in a histogram. You can make the bars any thickness. Add a plot like that found in the MACD indicator for the histogram bars in the Initialize() section:
                              Add(new Plot(new Pen(Color.Empty, 5), PlotStyle.Bar, "Color Bars"));

                              Change these lines and use a different double name:
                              double Value = RSI(period, 3)[0];
                              to something like:
                              double myRSI = RSI(period, 3)[0];

                              Make sure you plot the bar:
                              Value.Set(10); //see why we changed the name of your double?
                              or alternatively:
                              Values[0].Set(10); //this plots a bar from zero to ten, any number could be used.

                              if (Value > 50 && EmalineF > 50 && EmalineM > 50 && EmalineS > 50)
                              to something like this:
                              if (myRSI > 50 && EmalineF > 50 && EmalineM > 50 && EmalineS > 50)

                              Then you can test and change the color of the plots something like this:
                              if (myRSI > 50 && EmalineF > 50 && EmalineM > 50 && EmalineS > 50)
                              {
                              PlotColors[0][0] = Color.LimeGreen; //colors the current plot bar.
                              }
                              etc.

                              Make the changes to other parts of your code as needed and away you go. Then you could also make your code more efficient at a later time.

                              Dan
                              Hey eDanny, you had it buddy! You were right of course, I got it to work finally. Had to do ColorBars.Set(100) and the order of my plots were wrong. I had to set it to the 6th plot.... PlotColors[6][0] = Color.LimeGreen; it was skipping the plots 1,2,3 for some reason. And i see what your saying now, the Value.Set is always the first plot. Ive attached a pic of final product. Thanks for your help!
                              Attached Files

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by zstheorist, Today, 07:52 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post zstheorist  
                              Started by pmachiraju, 11-01-2023, 04:46 AM
                              8 responses
                              150 views
                              0 likes
                              Last Post rehmans
                              by rehmans
                               
                              Started by mattbsea, Today, 05:44 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post mattbsea  
                              Started by RideMe, 04-07-2024, 04:54 PM
                              6 responses
                              33 views
                              0 likes
                              Last Post RideMe
                              by RideMe
                               
                              Started by tkaboris, Today, 05:13 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post tkaboris  
                              Working...
                              X