Go Back   NinjaTrader Support Forum > NinjaTrader 8 > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

NinjaTrader
Reply
 
Thread Tools Display Modes
Old 06-01-2017, 11:35 AM   #1
reach4thelasers
Senior Member
 
Join Date: Aug 2015
Location: London, United Kingdom
Posts: 403
Thanks: 41
Thanked 59 times in 51 posts
Default Expandable Object Params in Strategy Analyser

Hey there.

I wonder if someone can help me with a small issue with ExpandableObject properties in the Strategy Analyzer.

I've made a spike of the design pattern I've come up with for composable Strategy settings, comprising a Strategy and two indicators which I have attached.

Each indicator has a settings model, which is the sole Ninjascript Property for the indicator, meaning the indicator can be instantiated like: Indicator(new IndicatorSettings()) rather than a massive parameter list.

The strategy settings model contains the Models of two indicators. I love this method - the time I've wasted copying and pasting parameters between indicators and strategies before now. This is loads better.

Anyway it is working great on the strategies Dialog. However the Strategy Analyser is not working as expected. The properties do appear there; however I am unable to specify the Optimiser parameters Min/Max/Increment e.g. "8;55;1". How can I make the strategy Analyser recognise these for the optimiser?

Thanks

Kevin
Attached Files
File Type: zip StrategyParams.zip (5.0 KB, 7 views)
reach4thelasers is offline  
Reply With Quote
Old 06-01-2017, 02:26 PM   #2
reach4thelasers
Senior Member
 
Join Date: Aug 2015
Location: London, United Kingdom
Posts: 403
Thanks: 41
Thanked 59 times in 51 posts
Default

A follow-on issue with this...

I'm using the System.Web Json Serializer for persistence in the spike strategy. I find its the easiest Serializer to work with in .NET as it was built for serializing objects.

However the strategy Analyzer is moaning that the XML is wrong.

There is an infinite number of ways that something can be serialized. Is there any sample code of the actual Serialization format that Ninjatrader expects? I've only seen code for brushes and fonts, and assumed that any string format would suffice, but clearly that's not the case.
Attached Images
File Type: png serialization.PNG (159.1 KB, 1 views)
reach4thelasers is offline  
Reply With Quote
Old 06-01-2017, 02:55 PM   #3
NinjaTrader_JessicaP
NinjaTrader Customer Service
 
NinjaTrader_JessicaP's Avatar
 
Join Date: Dec 2015
Location: Denver, CO
Posts: 2,403
Thanks: 206
Thanked 504 times in 496 posts
Default

I am investigating your first question. However to your second question regarding serialization, it is the case that the output must fit inside of a well formed XML document. This does not exclude JSON per-se, but any characters such as <, >, non-ASCII 0x20-0x7F, and the like may cause the serializer not to work. This publicly available link has more information.

https://www.w3schools.com/xml/xml_dtd.asp

As a reference I am giving you a code sample which is known to work for a completely different purpose, which you can use as a starting point toward outputting JSON that can fit inside a well formed XML document.

I will be replacing this sample with one tailored to your use case, and will be making a recommendation that our documentation be updated, after I have done more research.

Code:

        /// <summary>
        /// http://ninjatrader.com/support/helpGuides/nt8/en-us/working_with_brushes.htm
        /// </summary>
        [XmlIgnore]
        [Display (
            ResourceType = typeof(Custom.Resource),
            Name = "TestColor",
            GroupName = "NinjaScriptParameters",
            Order = 0
            )]
        public Brush TestColor
        { get; set; }
 
        /// <summary>
        /// http://ninjatrader.com/support/helpGuides/nt8/en-us/working_with_brushes.htm
        /// </summary>
        [Browsable(false)]
        [NinjaScriptProperty]
        public string TestColorSerialize
        {
            get { return GetColorName(((SolidColorBrush) TestColor).Color); }
 
            /// <summary>
            /// From this publicly available link
            /// http://stackoverflow.com/questions/372693/convert-string-to-brushes-brush-color-name-in-c-sharp
            /// <summary>
            set { TestColor = (SolidColorBrush) new BrushConverter().ConvertFromString(value); }
        }
 
 
        /// <summary>
        /// From this publicly available link
        /// http://stackoverflow.com/questions/3934747/system-windows-media-color-to-color-name
        /// <summary>
        public static string GetColorName(System.Windows.Media.Color color)
        {
            Type colors = typeof(System.Windows.Media.Colors);
            foreach(var prop in colors.GetProperties())
            {
                if(((System.Windows.Media.Color)prop.GetValue(null, null)) == color)
                    return prop.Name;
            }
 
            throw new Exception("The provided Color '" + color.ToString() + "' is not named.");
        }
