Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Dynamically change Plot color

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

    Dynamically change Plot color

    6.5.0.8
    Don't know if this has been reported or not.
    This doesn't work.
    Had to use 2 separate Plots.
    // Dynamically change the primary plot's color based on the indicator value
    protected override void OnBarUpdate()
    {
    if (Value[0] > 100)
    Plots[0].Pen = new Pen(Color.Blue);
    else
    Plots[0].Pen = new Pen(Color.Red);
    }

    #2
    Unfortunately what you are trying to achieve is not supported. Please see here on how to create multi color plots: http://www.ninjatrader-support.com/v...ead.php?t=3227

    Comment


      #3
      Try this -

      Plots[0].Pen.Color = Color.Blue;

      etc...
      RayNinjaTrader Customer Service

      Comment


        #4
        Thanks ray, I did try that - it didn't work either. For now I will just use 2 different Plots. Thanks.

        Comment


          #5
          Originally posted by kenz987 View Post
          6.5.0.8
          Don't know if this has been reported or not.
          This doesn't work.
          Had to use 2 separate Plots.
          // Dynamically change the primary plot's color based on the indicator value
          protected override void OnBarUpdate()
          {
          if (Value[0] > 100)
          Plots[0].Pen = new Pen(Color.Blue);
          else
          Plots[0].Pen = new Pen(Color.Red);
          }
          If you do create a new Pen in your code, then you should also dispose of it, because Pens use unmanaged resources and you will get memory leaks. You should store the Pens in a variable in the scope of the class or use the 'using' statement of C#, which will automatically dispose the objects once they leave the 'using'-scrope, like so:

          using(Pen pen = new Pen(Color.Blue))
          {
          Plots[0].Pen = pen;
          }

          Comment


            #6
            AgeKay: Actually your suggestion below will not work since Dispose will be called on the pen as soon as the using scope is left -> I suggest NOT assigning a new pen object but setting the pen properties as by Ray's suggestion.

            Comment

            Latest Posts

            Collapse

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