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
    DierkNinjaTrader Customer Service

    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.
            DierkNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by op1031, Today, 05:51 PM
            0 responses
            3 views
            0 likes
            Last Post op1031
            by op1031
             
            Started by nighttrader99, Today, 04:34 PM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_ShawnB  
            Started by Simon Investimens, Today, 02:51 PM
            1 response
            15 views
            0 likes
            Last Post NinjaTrader_ChrisL  
            Started by Unsuitable, Today, 02:49 PM
            0 responses
            14 views
            0 likes
            Last Post Unsuitable  
            Started by AroraAbhishek, Today, 01:49 PM
            1 response
            12 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Working...
            X