Dynamic Properties - NinjaTrader Programming | futures io social day trading
futures io futures trading


Dynamic Properties
Updated: Views / Replies:7,772 / 23
Created: by baruchs Attachments:4

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Reply
 4  
 
Thread Tools Search this Thread
 

Dynamic Properties

  #11 (permalink)
Elite Member
Huntsville AL/USA
 
Futures Experience: Beginner
Platform: NinjaTrader
Favorite Futures: Stocks, Futures
 
d1g1talfr3ak's Avatar
 
Posts: 24 since Nov 2011
Thanks: 31 given, 46 received

I'm with you

Okay... I just found this thread and I am trying to do the same exact thing.

I want to modify the properties for a strategy at runtime. I know that NT is using a GridControl to store the properties, such as:

[Description("Trade second contract")]
[GridCategory("Parameters")]
public bool TradeSecondContract
{
get { return useContract2; }
set { useContract2 = value; }

I did find where the base strategy has a ParameterCollection that can be accessed through this.Parameters. It contains each of my parameters as their types... but not the description and grid category.
I have tried modifying this list and it does not affect the GridControl.

I'm sure there must be some way to get a reference to the GridControl, but I have yet to find it.

I need to explore under the this.ChartControl.Controls... but I don't think that will be where it is.

This evening I plan on installing a tool to decompile the Ninjatrader dll's and look around. If you ever found an answer to your question please let me know.

Reply With Quote
 
  #12 (permalink)
Elite Member
Israel
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: pfg
Favorite Futures: eminis
 
Posts: 323 since Jun 2009
Thanks: 6 given, 206 received

Hi,
No I didn't find an answer.
I attached an example how to do it in c# (properties are standart c# method)
If you will be able to do it I would appreciate if you share.

Baruch

Reply With Quote
 
  #13 (permalink)
 Vendor: www.sharkindicators.com 
Calgary, AB
 
Futures Experience: Intermediate
Platform: NinjaTrader
Favorite Futures: futures, forex
 
Posts: 11 since Aug 2010
Thanks: 1 given, 39 received

Solution to dynamic properties


Please see the attached file for an example on how this is done. Basically indicator must implement the ICustomTypeDescriptor interface, and each properties that affects other properties must have :
 
Code
[RefreshProperties(RefreshProperties.All)]
When the property grid queries the indicator, it looks for an implementation of ICustomTypeDescriptor. If it's there, the GetProperties method is called instead of using reflection for the properties. A copy is made because the PropertyDescriptorCollection is readonly (so it won't work if you alter that method in this example).

I've made it relatively easy to display the properties you want - just change rewrite the ModifyProperties method. You can see two example properties that hide each other in this case.

Let me know if you have any questions.

Attached Files
Register to download File Type: cs TestProperties.cs (10.9 KB, 260 views)
Reply With Quote
The following 13 users say Thank You to jeremytang for this post:
 
  #14 (permalink)
Elite Member
Huntsville AL/USA
 
Futures Experience: Beginner
Platform: NinjaTrader
Favorite Futures: Stocks, Futures
 
d1g1talfr3ak's Avatar
 
Posts: 24 since Nov 2011
Thanks: 31 given, 46 received

Many Thanks!


jeremytang View Post
Please see the attached file for an example on how this is done. Basically indicator must implement the ICustomTypeDescriptor interface, and each properties that affects other properties must have :
 
Code
[RefreshProperties(RefreshProperties.All)]
When the property grid queries the indicator, it looks for an implementation of ICustomTypeDescriptor. If it's there, the GetProperties method is called instead of using reflection for the properties. A copy is made because the PropertyDescriptorCollection is readonly (so it won't work if you alter that method in this example).

I've made it relatively easy to display the properties you want - just change rewrite the ModifyProperties method. You can see two example properties that hide each other in this case.

Let me know if you have any questions.

I only regret that futures.io (formerly BMT) only let's me thank you once for that post!!

I created a forum on the NinjaTrader support site with the same question and got absolutely no help. I am continually impressed by both the expertise and willingness to help on this site.

Reply With Quote
 
  #15 (permalink)
 Vendor: www.sharkindicators.com 
Calgary, AB
 
Futures Experience: Intermediate
Platform: NinjaTrader
Favorite Futures: futures, forex
 
Posts: 11 since Aug 2010
Thanks: 1 given, 39 received

No problem

Yes this problem I noticed had practically no documentation about it... I ended up having to research the use of the property grid, and tried a variety of approaches until I settled on this one.

Reply With Quote
The following 6 users say Thank You to jeremytang for this post:
 
  #16 (permalink)
Elite Member
Barcelona
 
Futures Experience: Beginner
Platform: NinjaTrader 7
Favorite Futures: CL, TF
 
grankus's Avatar
 
Posts: 8 since Aug 2012
Thanks: 5 given, 0 received

Hello people!

Thank you for this solution, It helped me a lot!

Now I'm trying to change the description, making it dynamic as well, but I don't know how to do it exactly.

Do you know how?

Thanks!

Reply With Quote
 
  #17 (permalink)
Elite Member
Heidelberg, Germany
 
Futures Experience: Intermediate
Platform: NinjaTrader
Favorite Futures: Stocks
 
Posts: 11 since Jun 2014
Thanks: 6 given, 12 received


grankus View Post
Now I'm trying to change the description, making it dynamic as well, but I don't know how to do it exactly.

It is a very large co-incidence that you should ask this on exactly the same night as I am struggling with the same problem.

Unfortunately after many hours I have not found an answer. (C# is not my forte.) The problem seems simply that the complete reflection framework is read-only. The information is retrieved, made available, but can not be updated. In debugging, etc, I think that roughly the code should be as listed below. Unfortunately, this does NOT work.

 
Code
foreach (PropertyDescriptor property in col)
  if (property.Description.Contains("{myToken}"))
    foreach (Attribute attribute in property.Attributes)
      if (attribute.TypeId == typeof(DescriptionAttribute))
        (attribute as DescriptionAttribute).DescriptionValue = "Updated description text.";
The problem is here that DescriptionValue is protected. Also the property.Attributes collection is read-only, it does not even possible to create that new.

With apologies for not posting a working answer, but maybe someone sees an answer.

Brian

Reply With Quote
The following user says Thank You to zr6bcm for this post:
 
  #18 (permalink)
Elite Member
Heidelberg, Germany
 
Futures Experience: Intermediate
Platform: NinjaTrader
Favorite Futures: Stocks
 
Posts: 11 since Jun 2014
Thanks: 6 given, 12 received

Finally! DisplayName can be changed.

Background: what I wanted to do, is change the display name in the optimizer so that it can include information about the possible range of values for this parameter. (For what I am trying to do, the parameter range can change dynamically.)

NinjaTrader.Gui.Design.DisplayName attribute has a Name that can be written to. Thanks NinjaTrader.

Based on the original example, I just updated the source for the GetProperties method:

 
Code
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{
  PropertyDescriptorCollection originalCollection = TypeDescriptor.GetProperties(GetType(), attributes);
  PropertyDescriptor[]		 newProperties      = new PropertyDescriptor[originalCollection.Count];
  originalCollection.CopyTo(newProperties, 0);
  PropertyDescriptorCollection newCollection = new PropertyDescriptorCollection(newProperties);
			
  foreach (PropertyDescriptor property in newCollection)
    foreach (Attribute attribute in property.Attributes)
      if (attribute.TypeId == typeof(NinjaTrader.Gui.Design.DisplayNameAttribute))
      {
            NinjaTrader.Gui.Design.DisplayNameAttribute dn = attribute as NinjaTrader.Gui.Design.DisplayNameAttribute;
            dn.Name = dn.Name.Replace("{0}",  "abc");
            dn.Name = dn.Name.Replace("{1}",  "klm");
            dn.Name = dn.Name.Replace("{2}",  "xyz");
      }

  return newCollection;
}
The code is not the fastest with the double foreach loop and all the inline string replace sequences, but it does show the the basics of something that seems to work (at this wee hour of the morning).

Brian


Last edited by zr6bcm; October 9th, 2014 at 04:28 AM.
Reply With Quote
The following 2 users say Thank You to zr6bcm for this post:
 
  #19 (permalink)
Elite Member
Cedar Rapids, iowa
 
Futures Experience: Intermediate
Platform: Ninjatrader
Broker/Data: Ninjatrader - Continuum
Favorite Futures: 6E, TF, 6J
 
Tasker_182's Avatar
 
Posts: 626 since Aug 2009
Thanks: 426 given, 1,126 received

I implemented Jeremy's code to great effectiveness in this indicator: https://futures.io/download/vip_elite_circle/1539-download.html?view

"Money is better than poverty, if only for financial reasons." - Woody Allen
Reply With Quote
The following 2 users say Thank You to Tasker_182 for this post:
 
  #20 (permalink)
Elite Member
Barcelona
 
Futures Experience: Beginner
Platform: NinjaTrader 7
Favorite Futures: CL, TF
 
grankus's Avatar
 
Posts: 8 since Aug 2012
Thanks: 5 given, 0 received


I'm impressed!!! not only for the coincidence but for your solution, zr6bcm!

Well, maybe is not the most elegant solution with that doble loop, but the most important thing is its functionality.

I'll try this code.

I'd like the improve teh code but I'm not a programmer, I only try to get by and learn more day by day but it's really difficult because the lack of information of certain issues, it's a bit frustrating sometimes...

And regarding to this:


Quoting 
I implemented Jeremy's code to great effectiveness in this indicator: ...

I think I'm not allowed to download this file, because I'm not an Elite member.

But thanks a lot!

Jairo.


Last edited by grankus; October 9th, 2014 at 06:11 PM.
Reply With Quote

Reply



futures io > > > > > Dynamic Properties

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic Fib Lines S/R keepdchange NinjaTrader 10 May 8th, 2011 08:12 PM
Dynamic Stop Loss wallsteetking NinjaTrader Programming 2 March 7th, 2011 09:59 AM
Dynamic Range Indicator arjfca The Elite Circle 3 February 28th, 2011 06:18 AM
Draw object Properties kenz987 NinjaTrader Programming 1 November 10th, 2010 10:48 AM
Trading Hours in NT Properties togier Traders Hideout 4 August 18th, 2010 08:44 AM


All times are GMT -4. The time now is 07:50 PM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts
Page generated 2017-12-15 in 0.13 seconds with 20 queries on phoenix via your IP 54.163.61.66