Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Correct Method for NT7 to NT8 Color to Brush(es) Conversion

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

    Correct Method for NT7 to NT8 Color to Brush(es) Conversion

    Hi,

    I'm uncertain about the correct way to convert NT7 Color objects to NT8 Brushes/Brush objects.

    In NT7 I had input parameters as -

    public Color MYColour1
    {
    get { return myColour1; }
    set { myColour1 = value; }
    }
    // Serialize our Color object
    [Browsable(false)]
    public string MYColour1Serialize
    {
    get { return NinjaTrader.Gui.Design.SerializableColor.ToString( myColour1); }
    set { myColour1 = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value); }
    }


    and variables as -

    private Color myColour1=Color.Purple;
    private Brushes[] myColours = new Brushes[10];


    Assignment (so I can use my colours in an array) as -

    myColours[0]=myColour1;

    And usage as -

    DrawTriangleUp(..., myColours[0]);

    Now in NT8 I have input parameters as -

    public Brushes MYColour1
    {
    get { return myColour1; }
    set { myColour1 = value; }
    }
    // Serialize our Color object
    [Browsable(false)]
    public string MYColour1Serialize
    {
    get { return NinjaTrader.Gui.Design.SerializableColor.ToString( myColour1); }
    set { myColour1 = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value); }
    }



    and variables as -

    private Brushes myColour1 = Brushes.Purple;
    private Color[] myColours = new Color[10];


    Assignment (so I can use my colours in an array) as -

    myColours[0] = myColour1;


    But now when I want to draw I have

    Draw.TriangleUp(this,..., myColours[0]);

    but this method requires a Brush, not Brushes. What is the best/correct method to do this?


    Thanks,
    Will.

    #2
    Brushes is a predefined list of SolidColorBrush's which inherit from System.Windows.Media.Brush.

    It was the same as Colors.Red

    Also, if you wanna array of Brush's, for your Draw.Triangle, use private Brush[] myBrushes = new Brush[10]

    Also don't define a property as type Brushes. Just Brush is fine. If you have questions about what to use check out the pre-installed indicators such as VolumeZones.

    Here's what it should look like -
    Code:
    public Brush MYColour1
    {
    get { return myColour1; }
    set { myColour1 = value; }
    }
    
    // Serialize our Color object
    [Browsable(false)]
    public string MYColour1Serialize
    {
    get { return Serialize.BrushToString( myColour1); }
    set { myColour1 = Serialize.StringToBrush(value); }
    }
    
    
    private Brush myColour1 = Brushes.Purple;
    private Brush[] myBrushes = new Brush[10];
    
    
    myBrushes [0] = myColour1;
    
    Draw.TriangleUp(this,..., myBrushes [0]);

    Comment


      #3
      Just a quick question on Brush serialization. Do the internal conversion routines FREEZE the brush upon loading? Just a thought that hit me...

      Comment


        #4
        Hello,

        Using the built in methods StringToBrush and BrushToString, these can freeze based on if the brush can be frozen, specifically in StringToBrush. Not all cases will be caught as this is resource expensive, so it is generally recommended to handle your own freezing to ensure there are no errors.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Thanks for that, I've sorted that out now, but I have a couple more related questions.

          I had previously (NT7) a reference to plotcolors so i could point directly to a particular color series.

          now I have -

          private Series<Brush> MATemp;

          and later

          MATemp=PlotBrushes[0];

          which is giving a type conversion error. What is the correct way to do this?

          Also, whats the best way to force a chart repaint? I used to have -

          ChartControl.ChartPanel.Invalidate();
          ChartControl.ChartPanel.Refresh();

          but those methods don't exist now.

          Thanks,
          Will.

          Comment


            #6
            Originally posted by dontpanic View Post
            Thanks for that, I've sorted that out now, but I have a couple more related questions.

            I had previously (NT7) a reference to plotcolors so i could point directly to a particular color series.

            now I have -

            private Series<Brush> MATemp;

            and later

            MATemp=PlotBrushes[0];
            Hi. I would write :

            MATemp[0] = PlotBrushes[0][0];

            which is giving a type conversion error. What is the correct way to do this?

            Also, whats the best way to force a chart repaint? I used to have -

            ChartControl.ChartPanel.Invalidate();
            ChartControl.ChartPanel.Refresh();

            but those methods don't exist now.

            Thanks,
            Will.
            ForceRefresh();



            -----------------------------------------------
            Christophe - Ninja-Addons.com
            CEO Azur Investment Technologies "AzurITEC" sas

            3rd Party Add-On Vendor

            Comment


              #7
              In this code

              private Series<Brush> MATemp;

              I'm just declaring the reference, right?

              If I do your assignment

              MATemp[0] = PlotBrushes[0][0];

              Am I assigning a value to an array that doesn't exist?

              I basically just want a pointer or reference to a PlotBrushes series.

              Thanks,
              Will.

              Comment


                #8
                Hello,

                Thank you for the reply.

                If you are getting an error that the series does not exist, you still need to create it in State.Configure:

                Code:
                else if (State == State.Configure)
                {
                	MATemp = new Series<Brush>(this, MaximumBarsLookBack.Infinite);
                }
                Regarding how you have it now, MATemp would be a Series of Brushes from the 0 index of PlotBrushes or MATemp[0] = PlotBrushes[0][0]

                I look forward to being of further assistance.
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  Hi,

                  thanks for the reply, but thats not what I am after. I don't want to create MATemp as a new series. I want MATemp to be a only a REFERENCE to a series of brushes. This was working fine in NT7, I'm simply trying to find out the right way to do it in NT8.

                  So, MATemp is a reference to a brush series object. The series that it refers to will be PlotBrushes[0] or PlotBrushes[5] as examples.

                  In NT7 I had the declaration -

                  private ColorSeries MATemp;

                  And assignment -

                  MATemp=PlotColors[3];

                  Then I could refer to MATemp in the same way as PlotColors[]

                  MATemp[0] would be the same as PlotColors[3][0]

                  I just would like to know the equivalent code in NT8,

                  Thanks again.

                  Comment


                    #10
                    You need to define a BrushSeries as this is what PlotBrushes is.
                    Code:
                    private BrushSeries mySeries;
                    
                    OBU
                    {
                        mySeries = PlotBrushes[5];
                    }

                    Comment


                      #11
                      Hello,

                      Thank you for the clarification.

                      In this case, you are looking for PlotBrushes.

                      In the NinjaScript editor, if you type PlotBrushes[

                      With just the one open brace, you should get a intelleprompt popup that says "BrushSeries BrushSeries[].this etc...
                      The first word BrushSeries in the teal color would be the Type needed in this case.

                      So your syntax would be:

                      Code:
                      private BrushSeries MATemp;
                      
                      MATemp = PlotBrushes[2]; // third plot brush index
                      
                      Print(MATemp[0]);//current bar brush of third plot
                      I look forward to being of further assistance.
                      JesseNinjaTrader Customer Service

                      Comment


                        #12
                        Thanks, thats exactly what I am after, it was the type declaration that I was having trouble with.

                        Also, I can see in the intelliprompt how the type is shown, so I can use that in the future.

                        Just one thing I wanted to mention with the NT8 editor. When there is a compile error and you double-click on the error to take you to the line, its not highlighted like it was in NT7, its just the cursor that is placed at the error location. This means, for me at least, that I'm constantly searching for the cursor position in the editor to find the location of my error. Its a little thing, but very annoying, especially when doing an NT8 conversion and going through error after error, and constantly trying to find the cursor to locate the error. Perhaps you can pass this on to the development team.

                        Thanks,
                        will.

                        Comment


                          #13
                          Hello,

                          I actually had not noticed that myself but that is a good point, possibly an option in the NinjaScript editor to turn that on and off would be good to have.

                          Thanks for the suggestion, I will pass it through to the development team.

                          I look forward to being of further assistance.
                          JesseNinjaTrader Customer Service

                          Comment


                            #14
                            I've posted a script that automates converting most indicators and strategies. See http://ninjatrader.com/support/forum...ad.php?t=79551.

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by algospoke, Yesterday, 06:40 PM
                            2 responses
                            23 views
                            0 likes
                            Last Post algospoke  
                            Started by ghoul, Today, 06:02 PM
                            3 responses
                            14 views
                            0 likes
                            Last Post NinjaTrader_Manfred  
                            Started by jeronymite, 04-12-2024, 04:26 PM
                            3 responses
                            45 views
                            0 likes
                            Last Post jeronymite  
                            Started by Barry Milan, Yesterday, 10:35 PM
                            7 responses
                            21 views
                            0 likes
                            Last Post NinjaTrader_Manfred  
                            Started by AttiM, 02-14-2024, 05:20 PM
                            10 responses
                            181 views
                            0 likes
                            Last Post jeronymite  
                            Working...
                            X