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

Change an Indicator Color in a Strategy

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

    Change an Indicator Color in a Strategy

    I created a MA crossover strategy using the Strategy Wizard. I selected true for plot on chart. The MAs show up on the chart, but they are both the same color. How can I change the colors of the indicators?
    This is what the source code looks like:
    protected override void Initialize()
    {
    Add(EMA(14));
    Add(EMA(28));
    }

    Thanks, Tim

    #2
    NinexTim,

    Here is a relevant link : http://www.ninjatrader.com/support/f...ead.php?t=3227

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

    Comment


      #3
      Adam,
      From the looks of the link you sent me, I can't change the color using the Add statement that I have. I unlocked the code and copied the Add(new Plot ... that was in the example. Now I get multiple errors when I compile.
      This is the code I added:
      protected override void Initialize()
      {
      //Add(EMA(14));
      //Add(EMA(28));
      Add(new Plot(Color.FromKnownColor(KnownColor.DarkRed), PlotStyle.Line, "Upper"));
      Add(new Plot(Color.FromKnownColor(KnownColor.Black), PlotStyle.Line, "Lower"));
      }

      protected override void OnBarUpdate()
      {
      Lower.Set(EMA(14)[0]);
      Upper.Set(EMA(28)[0]);
      }

      These are the errors:
      The best overloaded method match for 'NinjaTrader.Strategy.StrategyBase.Add(NinjaTrader .Indicator.IndicatorBase)' has some invalid arguments
      Argument '1': cannot convert from 'NinjaTrader.Gui.Chart.Plot' to 'NinjaTrader.Indicator.IndicatorBase'
      The name 'Lower' does not exist in the current context
      The name 'Upper' does not exist in the current context

      Thanks, Tim

      Comment


        #4
        NinexTim,

        What error messages are you getting?

        You can also do something like PlotColors[0][0] = Color.Red; in OnBarUpdate

        Adam P.NinjaTrader Customer Service

        Comment


          #5
          Adam,
          Here are the errors I'm getting. Do I need to declare Upper and Lower somewhere?
          Thanks, Tim
          Originally posted by NinexTim View Post
          These are the errors:
          The best overloaded method match for 'NinjaTrader.Strategy.StrategyBase.Add(NinjaTrader .Indicator.IndicatorBase)' has some invalid arguments
          Argument '1': cannot convert from 'NinjaTrader.Gui.Chart.Plot' to 'NinjaTrader.Indicator.IndicatorBase'
          The name 'Lower' does not exist in the current context
          The name 'Upper' does not exist in the current context

          Comment


            #6
            Tim,

            Please try this formatting :

            Add(new Plot(new Pen(Color.Black, 2), PlotStyle.Line, "CCI_Plot"));

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

            Comment


              #7
              Adam,
              I put the line you suggested in the Initialize portion of my code:
              protected override void Initialize()
              {
              Add(new Plot(new Pen(Color.Black, 2), PlotStyle.Line, "CCI_Plot"));

              I still get the same errors as before:
              The best overloaded method match for 'NinjaTrader.Strategy.StrategyBase.Add(NinjaTrader .Indicator.IndicatorBase)' has some invalid arguments
              Argument '1': cannot convert from 'NinjaTrader.Gui.Chart.Plot' to 'NinjaTrader.Indicator.IndicatorBase'

              Thanks, Tim

              Comment


                #8
                NinexTim,

                Apologies, I overlooked that you are working with a strategy here. That is indicator code only.

                One thing to remember here is you can't add plots like this to a strategy. I would suggest creating an indicator first, then you can add the indicator to your strategy.
                Last edited by NinjaTrader_AdamP; 04-03-2012, 08:14 AM.
                Adam P.NinjaTrader Customer Service

                Comment


                  #9
                  Change an Indicator color in a Strategy (SOLUTION)

                  Tim,

                  I know this is a bit late, but hopefully it will help some people who are trying to do the same.

                  To change the color of an Indicator in a Strategy, you have to get the Pen object of the Indicator's Plot and change the color of the Pen object.

                  Here's an example:

                  PHP Code:
                          protected override void Initialize()
                          {
                              
                  Add(EMA(10));
                              
                  CalculateOnBarClose true;
                          }

                          protected 
                  override void OnBarUpdate()
                          {    
                              
                  Pen my_pen this.Indicators[0].Plots[0].Pen;
                              
                  my_pen.Color Color.Red;
                          } 
                  You can do this for each of your Indies by changing the '[0]' after 'Indicators' to 1, 2, 3, etc...

                  I haven't tried this with a different style of indicator, however I imagine it would work similarly.

                  Kenny

                  Comment


                    #10
                    Kenny, thanks for your update on this topic.
                    Unless you want to change the plot colors dynamically in your strategy, I would prefer setting the indicator plots colors in the Initialize() section.
                    Also added an example how to set the plot line thickness and DashStyle.

                    Code:
                    [FONT=Courier New][COLOR=#007700]protected [/COLOR][COLOR=#0000bb]override void Initialize[/COLOR][/FONT][FONT=Courier New][COLOR=#007700]() [/COLOR][/FONT]
                    [FONT=Courier New][COLOR=#007700]{ [/COLOR][/FONT]
                    [FONT=Courier New][COLOR=#0000bb]Add(EMA(10));[/COLOR][/FONT]
                    [FONT=Courier New][COLOR=#0000bb]EMA(10).[COLOR=blue]Plots[0].Pen.Color = Color[/COLOR].Red;  [/COLOR][COLOR=seagreen]// set plot color[/COLOR][/FONT]
                    [FONT=Courier New][FONT=Courier New][COLOR=#0000bb]EMA(10).Plots[0].Pen[/COLOR][COLOR=blue].Width[/COLOR][/FONT][/FONT][COLOR=sandybrown][COLOR=blue][FONT=Courier New][FONT=Courier New] = 2[/FONT][/FONT][FONT=Courier New][FONT=Courier New];          [COLOR=seagreen]// set line width[/COLOR][/FONT][/FONT][/COLOR][/COLOR]
                    [COLOR=sandybrown][FONT=Courier New][FONT=Courier New][COLOR=#0000bb]EMA(10).[/COLOR][/FONT][/FONT][COLOR=blue][FONT=Courier New][FONT=Courier New]Plots[[/FONT][/FONT][FONT=Courier New][FONT=Courier New][FONT=Courier New]0[/FONT][/FONT][/FONT][FONT=Courier New][FONT=Courier New]].Pen.DashStyle = DashStyle.Dash; [COLOR=seagreen]// set DashStyle [/COLOR][/FONT][/FONT][/COLOR][/COLOR]
                     }
                    Marco
                    Last edited by marcow; 08-29-2012, 12:11 PM.

                    Comment


                      #11
                      how to do this with BB

                      Marcow thank you

                      How to do this for the Bowlinger band
                      I am trying to make the middle line disappear but code gives error:

                      Bollinger(2,Bb).Middle.Plots[0].Pen.Color = Color.Transparent;

                      any suggestions?

                      Comment


                        #12
                        yeshe, the plots would go strictly by collection index and not be name here, so I would suggest to instead try with (second plot at index 1 is the middle plot).

                        Bollinger(2,Bb).Plots[1].Pen.Color = Color.Transparent;
                        BertrandNinjaTrader Customer Service

                        Comment


                          #13
                          Bertrand
                          works
                          great!

                          Comment


                            #14
                            does anyone have ideas on how i can change the colors of NinjaTrader RMI main line to Red (for example) when great than 50 and Green when less than 50

                            Comment


                              #15
                              Hello RicRules,

                              Thank you for writing in. There are not any built in NinjaTrader indicators called RMI. Did you possibly misspell the acronym or are you referring to an indicator you downloaded on the internet? If you can please attach the indicator you are referring to to your response, I can assist further.

                              Thank you in advance.
                              Michael M.NinjaTrader Quality Assurance

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by AttiM, 02-14-2024, 05:20 PM
                              12 responses
                              213 views
                              0 likes
                              Last Post DrakeiJosh  
                              Started by cre8able, 02-11-2023, 05:43 PM
                              3 responses
                              237 views
                              0 likes
                              Last Post rhubear
                              by rhubear
                               
                              Started by frslvr, 04-11-2024, 07:26 AM
                              8 responses
                              117 views
                              1 like
                              Last Post NinjaTrader_BrandonH  
                              Started by stafe, 04-15-2024, 08:34 PM
                              10 responses
                              47 views
                              0 likes
                              Last Post stafe
                              by stafe
                               
                              Started by rocketman7, Today, 09:41 AM
                              3 responses
                              12 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Working...
                              X