![]() |
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Oct 2009
Location: Australia
Posts: 108
Thanks: 2
Thanked 14 times in 7 posts
|
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 |
|
NinjaTrader Customer Service
Join Date: Jun 2009
Location: Denver, CO
Posts: 3,149
Thanks: 10
Thanked 89 times in 81 posts
|
David, unfortunately what you are looking to do is unsupported.
Austin
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
|
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 |
|
|
|
|
|
#4 |
|
Senior Member
Join Date: Oct 2008
Posts: 250
Thanks: 0
Thanked 6 times in 2 posts
|
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: http://www.ninjatrader-support.com/H...HKeywords.html . 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 at 03:30 PM.
|
|
|
|
|
|
#5 |
|
Senior Member
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
|
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 |
|
|
|
|
|
#6 | |
|
Senior Member
Join Date: Oct 2008
Posts: 250
Thanks: 0
Thanked 6 times in 2 posts
|
Quote:
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. |
|
|
|
|
|
|
#7 |
|
Senior Member
Join Date: Oct 2009
Location: Australia
Posts: 108
Thanks: 2
Thanked 14 times in 7 posts
|
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 :-
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; } |
|
|
|
|
The following user says thank you to David Lean for this post: |
|
|
|
#8 |
|
Senior Member
Join Date: Oct 2008
Posts: 250
Thanks: 0
Thanked 6 times in 2 posts
|
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. |
|
|
|
|
|
#9 |
|
Senior Member
Join Date: Oct 2008
Posts: 250
Thanks: 0
Thanked 6 times in 2 posts
|
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.
Last edited by cclsys; 11-19-2009 at 05:20 PM.
|
|
|
|
|
|
#10 |
|
Senior Member
Join Date: Oct 2009
Location: Australia
Posts: 108
Thanks: 2
Thanked 14 times in 7 posts
|
"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 at 05:45 AM.
Reason: Fix Typos
|
|
|
|
|
|
#11 |
|
Member
Join Date: Sep 2008
Posts: 68
Thanks: 0
Thanked 0 times in 0 posts
|
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 |
|
|
|
|
|
#12 |
|
Senior Member
Join Date: Oct 2009
Location: Australia
Posts: 108
Thanks: 2
Thanked 14 times in 7 posts
|
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
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. |
|
|
|
|
|
#13 |
|
Member
Join Date: Sep 2008
Posts: 68
Thanks: 0
Thanked 0 times in 0 posts
|
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.
|
|
|
|
|
|
#14 |
|
Senior Member
Join Date: Mar 2008
Location: UK West Sussex
Posts: 665
Thanks: 9
Thanked 9 times in 7 posts
|
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?
|
|
|
|
|
|
#15 |
|
Senior Member
Join Date: Oct 2009
Location: Australia
Posts: 108
Thanks: 2
Thanked 14 times in 7 posts
|
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(); } |
|
|
|
![]() |
| Tags |
| properties, serializable |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [Gui.Design.DisplayName("")]; | blarouche | Version 7 Beta General Questions & Bug Reports | 13 | 11-13-2009 03:24 PM |
| Some attribute clarification on Gui.Design.* | Brian1 | Indicator Development | 4 | 03-17-2009 07:59 AM |
| Gui.Design.DisplayName string? | NinjaCustomer | Indicator Development | 2 | 02-19-2008 10:46 PM |
| Error NinjaTrader.Gui | simone | General Programming | 1 | 06-19-2007 04:40 PM |
| GUI wish list | Oli | Suggestions And Feedback | 1 | 04-02-2007 05:20 AM |