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

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

    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 Kraken29, Today, 12:32 PM
      1 response
      6 views
      0 likes
      Last Post NinjaTrader_Erick  
      Started by codeowl, 02-11-2019, 05:47 AM
      23 responses
      678 views
      0 likes
      Last Post stockbux  
      Started by arangocj, Today, 12:37 PM
      0 responses
      11 views
      0 likes
      Last Post arangocj  
      Started by joselube001, Today, 12:17 PM
      1 response
      10 views
      0 likes
      Last Post NinjaTrader_Erick  
      Started by marcus2300, Today, 10:21 AM
      5 responses
      13 views
      0 likes
      Last Post RaddiFX
      by RaddiFX
       
      Working...
      X