Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to set default line color based on another property?

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

    How to set default line color based on another property?

    I'm trying to set the default line color for an indicator based on the setting of another property. The reason is that several copies of the indicator, with different settings, might be displayed in the same panel, and they need to be different colors to tell them apart.

    I tried the following code, which works perfectly, except that it generates an error message to the Output window. The error message is:

    Failed to set property 'CorrType' for indicator 'Correlation3': Exception has been thrown by the target of an invocation.

    What is the reason for the error message, and can you please tell me how to set the plot color from another property setter without triggering an error message, or else stop sending the error message?

    Thanks.

    Code:
    public CorrelationType CorrType
    {
           get { return corrType; }
           set 
           { 
    		corrType = value; 
    		switch (corrType)
    		{
    			case CorrelationType.Pearson:
    				Plots[0].Pen.Color = Color.CornflowerBlue;
    				break;
    			case CorrelationType.Rank:
    				Plots[0].Pen.Color = Color.Red;
    				break;
    			case CorrelationType.Residual:
    				Plots[0].Pen.Color = Color.ForestGreen;
    				break;
    			case CorrelationType.PctChange:
    				Plots[0].Pen.Color = Color.Purple;
    				break;
    		}
    	}
    }

    #2
    kdoren,

    This is not supported.

    What you can try is just doing it from Initialize().
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      I doesn't work in Initialize() (I tried that first).

      I want to change the default color but still allow the user to set it to something else. The code I posted works exactly right in every way, except it generates that (non-fatal) error message.

      Comment


        #4
        Turns out it was an index out of range exception, it works if you precede the switch statement with:

        if (Plots.Length > 0)
        switch ( ... etc.

        Comment


          #5
          kdoren,

          Glad you got it resolved and thanks for posting the fix.
          Josh P.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

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