NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Strategy Development

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

Reply
 
Thread Tools Display Modes
Old 01-23-2009, 01:36 PM   #1
ChiTrader2000
Senior Member
 
Join Date: Nov 2008
Posts: 160
Thanks: 0
Thanked 0 times in 0 posts
Default How to iterate over all user-created "this.Parameters" in NT Strategy code.

Hello,

My users are creating NinjaScript strategies, and they are creating custom parameters for their strategies that look something like this in the C# code:

privateint ticksBetter = 1;

[Description(
"Ticks Better is used to do such-and-such.")]
[Category(
"Parameters")]
publicint TicksBetter
{
get { return ticksBetter; }
set { ticksBetter = Math.Max(0, value); }
}

I am looking for a way to iterate over all user-created custom parameters so that I can write this information out to a database. Using intellisense inside of a strategy, I can't find a collection like "this.Parameters". Is there a collection that holds these parameters that I can iterate over in C# code?

Thanks in advance!

ChiTrader2000
ChiTrader2000 is offline  
Reply With Quote
Old 01-23-2009, 01:39 PM   #2
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

Unfortunately ChiTrader2000, this is not supported.
NinjaTrader_Josh is offline  
Reply With Quote
Old 01-23-2009, 01:50 PM   #3
Ralph
Senior Member
 
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
Default

ChiTrader2000, it's not just not supported by NT, but there is no concept in C# which provides collections for methods, variables or properties automatically. Guess you have to collect it by your own.

Regards
Ralph
Ralph is offline  
Reply With Quote
Old 01-23-2009, 01:56 PM   #4
ChiTrader2000
Senior Member
 
Join Date: Nov 2008
Posts: 160
Thanks: 0
Thanked 0 times in 0 posts
Default

Hello,

Thanks for the information.

I will just write it myself using C# Reflection.

Thanks again,

ChiTrader2000
ChiTrader2000 is offline  
Reply With Quote
Old 01-23-2009, 02:06 PM   #5
Ralph
Senior Member
 
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
Default

Just an idea for coding. Instead of using private variables like:
private int ticksBetter = 1;
you could use the desired (and self-designed) collection as source the properties are reading from, and as target the properties are writing to. This way your collection is always up-to-date without additional coding required.

Regards
Ralph


Ralph is offline  
Reply With Quote
Old 01-24-2009, 11:58 AM   #6
ChiTrader2000
Senior Member
 
Join Date: Nov 2008
Posts: 160
Thanks: 0
Thanked 0 times in 0 posts
Default

Hello Ralph,

That's a great way to do it without using System.Reflection. Problem solved!

Thanks again!

ChiTrader2000
ChiTrader2000 is offline  
Reply With Quote
Old 01-24-2009, 01:48 PM   #7
molecool
Senior Member
 
Join Date: Jan 2009
Posts: 423
Thanks: 25
Thanked 11 times in 10 posts
Default

Hi there:

Alright, I'm fairly new to NT and only started to code in C# but I have been coding in Java for over 12 years. Take a look at this:

http://www.developer.com/java/other/article.php/2114451

In Java it's possible to use 'introspection' to dynamically retrieve a class' parameters and then loop through them. The article covers both Java and C#.

Good luck!

Michael
molecool is offline  
Reply With Quote
Old 02-20-2009, 04:01 PM   #8
BaKlava
Junior Member
 
Join Date: Jan 2009
Posts: 6
Thanks: 0
Thanked 0 times in 0 posts
Default

Can you tell us what function is called to get the Parameter name string that is displayed in the chart, or in the Parametesr column of the strategies tab?
BaKlava is offline  
Reply With Quote
Old 02-22-2009, 01:08 PM   #9
BaKlava
Junior Member
 
Join Date: Jan 2009
Posts: 6
Thanks: 0
Thanked 0 times in 0 posts
Default

Never mind, me and my seemingly limitless genious has figured it out!



public string getParameterString()
{
string parameterString = "";

foreach( NinjaTrader.Strategy.Parameter parameter in this.Parameters)
{
parameterString += "( ";
parameterString += parameter.Name;
parameterString += " = " + parameter.Value;
parameterString += " ) - ";

}
return parameterString;

}
BaKlava is offline  
Reply With Quote
Old 02-22-2009, 02:14 PM   #10
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

Note: this is a area which is beyond what we provide support for. Please be aware that the undocumented features you're using might be gone or work differently on next NT version/release.
NinjaTrader_Dierk is offline  
Reply With Quote
Old 02-22-2009, 02:47 PM   #11
BaKlava
Junior Member
 
Join Date: Jan 2009
Posts: 6
Thanks: 0
Thanked 0 times in 0 posts
Default

When's that? Approx?
BaKlava is offline  
Reply With Quote
Old 02-23-2009, 02:08 AM   #12
NinjaTrader_Ben
NinjaTrader Customer Service
 
NinjaTrader_Ben's Avatar
 
Join Date: May 2008
Location: Denver, CO
Posts: 3,157
Thanks: 0
Thanked 3 times in 3 posts
Default

Hello,

There is no set release date. We are hoping to get it into Beta testing within a few months.
NinjaTrader_Ben 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
Add to ATM Strategy "Trailing "Limit"" shawnj Suggestions And Feedback 2 10-10-2008 08:01 PM
Can "workspaces" be created for charts? bluelou Charting 9 07-18-2008 08:31 AM
"'OrderRejected'. Strategy has sent cancel requests" & "There is no market data..." Elliott Wave Strategy Development 6 04-12-2008 12:03 AM
2 instances of strategy when clicking "apply" and "okay" dtf139 Historical NinjaTrader 6.5 Beta Threads 2 01-07-2008 11:25 PM
SuperDOM Window with "Always On Top" created deadlock jwalker Miscellaneous Support 1 05-19-2005 03:49 PM


All times are GMT -6. The time now is 03:53 PM.