NexusFi: Find Your Edge


Home Menu

 





Dynamic Properties


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one baruchs with 6 posts (0 thanks)
    2. looks_two grankus with 3 posts (0 thanks)
    3. looks_3 zr6bcm with 3 posts (6 thanks)
    4. looks_4 sam028 with 2 posts (3 thanks)
      Best Posters
    1. looks_one jeremytang with 10 thanks per post
    2. looks_two zr6bcm with 2 thanks per post
    3. looks_3 Tasker_182 with 2 thanks per post
    4. looks_4 sam028 with 1.5 thanks per post
    1. trending_up 15,184 views
    2. thumb_up 31 thanks given
    3. group 16 followers
    1. forum 23 posts
    2. attach_file 4 attachments




 
Search this Thread

Dynamic Properties

  #11 (permalink)
 
d1g1talfr3ak's Avatar
 d1g1talfr3ak 
Huntsville AL/USA
 
Experience: Beginner
Platform: NinjaTrader
Trading: Stocks, Futures
Posts: 24 since Nov 2011
Thanks Given: 31
Thanks Received: 46

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.

Follow me on Twitter Reply With Quote

Can you help answer these questions
from other members on NexusFi?
MC PL editor upgrade
MultiCharts
REcommedations for programming help
Sierra Chart
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
Better Renko Gaps
The Elite Circle
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
33 thanks
Just another trading journal: PA, Wyckoff & Trends
28 thanks
Bigger Wins or Fewer Losses?
23 thanks
Tao te Trade: way of the WLD
23 thanks
GFIs1 1 DAX trade per day journal
21 thanks
  #12 (permalink)
 baruchs 
Israel
 
Experience: Intermediate
Platform: NinjaTrader
Broker: pfg
Trading: eminis
Posts: 323 since Jun 2009

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

Started this thread Reply With Quote
  #13 (permalink)
 
jeremytang's Avatar
 jeremytang  SharkIndicators is an official Site Sponsor
Site Sponsor

Web: SharkIndicators
AMA: Ask Me Anything
Webinars: SharkIndicators Webinars
Elite offer: Click here
 
Posts: 16 since Aug 2010
Thanks Given: 4
Thanks Received: 53


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
Elite Membership required to download: TestProperties.cs
Reply With Quote
  #14 (permalink)
 
d1g1talfr3ak's Avatar
 d1g1talfr3ak 
Huntsville AL/USA
 
Experience: Beginner
Platform: NinjaTrader
Trading: Stocks, Futures
Posts: 24 since Nov 2011
Thanks Given: 31
Thanks Received: 46


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.

Follow me on Twitter Reply With Quote
  #15 (permalink)
 
jeremytang's Avatar
 jeremytang  SharkIndicators is an official Site Sponsor
Site Sponsor

Web: SharkIndicators
AMA: Ask Me Anything
Webinars: SharkIndicators Webinars
Elite offer: Click here
 
Posts: 16 since Aug 2010
Thanks Given: 4
Thanks Received: 53

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
  #16 (permalink)
 
grankus's Avatar
 grankus 
Barcelona
 
Experience: Beginner
Platform: NinjaTrader 7
Trading: CL, TF
Posts: 8 since Aug 2012
Thanks Given: 5
Thanks Received: 0

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)
 zr6bcm 
Heidelberg, Germany
 
Experience: Intermediate
Platform: NinjaTrader
Trading: Stocks
Posts: 12 since Jun 2014
Thanks Given: 9
Thanks Received: 12


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
Thanked by:
  #18 (permalink)
 zr6bcm 
Heidelberg, Germany
 
Experience: Intermediate
Platform: NinjaTrader
Trading: Stocks
Posts: 12 since Jun 2014
Thanks Given: 9
Thanks Received: 12

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

Reply With Quote
Thanked by:
  #19 (permalink)
 
Tasker_182's Avatar
 Tasker_182 
Cedar Rapids, iowa
Legendary Market Wizard
 
Experience: Intermediate
Platform: Ninjatrader
Broker: Ninjatrader - Continuum
Posts: 716 since Aug 2009
Thanks Given: 476
Thanks Received: 1,401

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

Be yourself; everyone else is already taken. Oscar Wilde
Reply With Quote
Thanked by:
  #20 (permalink)
 
grankus's Avatar
 grankus 
Barcelona
 
Experience: Beginner
Platform: NinjaTrader 7
Trading: CL, TF
Posts: 8 since Aug 2012
Thanks Given: 5
Thanks Received: 0


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.

Reply With Quote




Last Updated on March 18, 2017


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
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.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts