Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Dynamically change Color

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

    Dynamically change Color

    I tried the example in the help screen to dynamically change color of a plot. However, only the last change is active throughout the plot so I get only one change rather than a change for different bars.
    Example from help:
    // Dynamically change the primary plot's color based on the indicator value
    protected override void OnBarUpdate()
    {
    if (Values[0] > 100)
    Plots[0].Pen = new Pen(Color.Blue);
    else
    Plots[0].Pen = new Pen(Color.Red);
    }


    My code:
    if(piSignal[0] == 1)
    {Plots[2].Pen = new Pen(Color.Green,3); else if (piSignal[0] == -1)
    {Plots[2].Pen = new Pen(Color.Red,3);
    else
    {Plots[2].Pen = new Pen(Color.Yellow,3);

    #2
    Correct, your code does exactly that. If you want to have different plotted colors check out this sample.

    RayNinjaTrader Customer Service

    Comment


      #3
      Question about dynamically changing Plot colors

      Hello Ray.

      I am taking a look at the example you posted on dynamically changing Plot colors.

      Question. I'm not sure how 'RisingPlot.Set(1, SMA(Period)[1]);' is working.

      I have ..

      Add(new Plot(Color.Green, PlotStyle.Dot, "Upper"));
      Add(new Plot(Color.Red, PlotStyle.Dot, "Lower"));
      Add(new Plot(Color.Yellow, PlotStyle.Dot, "Middle"));

      But when I get to ..

      UpperPlot.Set(1, MACD(fastLen, slowLen, smooth)[1]);
      UpperPlot.Set(MACD(fastLen, slowLen, smooth)[0]);

      The compiler tells me 'The name 'UpperPlot' does not exist in the current context'.

      What am I missing ?

      Why does the compiler recognize 'RisingPlot.Set' and not 'UpperPlot.Set' ?

      Regards,
      R. C. Singleton

      Comment


        #4
        Hi rcsingleton,

        The plot names are defined in the collapsed "Properties" section of your code.

        Code:
        // Adds three DataSeries to store the values of the three plots added in Initialize()
        [Browsable(false)]    // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
        [XmlIgnore()]        // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
        public DataSeries [COLOR=Red]RisingPlot[/COLOR]
        {
            get { return Values[0]; }
        }
        The index on Values corresponds to the Add() method you had above.
        Code:
        Add(new Plot(Color.Green, PlotStyle.Dot, "Upper"));
        Add(new Plot(Color.Red, PlotStyle.Dot, "Lower"));
        Add(new Plot(Color.Yellow, PlotStyle.Dot, "Middle"));
        Index of 0 corresponds with "Upper", index=1="Lower", index=2="Middle".
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Thank You

          Thank you Josh.

          That did the trick. Will remember to look at 'Properties' section in the future.

          Comment

          Latest Posts

          Collapse

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