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

Complete list of NinjaTrader.Gui.Design.Serializable options?

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

    Complete list of NinjaTrader.Gui.Design.Serializable options?

    Hi,
    I'm looking for a complete list of methods that NinjaTrader supplies to serialize properties.
    For example:
    NinjaTrader.Gui.Design.SerializableColor
    NinjaTrader.Gui.Design.SerializableFont

    Unfortunately the Intellisense is not assisting to list the Methods under
    NinjaTrader.Gui.Design. Given that it doesn't list "Gui" as a method under NinjaTrader but if you type it in, then does work & does list all the methods below "NinjaTrader.Gui". I think it is a bug ie They didn't correctnly attribute all the classes when they developed them.

    Specifically I'm looking for an option to Serialize a FileInfo &/or Directory object as that would make it easier for end users to have a Sound File as a property.

    Thanks

    #2
    David, unfortunately what you are looking to do is unsupported.
    AustinNinjaTrader Customer Service

    Comment


      #3
      Hi David,

      you are probably on your own. You need a pair of two functions: one converts your public object interface into a blank/comma/semicolon-separated string, the other reads the string back, cuts it into an array with split(), creates a new object instance and populates the public interface with tryparse or something similar applied to the string array.

      Regards
      Ralph

      Comment


        #4
        This is only marginally related but involves serializing. I just added a data series to an existing indicator and am referencing it in a new indicator I made. It works fine. However, I cannot save a template with it, getting the 'contact help for information about serializing' message. I have tried adding in and taking away the Browsable and XML ignores, but it won't take. I have run into this sort of thing before and muddled through usually, but this time it ain't happening, I think because it's the first time I am using a DataSeries I made myself versus referencing a plot.

        There is nothing in the HD help menu or the online list at:

        .

        So what does a properly set up DataSeries look like in the Variables and Properties Menu so that it can be accessed in other indicators and be saveable into templates?

        PS After typing this I tried loading and unloading it and it worked fine, so I guess the changes I made were good but it had to be reloaded. I still would appreciate some references to what this serializing business is. I know the word, but I have no idea what it means and what the issue is. There is nothing I have found in the Help areas about it. No big deal, but would like to further understanding.
        Last edited by cclsys; 11-15-2009, 04:30 PM.

        Comment


          #5
          cclsys, serialisation is a concept which saves an arbitrary property as a string in an xml file (workspace in case of NT), and vice versa. Serialisation for native c# data types is implemented by the compiler automatically. For structures and classes you need to write it by your own, the compiler couldn't know which components you would like to serialise and how to do that.
          It is a complex topic, if you need help for a certain implementation, a simple executable example would be helpful.

          Regards
          Ralph

          Comment


            #6
            Originally posted by Ralph View Post
            cclsys, serialisation is a concept which saves an arbitrary property as a string in an xml file (workspace in case of NT), and vice versa. Serialisation for native c# data types is implemented by the compiler automatically. For structures and classes you need to write it by your own, the compiler couldn't know which components you would like to serialise and how to do that.
            It is a complex topic, if you need help for a certain implementation, a simple executable example would be helpful.

            Regards
            Ralph
            Thxs. That helps knowing it goes into an xml. As for example, I bat it back:

            it would be helpful for me to see examples of DataSeries that are set up correctly and one or two that are set up incorrectly so that I can understand what is wanted since there are no guidelines/instructions anywhere (that I can find) in the Help Menus, despite the prompt to get instructions therein.

            It also seems to be from experience - though maybe I am confused - that the XML ignore line in the Properties Menu seems to have a different effect with Plots than DataSeries in that sometimes you have to have it there for the templates to work and sometimes you have to make sure it isn't there. Again, maybe I am confused because I have no background in C languages (or any lingos except Tradestation), but also the lack of documented Help with examples certainly makes it hard to figure out on one's own.

            Comment


              #7
              Solution

              Warning: I've been asked to remind all that "Unsupported" means this may break in a future release. Or might not work with other aspects of the program eg Analyzer etc. Use this insight with caution, it is not documented.


              Thanks everyone.
              I used .NET reflection to rip out all the Methods, Properties etc.
              I can state with confidence that there are only 3 extra serialisation methods provided by Ninja above that which comes standard with .NET.
              They are :-
              • NinjaTrader.Gui.Design.SerializableColor
              • NinjaTrader.Gui.Design.SerializableFont
              • NinjaTrader.Gui.Design.SerializablePen
              Pen seems to work differently so get confident with the others first.

              On Serialising the File Object.
              Clearly not difficult to parse the properties into a Parameter & use XMLSerialise & StreamWriter to create my own serialization class. But unlike the Color & Font it doesn't appear that the Ninja properties dialog is designed to handle the File Objects properties. So hooking it up the FileOpen dialog looked like it would make the indicator too hard to install on other peoples machines. As getting an "easy to change property value" experience wa what I was going for. Its back to the drawing board.

              I hope you find the code below useful.

              Partial code walking you thru the step to use build-in Ninja Serialization.
              Step 1 - Declare local Variables

              #region Variables
              // Wizard generated variables
              private float yOffset = 15; // Gap up from the bottom of the Panel
              private Color textColor = Color.Black;

              // User defined variables (add any user defined variables below)
              //----------< Text for Y Axis Labels >--------------------
              StringFormat stringFormat = new StringFormat();
              private SolidBrush textBrush = new SolidBrush(Color.Black);
              private Font textFont = new Font("Arial", 8);
              #endregion

              Step 2 - Set Brush color to property

              protected override void Initialize()
              {
              textBrush.Color = textColor;

              Step 3 - Set Properties & Serialise Correctly


              [Description("Y Offset of text from Bottom of Panel")]
              [Category("Parameters - Font")]
              [Gui.Design.DisplayName("Text Position")]
              public float YOffset
              {
              get { return yOffset; }
              set { yOffset = Math.Min(Math.Max(0,value),1000); }
              }

              [Browsable(false)]
              public string MyFontSerialize
              {
              get { return NinjaTrader.Gui.Design.SerializableFont.ToString(textFont); }
              set { textFont = NinjaTrader.Gui.Design.SerializableFont.FromString (value); }
              }

              [XmlIgnore()]
              [Description("Font of Bar Numbers")]
              [Gui.Design.DisplayName("Text Font")]
              [Category("Parameters - Font")]
              public System.Drawing.Font TextFont
              {
              get { return textFont; }
              set { textFont = value; }
              }

              [Browsable(false)]
              public string TextColorSerialize
              {
              get { return NinjaTrader.Gui.Design.SerializableColor.ToString(textColor); }
              set { textColor = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value); }
              }

              [XmlIgnore()]
              [Description("Color of Bar Numbers")]
              [Category("Parameters - Font")]
              [Gui.Design.DisplayName("Text Color")]
              public Color TextColor
              {
              get { return textColor; }
              set { textColor = value; }
              }
              #endregion

              Step 4 - Use it Somewhere

              public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
              {
              // ---< ensure you call the base Plot Method prior to exiting this method >---
              base.Plot(graphics, bounds, min, max);

              if (Bars == null || /*Plots.Count < 2 ||*/ ChartControl == null)
              return;

              // if (CurrentBar <= 1)
              // return;

              // ------------< Initialise Offsets & Graphic environment >---------------------
              int barWidth = ChartControl.ChartStyle.GetBarPaintWidth(ChartCont rol.BarWidth);
              int barSpace = ChartControl.BarSpace;

              SmoothingMode oldSmoothingMode = graphics.SmoothingMode;
              graphics.SmoothingMode = SmoothingMode.AntiAlias;

              // ===< Determine where Text will be displayed.Bottom of the Price Chart >===
              float y = bounds.Top + bounds.Height - yOffset - textFont.Height;
              graphics.DrawString( "CB-cntBar", textFont, textBrush, bounds.Left, y, stringFormat);

              float y2 = y - 15;
              graphics.DrawString( "cntBar", textFont, textBrush, bounds.Left, y2, stringFormat);

              // ---< For each bar that is displayed on the screen >---
              for(int cntBar = ChartControl.FirstBarPainted; cntBar <= ChartControl.LastBarPainted; cntBar++)
              {
              // if (!ChartControl.ShowBarsRequired && cntBar < BarsRequired)
              // continue;

              float x = ChartControl.GetXByBarIdx(cntBar);
              graphics.DrawString( (CurrentBar - cntBar).ToString(), textFont, textBrush, x, y, stringFormat);
              graphics.DrawString( cntBar.ToString(), textFont, textBrush, x, y2, stringFormat);
              }

              //=====< Return SmoothingMode to its original value >========
              graphics.SmoothingMode = oldSmoothingMode;
              }

              Comment


                #8
                David, thanks for an incredibly generous reply. I'll be chewing on that on and off for a while as I muck around in my amateur attempts to translated simple ideas into code.

                If you still have the interest: could you try to explain in normal English for non-programmers like myself what the BrowsableFalse and XML ignore lines are telling the code to do exactly? Someone explained it to me before but I didn't understand the terms at all so it didn't 'take'.

                Thanks again.

                Comment


                  #9
                  Look, that is not the original topic of this thread, but it is a little niggle I noticed today with graphics and perhaps your or someone else can help me out, or there is no solution.
                  I just uprgraded monitors to a lovely 23-incher with higher contrast etc.

                  Yesterday I coded in some wingding thingies above/below bars to make them smaller than the default dots/triangles etc. which are rather big.

                  Now with my monitor today I see some sort of black background around the text, or gray rather. Clearly (pun intended) this is not a big deal, but if there is a way to just have the character without the background I would like it better.

                  {DrawText(CurrentBar.ToString()+"ScalpDown" , true, wd, 0 , Low[0] -t, Color.Turquoise,
                  textFont1, StringAlignment.Center, Color.Transparent, Color.Transparent, 1);}

                  The text I lifted from somewhere else to know how to code the CurrentBar.ToString etc. had Color.Empty instead of Transparent. I put in the latter to see if it would make any difference. It didn't. Any ideas, or is this just something that is just going to be there. Doesn't seem to be there with triangles and dots though....

                  Not sure if you will be able to see it with my snapshot, but around the smallest windgdinger thingies is a square (it looks like) of a greyish color. Maybe that is just the nature of a wingding character which might be a picture saved to a file which is produced when the character is called and this picture is part of the character. But when you type that same wingding onto a white screen in a doc text, there is no such background in evidence, nor on blue screen.

                  Small thing. A little wingding thing. But if there is an instruction that would clear it up, would appreciate it. Now I notice the problem it is irritating me! The smaller the problem, the more it 'bugs' you!
                  Maybe I bought a bad monitor. But somehow I doubt that's it.
                  Attached Files
                  Last edited by cclsys; 11-19-2009, 06:20 PM.

                  Comment


                    #10
                    "Could you try to explain in normal English for non-programmers like myself what the BrowsableFalse and XML ignore lines are telling the code to do exactly? "
                    Sorry I can not answer this with authority as I've not seen any documentation on either of these attributes from Ninja. They do pre-compile & generate their own code so they may be ding something non-standard.

                    But assuming they are just passing them direct to .NET. Which is a safe bet, then the following answer should be close.
                    [Browsable(false/true)]
                    Your Indicator code is creating a Class. This class describes how your indicator will behave when you actually put the indicator on the chart. Each time you put the Indicator on a chart it creates an Indicator Object. This is similar to the class being "A Baby". But if you actually create a baby object. You set its properties like Eye Colour, Gender & Name. Even if delete a baby & create a new one with the same Property values it is a New Baby object.
                    Classes have Methods & Properties.
                    You can define properties which are visible (Public) to someone who creates the Indicator Object & those which are not visible (private). This is what you are doing when you put Public or Private before the variable name or Property name or method name.

                    It is possible to pass your object to a Properties dialog box, which can read all the Public properties & display them. But some of these properties need to be public so code can access them but you don't want to display in the Properties dialog. The [Browsable] Attribute is a way of control if a public property is visible in the Properties dialog. Clearly Private properties aren't visible anywhere, so they don't need this attribute.


                    [XMLIgnore ]
                    Serialization is the process of taking the Public properties of an object & flattening them out into a binary string or XML Document. This makes it easy to transmit or save to a file. The value of each field & public property becomes an XML element or XML Attribute in an XML document.

                    By default .NET will try to use the XMLSerializer class to serialize all the public properties. So if you try to "save" an instance of your object (Indicator) & persist it to disk or maybe transmit it to another location, you don't have to do anything, it just happens. But that really only works for the basic .NET datatypes (like int & string). For more complex properties that are really objects which contain their own properties, they need to expose their own methods which .NET can call & ask it to serialise itself. So if you've written a method that serialises a particular complex property you want .NET to use your method & not the default XMLSerialiser (which will fail). XMLIgnore is the way to tell it "Don't do anything with this property, I've serialised it myself. Or in this case, I'm using it to serialise other stuff & don't need it serialised at all."


                    I hope this was at a level that makes sense. I've kinda glossed over & simplified things so I hope I didn't upset those who think this explaination lacks precision
                    Dave.
                    Last edited by David Lean; 11-20-2009, 06:45 AM. Reason: Fix Typos

                    Comment


                      #11
                      Properties section of Startegy

                      Hi David,
                      This is dort of off topic but this is the closest thread I could find. Some of the Indicators I have found here have different "sections" in the parameter
                      list wich is dispalyed when you load the Indicator.
                      I have tried to do the smae thing for a strategy by changing

                      [Catagory("Prameters")];

                      to

                      [Catagory("Stop Loss Settings")]

                      But nothing shows up in the Dialog box. What am I missing??
                      Thanks for your help

                      Comment


                        #12
                        In v6.5 the idea of creating different sections in your parameter list has some advantages & a massive disadvantage. (I think this may change in v7.0)
                        Advantages
                        1. You can break the parameters up into logical groups. Which may also make it easier to sort them how you want.
                        2. You can control what parameter values are displayed at the top of the chart. As only the ones in the Parameter section will be displayed in the signature of the indicator.
                        Disadvantage
                        • Bacause of Point 2 above. No other parts of Ninja can see your "extra" parameters. So if you need to use them in a Strategy, Market Analyzer etc you can't.
                        So. The Strategies you create live in a harness that needs to pass parameters to your strategy, & run it a squillion times. It needs to know about all your parameters (as you might want to optimise them) & you will notice that unlike indicators the pre-compiler doesn't put all that extra code down the bottom of your code. Which suggests to me (& I'm only guessing as I don't have access to Ninja internals) that the strategies are all grouped together & compiled tightly into the Strategy execution system.

                        In Short.
                        If you created a parameter like that, the strategy execution engine would not know how to pass it, its value. So they don't let you do it.

                        Comment


                          #13
                          Thanks for the reply. I have to think you are right. I did try changing the "Parameters" to something else and the ones I changed did not even display in the dialog box.

                          Comment


                            #14
                            cclsys

                            re the wingdings issue - have you tried Color.Empty instead of transparent. I only found this out working with a black background where I had the same issue - I had wondered if it was a small bug?

                            Comment


                              #15
                              Part 1/2

                              Sorry I don't have the time at present to reproduce your issue & give you a code solution that works.
                              So this is speculation.
                              1. Like you I'd have tried Color.Empty on the background. But you say that doesn't work. I'd also test to see if the issue is actually designed into the font. Try increasing the font size, really big &/or changing the Font Color. You may discover that the "Greyish" edges is actually the anti-aliasing that ie designed into the font. By changing the colour the "greyish" area should change to a different color. This should not be relevant if they are Tryetyppe fonts. (which they are in Vista & Win7) I'm unsure about WinXP, they may be bitmap fonts.

                              2. An alternative is to use the PLOT method. (See some of my other posts) You can draw whatever shape you want with GDI+ & use
                              ChartControl.GetXByBarIdx(cntBar);
                              to find the X location of the Bar. Then use High or Low with an offset to put your symbol where you want.

                              Sample GDI code
                              privatevoid DrawSymbol(Graphics graphics, SymbolType mySignal, int x, int YValue, Color symbolColor ) {
                              // =====< Draw appropriate graphic signal >=======

                              // ---< Initialise GDI objects >---
                              int barWidth = ChartControl.ChartStyle.GetBarPaintWidth(ChartCont rol.BarWidth);
                              Pen penBlack = new Pen(System.Drawing.Color.Black, 0); //Might add a width as 2nd param
                              SolidBrush signalBrush = new SolidBrush( symbolColor);
                              GraphicsPath path = new GraphicsPath();

                              // ---< Paint the symbol >---
                              switch (mySignal)
                              {
                              // -------< Non-Directional Signals >-------------------
                              case SymbolType.Circle:
                              // =========< Draw As Circles >========
                              path.AddEllipse( (x - barWidth/2) , YValue, barWidth, barWidth);
                              graphics.DrawEllipse(penBlack, x - barWidth/2 , YValue, barWidth ,barWidth);
                              break;

                              }
                              //=========< Paint color into Signal shape >=======
                              graphics.FillPath(signalBrush, path);
                              signalBrush.Dispose();
                              penBlack.Dispose();
                              path.Dispose();
                              }

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by arvidvanstaey, Today, 02:19 PM
                              4 responses
                              11 views
                              0 likes
                              Last Post arvidvanstaey  
                              Started by samish18, 04-17-2024, 08:57 AM
                              16 responses
                              60 views
                              0 likes
                              Last Post samish18  
                              Started by jordanq2, Today, 03:10 PM
                              2 responses
                              9 views
                              0 likes
                              Last Post jordanq2  
                              Started by traderqz, Today, 12:06 AM
                              10 responses
                              18 views
                              0 likes
                              Last Post traderqz  
                              Started by algospoke, 04-17-2024, 06:40 PM
                              5 responses
                              47 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Working...
                              X