Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
How can I access TickSize (or equivalent) from strategy Parameter section?
Collapse
X
-
Hello,
Thank you for the question.
Are you referring to a properties set?
or
Code:private double period; [Description("Period")] [GridCategory("Period")] public double Period { get { return period; } set { period = value; } }
Code:private double period; [Description("Period")] [GridCategory("Period")] public double Period { get { return period + 1 * TickSize; } set { period = value; } }
I look forward to being of further assistance.JesseNinjaTrader Customer Service
-
The problem is in get_ticks_dollar_str(). The way it is right now causes an exception to be thrown. If I switch the comments so TickSize is not used all works just fine, except that I don't get the tick size associated with the instrument.
Code:[Description("Enter ticks only. Ticks and dollars will be displayed.")] [GridCategory("Parameters -- Order Handling")] [Gui.Design.DisplayName ("011 1st scale out -- ticks")] public string First_scale_out__ticks_str { get { return user__1st_scale_out__ticks_str; } set { _1st_scale_out__ticks = get_ticks( value ); if( _1st_scale_out__ticks <= 100 ) user__1st_scale_out__ticks_str = get_ticks_dollar_str( _1st_scale_out__ticks ); } } // Typical arg = "10 ticks = $50.00" //----------------------------------------------------------------------------------- private int get_ticks( string str ) { char[] delimiters = { ' ' }; string[] words = str.Split( delimiters ); return Int32.Parse( words[ 0 ] ); } // Create tick dollar string to display in parameters //----------------------------------------------------------------------------------- private string get_ticks_dollar_str( int ticks ) { // double scale_dollars = ticks * 5; // This works double scale_dollars = ticks * TickSize; // This throws an exception return ticks.ToString() + " ticks \t= " + scale_dollars.ToString("C"); }
Comment
-
Hello,
Thank you for providing this.
I re created the variables for this and tried it, I am getting a few various errors in your get_ticks method.
For this, to accurately figure out the reason I would need a sample for the input on this. it seems get_ticks takes a string input and parses the string. Can you provide an example of the string you are passing into this method?
I will work on the get_ticks first, the property is trivial once the method is working correctly but for now it seems this is the cause.
The message: 'MinjaTrader.Strategy.bcSr' could not be deserialized: is most likely caused by this property not currently working correctly, simple types like String and Int can be serialized but only if the Get/Set work for the property. You would get errors like this if you try to serialize a more complicate object like a color also.
I look forward to being of further assistance.JesseNinjaTrader Customer Service
Comment
-
All three of these work fine:
ticks = get_ticks( "10 ticks = $50.00" );
ticks = get_ticks( value );
ticks = 10;
When I replace TickSize with a literal or variable all works just fine. Functionally correct and no exceptions. The user enters a numerical tick count in the strategy parameter dialog box. Tick and dollar amount are then displayed.
Your example is a little different in that your usage of TickSize is in get{} and mine is in set{}. Can't see why that would matter although it might.
This snippet illustrates the issue. The only line of code that will cause the failure is the one with TickSize.
[Code:Description("Enter ticks only. Ticks and dollars will be displayed.")] [GridCategory("Parameters -- Order Handling")] [Gui.Design.DisplayName ("011 1st scale out -- ticks")] public string Ticks_str { get { return ticks_str; } set { ticks = 10; // ticks_str = ticks .ToString() + " ticks \t= " + (ticks * TickSize).ToString("C"); // This does not work ticks_str = ticks .ToString() + " ticks \t= " + (ticks * 5).ToString("C"); // This works } }
Comment
-
Hello,
I am not sure I see exactly what was wrong in your existing example, I replaced what you had with a slightly different approach which adds some error handing in case you do not enter a number.
I believe what you are trying to do would be the following:
Code:private int ticks = 0; private string ticks_str = ""; [Description("Enter ticks only. Ticks and dollars will be displayed.")] [GridCategory("Parameters -- Order Handling")] [Gui.Design.DisplayName ("011 1st scale out -- ticks")] public string Ticks_str { get { return ticks_str; } set { ticks = 0; int.TryParse(value, out ticks); ticks_str = ticks.ToString() + " ticks \t= " + (ticks * TickSize).ToString("C"); } }
I look forward to being of further assistance.JesseNinjaTrader Customer Service
Comment
-
Not sure what is going on here, but when I replace my set{} with the example you provided I get the same error I get with my version. All I have to do is replace TickSize with a number and the exceptions go away and all works fine. This is true with your version and mine.
If I use TickSize in get{} or set{} I get the exceptions.
This is from the TickSize help:
"NOTE: This property should NOT be accessed within the Initialize() method."
I assume because it is not valid or initialized yet.
The get{} set{} of parameters are certainly accessed before initialize(). So maybe what I am trying to do cannot be done with TickSize directly.
Comment
-
Hello,
Have you completely remove all instances of the script from the Control Center Strategies tab and any charts and then re applied it?
This could be a case where the changes have not yet been applied because the script was not completely removed and re added, this generally only happens when changes are made in Initialize.
I had no exceptions using this, if you still are after the above process, can you create a test script using the property and do a File -> Utilities -> Export NinjaScript so I can just import and run exactly what you are trying?
I look forward to being of further assistance.JesseNinjaTrader Customer Service
Comment
-
The attached script illustrates what I am experiencing perfectly. Make sure you have your output window open and visible when loading script. If comment the line with TickSize and uncomment the line with the literal (5) all works fine.Attached Files
Comment
-
Hello,
Thank you for providing the example.
It looks like this is strategy specific, the example does work using when inheriting from indicator base but not strategy base. I believe this is due to the way the instance of the strategy is created vs the indicator when it is added.
Instead, you can use the following which works in both a strategy or an indicator:
Code:private int ticks = 0; private string ticks_str = ""; [Description("Enter ticks only. Ticks and dollars will be displayed.")] [GridCategory("Parameters -- Order Handling")] [Gui.Design.DisplayName("011 1st scale out -- ticks")] public string TestTicks { get { return ticks_str; } set { int.TryParse(value, out ticks); ticks_str = ticks.ToString() + " ticks \t= " + (ticks * Instrument.MasterInstrument.TickSize).ToString("C"); } }
Instrument.MasterInstrument.TickSize
I look forward to being of further assistance.JesseNinjaTrader Customer Service
Comment
-
Before I started this thread I tried accessing Instrument.MasterInstrument. It did not work then and it does not work now.
There is a difference in error profiles from trying to access TickSize and trying to access anything from Instrument.MasterInstrument. When trying to access TickSize exceptions are thrown that appear in the output window and I get the deserialization dialog that I mentioned before. When trying to access anything from Instrument.MasterInstrument I get the deserialization dialog only. The calculation appears to be correct though.
The attached script includes your suggestions and illustrates the error. In order to experience the error, you must try to edit the strategy.Attached Files
Comment
-
Hello,
Yes this would not be able to be serialized due to it using Instrument before it will be available.
This can be ignored from serialization so the property would still work and allow the strategy its self to be serialized.
If this is simply a cosmetic item for the property, I would recommend instead just making this an int and display the value on screen using a DrawText with the Price. The int could be both serialized and used in logic that way, or manually as you had previously using a specified tick size.
If you do want to use this and not serialize it, you could add [XmlIgnore] to the tags on the property and it will not be serialized.
I look forward to being of further assistance.JesseNinjaTrader Customer Service
Comment
-
Hello,
Yes that is correct, that 1 specific property would not be remembered but the remainder of the properties and script would be.
Unfortunately because of when this property is accessed I don't believe there is a work around to be able to serialize specifically this.
I look forward to being of further assistance.JesseNinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by rhyminkevin, Yesterday, 04:58 PM
|
5 responses
62 views
0 likes
|
Last Post
by dp8282
Today, 09:36 AM
|
||
Started by realblubb, Today, 09:28 AM
|
0 responses
2 views
0 likes
|
Last Post
by realblubb
Today, 09:28 AM
|
||
Started by AaronKoRn, Yesterday, 09:49 PM
|
1 response
18 views
0 likes
|
Last Post
by Rikazkhan007
Today, 09:24 AM
|
||
Started by ageeholdings, Today, 07:43 AM
|
0 responses
12 views
0 likes
|
Last Post
by ageeholdings
Today, 07:43 AM
|
||
Started by pibrew, Today, 06:37 AM
|
0 responses
4 views
0 likes
|
Last Post
by pibrew
Today, 06:37 AM
|
Comment