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

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 agclub, 04-21-2024, 08:57 PM
            4 responses
            18 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by Irukandji, Today, 04:58 AM
            0 responses
            3 views
            0 likes
            Last Post Irukandji  
            Started by fitspressoburnfat, Today, 04:25 AM
            0 responses
            2 views
            0 likes
            Last Post fitspressoburnfat  
            Started by Skifree, Today, 03:41 AM
            1 response
            4 views
            0 likes
            Last Post Skifree
            by Skifree
             
            Started by usazencort, Today, 01:16 AM
            0 responses
            1 view
            0 likes
            Last Post usazencort  
            Working...
            X