Last edited by NinjaTrader_JessicaP; 06-01-2017 at 03:05 PM.
NinjaTrader_JessicaP is offline  
Reply With Quote
Old 06-01-2017, 10:23 PM   #4
reach4thelasers
Senior Member
 
Join Date: Aug 2015
Location: London, United Kingdom
Posts: 403
Thanks: 41
Thanked 59 times in 51 posts
Default

Thanks Jess! Good thinking, I never thought about encoding. I will get on that now! Cheers
reach4thelasers is offline  
Reply With Quote
Old 06-02-2017, 02:45 PM   #5
NinjaTrader_JessicaP
NinjaTrader Customer Service
 
NinjaTrader_JessicaP's Avatar
 
Join Date: Dec 2015
Location: Denver, CO
Posts: 2,403
Thanks: 206
Thanked 504 times in 496 posts
Default

I have some more information regarding this.

I am attaching a series of indicators I am using for testing, as a tool that I can make immediately available to you. If you are in doubt as to whether an ASCII character will cause serialization to fail simply attach the test indicator with the ordinal matching your ascii character to a chart, save your workspace, close Ninja, and reopen your workspace. If it's serializable, your chart will come up with your indicator attached. This publicly available reference can help you match characters to ordinal values.

http://www.asciitable.com/index/asciifull.png

When I am in the office again on Monday I will address your question regarding optimizing using the strategy analyzer and your design pattern.
Attached Files
File Type: zip Indicators.zip (275.0 KB, 2 views)
NinjaTrader_JessicaP is offline  
Reply With Quote
Old 06-04-2017, 04:17 AM   #6
reach4thelasers
Senior Member
 
Join Date: Aug 2015
Location: London, United Kingdom
Posts: 403
Thanks: 41
Thanked 59 times in 51 posts
Default

Thanks Jessica.

I found a potential bug related to presistence of Nested Properties. I've attached a Spike.

Steps to reproduce:

- Open Ninjascript Output window and add the NestedSettingsPersistance Indicator to a chart
- Note the output of the default string values for Local and nested values
- Open Indicator settings and change values to "Other Nested String" and "Other local string",
- save presets
- push ok
- observe the new values in the output as expected
- remove indicator from chart and re-add
- observe that the values "other nested" and "other local" have been retrieved, indicating that "save presets" has worked and the values were persisted correctly.
- Rebuild Ninjascript
- right click the chart and "reload Ninjascript"
- Observe in the output window that the nested value is back to "default" - the persistence, which previously worked, has now failed after a rebuild.
- Comment out "Browsable(false)" attribute from the NestedSettingsSerializable property and repeat the above tests.
- By removing this property the persistence works as expected even after a rebuild. However the serialized string appears in the property browser which is not ideal.
Attached Files
File Type: cs SerializationHelper.cs (1.2 KB, 3 views)
File Type: cs NestedSettingsPersistenceBug.cs (5.6 KB, 4 views)
reach4thelasers is offline  
Reply With Quote
The following user says thank you to reach4thelasers for this post:
Old 06-06-2017, 01:19 PM   #7
NinjaTrader_JessicaP
NinjaTrader Customer Service
 
NinjaTrader_JessicaP's Avatar
 
Join Date: Dec 2015
Location: Denver, CO
Posts: 2,403
Thanks: 206
Thanked 504 times in 496 posts
Default

This behavior was confirmed on our end. We will be investigating this further. Please keep an eye on the NinjaTrader 8 Release Notes page for updates and bugfixes.


http://ninjatrader.com/support/helpG...ease_notes.htm


Tracking ID:NTEIGHT-11779
Attached Files
File Type: cs NestedSettingsPersistance.cs (5.8 KB, 0 views)
File Type: cs SerializationHelper.cs (1.4 KB, 0 views)
NinjaTrader_JessicaP is offline  
Reply With Quote
Old 06-14-2017, 12:16 PM   #8
reach4thelasers
Senior Member
 
Join Date: Aug 2015
Location: London, United Kingdom
Posts: 403
Thanks: 41
Thanked 59 times in 51 posts
Default

Hey Jess,

Did you find out any further information about my Original Query in Post #1 below?
reach4thelasers is offline  
Reply With Quote
Old 06-14-2017, 12:57 PM   #9
NinjaTrader_JessicaP
NinjaTrader Customer Service
 
NinjaTrader_JessicaP's Avatar
 
Join Date: Dec 2015
Location: Denver, CO
Posts: 2,403
Thanks: 206
Thanked 504 times in 496 posts
Default

Due to the way I reported some things, I left this ticket in a state that was difficult for our tracking software to manage, and as a result have not put more effort into making the sorts of inputs you mentioned in post #1 vulnerable to the optimizer. I apologize for this. I am reviewing this now and will come back when I have more information.
NinjaTrader_JessicaP is offline  
Reply With Quote
Old 06-19-2017, 07:58 AM   #10
NinjaTrader_JessicaP
NinjaTrader Customer Service
 
