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

Changing indicator colours as part of NT Strategy

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

    Changing indicator colours as part of NT Strategy

    Hi
    How does one change the indicator line (e.g. EMA) colour if part of an NT strategy?

    thx
    David

    #2
    You can do something like:

    Code:
    protected override void Initialize()
    {
        Add(SMA(20));
        SMA(20).Plots[0].Pen.Color = Color.Red;
        CalculateOnBarClose = true;
    }
    RayNinjaTrader Customer Service

    Comment


      #3
      thx - this works a treat.........
      next step, how does one change the colours of both the two lines & histogram for the MACD.

      thx
      David

      Comment


        #4
        The concept is that the Plots[] and Lines[] are arrays holding plot and line objects. If you have a two line plot, you can change the color by accessing either Plots[0] for the first plot, Plots[1] for the second plot and so on...





        Review my sample code to get an idea of how you could replicate this for the MACD indicator.
        RayNinjaTrader Customer Service

        Comment


          #5
          great - easy to code; work a treat. thx for your help !
          David

          Comment


            #6
            OK - hopefully final question on this thread. I am now struggling to change the thickness of the MACD histogram! How can I resolve this one. thx !!!!
            David

            Comment


              #7
              On the indicator properties: Right click->Indicators

              Comment


                #8
                thx. but would like to integrate into the coded strategy....pls refer to earlier notes on this. thx. David

                Comment


                  #9
                  Try:

                  SMA(20).Plots[0].Pen.Width = 2;
                  RayNinjaTrader Customer Service

                  Comment


                    #10
                    thx Ray ! it works

                    Comment


                      #11
                      I am having a problem controlling the Plot Color. I have an indicator that has one plot that was generated by the wizard:

                      Add(new Plot(Color.FromKnownColor(KnownColor.Blue), PlotStyle.Bar, "ChangeFromOpen"));

                      I am assuming that this is stored in Plots[0].

                      The indicator works until I add the following code to the OnBarUpdate method to try and manipulate the color of the plot (the code was copied directly from the help example):

                      if (Values[0] > 100)
                      Plots[0].Pen = new Pen(Color.Blue);
                      else
                      Plots[0].Pen = new Pen(Color.Red);

                      I get the compiler error: Operator '>' cannot be applied to operands of type 'NinjaTrader.Data.DataSeries' and 'int'

                      If I try and compare it to 100.0 then I get the same error message except 'double' instead of 'int'

                      Any help would be greatly appreciated.
                      Last edited by higler; 08-01-2007, 05:14 PM. Reason: Clarification

                      Comment


                        #12
                        Values[0] returns a DataSeries at that index. To get the value of try something like:

                        Values[0][0]

                        Also, no need to create a new Pen object. Best to avoid creating new objects if you do not have to.

                        Plots[0].Pen.Color = Color.Red;
                        '
                        will work for example.
                        RayNinjaTrader Customer Service

                        Comment


                          #13
                          Thanks. That works.

                          Comment


                            #14
                            If I have an indicator with three plots, is there a way to programmatically turn off/on the price markers for the individual plots? Thanks.

                            Comment


                              #15
                              Unfortunately this can only be programatically controlled at the indicator level for all price markers, not individually.
                              RayNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by WHICKED, Today, 12:45 PM
                              2 responses
                              16 views
                              0 likes
                              Last Post WHICKED
                              by WHICKED
                               
                              Started by GussJ, 03-04-2020, 03:11 PM
                              15 responses
                              3,272 views
                              0 likes
                              Last Post xiinteractive  
                              Started by Tim-c, Today, 02:10 PM
                              1 response
                              8 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by Taddypole, Today, 02:47 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post Taddypole  
                              Started by chbruno, 04-24-2024, 04:10 PM
                              4 responses
                              51 views
                              0 likes
                              Last Post chbruno
                              by chbruno
                               
                              Working...
                              X