Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

NT8 - How to make partial class?

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

    NT8 - How to make partial class?

    I am making a function to generate a LinearGradientBrush based on input parameters of startPoint, endPoint, Brushes, gradientStop offsets etc etc.

    I have done plenty of private classes within indicators but I wanted to try my hand at an external/public class to be accessed by many indicators.

    I followed the instructions to make a partial class in 'Code Breaking Changes' however I can't seem to access my class from another indicator.

    The whole 'Addon' thing still confuses me so I tried adding a duplicate of sorts in both Addons and Indicators.

    I would appreciate it if you can take a look at the code below and advise me what to do.

    Code:
    namespace NinjaTrader.NinjaScript.Indicators.Sim22
    {
        /// <summary>
        /// A function to help generate LinearGradient brushes by Sim22 Nov 2015
        /// </summary>
        public partial class Sim22_LinearGradientBrushFunction : Indicator
        {
            
            public static LinearGradientBrush linBrushFunction(Point startPoint, Point endPoint, Brush gs1Brush, double gs1Offset, Brush gs2Brush, double gs2Offset, Brush gs3Brush, double gs3Offset, Brush gs4Brush, double gs4Offset, Brush gs5Brush, double gs5Offset, Brush gs6Brush, double gs6Offset)
            {
                System.Windows.Media.LinearGradientBrush  linBrush = new LinearGradientBrush();
                
                linBrush.StartPoint = startPoint;
                linBrush.EndPoint = endPoint;
                
                GradientStop gs1 = new GradientStop();
                gs1.Offset = gs1Offset;
                SolidColorBrush gs1SCB = (SolidColorBrush)gs1Brush;
                gs1SCB.Freeze();
                gs1.Color = gs1SCB.Color;
                linBrush.GradientStops.Add(gs1);
                
                GradientStop gs2 = new GradientStop();
                gs2.Offset = gs2Offset;
                SolidColorBrush gs2SCB = (SolidColorBrush)gs2Brush;
                gs2SCB.Freeze();
                gs2.Color = gs2SCB.Color;
                linBrush.GradientStops.Add(gs2);
                
                GradientStop gs3 = new GradientStop();
                gs3.Offset = gs3Offset;
                SolidColorBrush gs3SCB = (SolidColorBrush)gs3Brush;
                gs3SCB.Freeze();
                gs3.Color = gs3SCB.Color;
                linBrush.GradientStops.Add(gs3);
                
                GradientStop gs4 = new GradientStop();
                gs4.Offset = gs4Offset;
                SolidColorBrush gs4SCB = (SolidColorBrush)gs4Brush;
                gs4SCB.Freeze();
                gs4.Color = gs4SCB.Color;
                linBrush.GradientStops.Add(gs4);
                
                GradientStop gs5 = new GradientStop();
                gs5.Offset = gs5Offset;
                SolidColorBrush gs5SCB = (SolidColorBrush)gs5Brush;
                gs5SCB.Freeze();
                gs5.Color = gs5SCB.Color;
                linBrush.GradientStops.Add(gs5);
                
                GradientStop gs6 = new GradientStop();
                gs6.Offset = gs6Offset;
                SolidColorBrush gs6SCB = (SolidColorBrush)gs6Brush;
                gs6SCB.Freeze();
                gs6.Color = gs6SCB.Color;
                linBrush.GradientStops.Add(gs6);
                
                linBrush.Freeze();
                
                return linBrush;
                
            }
        }
    }
    Thank you,

    Simon.
    Attached Files

    #2
    Hello,

    Thank you for the question.

    I was unsure if you were trying to place this in the Indicator folder or addons, for this reply I have placed this in the Addons folder to prevent any un needed indicator code being added to the file.

    Your sample is basically all correct aside from the namespace and Inheritance if you are in the Addons folder.

    To allow this to compile and be seen from a another file, you could change the namespace to:

    Code:
    namespace NinjaTrader.NinjaScript.AddOns
    and the class, remove the inheritance or change:

    Code:
    public partial class Sim22_LinearGradientBrushFunction : Indicator
    to

    Code:
    public partial class Sim22_LinearGradientBrushFunction
    This should allow the file to compile, to use from a different script you could call its qualified name or:

    Code:
    NinjaTrader.NinjaScript.AddOns.Sim22_LinearGradientBrushFunction.linBrushFunction(......);
    I look forward to being of further assistance.

    Comment


      #3
      Brilliant Jesse, thank you. The complex things don't stump me, just the simple things :-s

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      563 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      329 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
      547 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