NinjaTrader_JessicaP's Avatar
 
Join Date: Dec 2015
Location: Denver, CO
Posts: 2,403
Thanks: 206
Thanked 504 times in 496 posts
Default

I was unable to compile and run the spike you created in your first post. I received the attached errors. If the compile time errors are the question being asked, the reason for these is that the NinjaTrader compiler generates code automatically, and the code as written is incompatible with the generator. If there are special compiling instructions please let me know.
Attached Files
File Type: csv NinjaTrader Grid 2017-06-19 07-57 AM.csv (1.2 KB, 3 views)
NinjaTrader_JessicaP is offline  
Reply With Quote
Old 06-19-2017, 11:51 AM   #11
reach4thelasers
Senior Member
 
Join Date: Aug 2015
Location: London, United Kingdom
Posts: 403
Thanks: 41
Thanked 59 times in 51 posts
Default

Hey Jess,

Try the attached. I think the Ninjascript code at the bottom had the Namespaces out of sync. If this doesn't work try deleting the Ninjascript code at the bottom and letting it regenerate.

Let me know if it works. I can send you a version without the Namespaces if necessary.

Kevin.
Attached Files
File Type: zip StrategyParams.zip (5.0 KB, 1 views)
reach4thelasers is offline  
Reply With Quote
Old 06-19-2017, 02:21 PM   #12
NinjaTrader_JessicaP
NinjaTrader Customer Service
 
NinjaTrader_JessicaP's Avatar
 
Join Date: Dec 2015
Location: Denver, CO
Posts: 2,403
Thanks: 206
Thanked 504 times in 496 posts
Default

Attached is a code sample that should do something like what you are describing. Code samples we provide are for educational purposes, and are not intended for live trading, and are not guaranteed to accomplish any user goal or to be maintained.
Attached Files
File Type: zip Filename.zip (5.8 KB, 4 views)
NinjaTrader_JessicaP is offline  
Reply With Quote
Old 06-21-2017, 11:41 AM   #13
reach4thelasers
Senior Member
 
Join Date: Aug 2015
Location: London, United Kingdom
Posts: 403
Thanks: 41
Thanked 59 times in 51 posts
Default

Hey Jess, thanks for the response. That works pretty well, I was hoping it would just pick up the nested properties, but your solution works for me!!

Thanks again

Kevin
reach4thelasers is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Bug: improperly cloned expandable object ETFVoyageur Version 8 Beta 55 08-11-2016 09:39 PM
Cannot reflect expandable object? ETFVoyageur Version 8 Beta 5 08-04-2016 04:27 PM
NT8-B5: Null object exception in Market Analyser Laker Version 8 Beta 1 10-07-2015 01:19 PM
Params show on Chart, but not Strategy Wizard zoltran Indicator Development 3 07-17-2007 11:43 PM


All times are GMT -6. The time now is 02:48 AM.

Futures, foreign currency and options trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing ones financial security or lifestyle. Only risk capital should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results. View Full Risk Disclosure.

CFTC Rules 4.41 - Hypothetical or Simulated performance results have certain limitations, unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under-or-over compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.

This website is hosted and operated by NinjaTrader, LLC (“NT”), a software development company which owns and supports all proprietary technology relating to and including the NinjaTrader trading platform. NT is an affiliated company to NinjaTrader Brokerage (“NTB”), which is a NFA registered introducing broker (NFA #0339976) providing brokerage services to traders of futures and foreign exchange products. This website is intended for educational and informational purposes only and should not be viewed as a solicitation or recommendation of any product, service or trading strategy. No offer or solicitation to buy or sell securities, securities derivative or futures products of any kind, or any type of trading or investment advice, recommendation or strategy, is made, given, or in any manner endorsed by any NT affiliate and the information made available on this Web site is not an offer or solicitation of any kind. Specific questions related to a brokerage account should be sent to your broker directly. The content and opinions expressed on this website are those of the authors and do not necessarily reflect the official policy or position of NT or any of its affiliates. 

Vendors along with their websites, products and services, collectively referred to as (“Vendor Content”), are independent persons or companies that are in no manner affiliated with NT or any if its affiliates. NT or any of its affiliates are not responsible for, do not approve, recommend or endorse any Vendor Content referenced on this website and it’s your sole responsibility to evaluate Vendor Content. Please be aware that any performance information provided by a vendor should be considered hypothetical and must contain the disclosures required by NFA Rule 2-29(c). If you are interested in learning more about, or investigating the quality of, any such Vendor Content you must contact the vendor, provider or seller of such Vendor Content. No person employed by, or associated with, NT or any of its affiliates is authorized to provide any information about any such Vendor Content. Visit the CFTC resources for education regarding the industry and signs of fraud.