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
Strategy Property
Collapse
X
-
Strategy Property
Is it possible to create a custom property for a strategy and provide a list of values for the dropdown menu?Tags: None
-
Hello RiversideDude,
Thanks for your post.
Yes, you can create custom properties and a drop down of selectable choices (enum). Here are some references in our tips section:
http://ninjatrader.com/support/forum...ead.php?t=5782
http://ninjatrader.com/support/forum...ead.php?t=4770
For creating an enum to provide the dropdown, you can find two examples in this NT8 indicator in the forums: http://ninjatrader.com/support/forum...d=7&linkid=682
(Note: Critical - Specifically for some NinjaScripts, it will prompt that you are running newer versions of @SMA, @EMA, etc. and ask if you want to replace, press 'No')Paul H.NinjaTrader Customer Service
-
-
I would like to add a property "Strategy Type" to my strategy with the following values:
Breakeven
Manual
Trail
This changes the logic of how my strategy will function. I would rather use strings instead of integers, if possible.
Thanks!!Last edited by RiversideDude; 03-15-2017, 01:52 PM.
Comment
-
Hello RiversideDude,
Thanks for your reply.
You can use an enum for this. Please review the code of the indicator I provided in the previous post.
The first thing you will see is the enum D3SpotIndicatorMethod with a list of names of indicators. In the OnBarUpdate() you will see a switch statement that reacts based on what the user selected (Method). The user selection is provided in the public D3SpotIndicatorMethod Method in the region Properties.
You would be able to implement in the same way and have the drop down selectable.Paul H.NinjaTrader Customer Service
Comment
-
-
Using enum Types to create Dropdown List for Strategies/Indicators
Here's what I did to obtain an dropdown list of string values for properties for a strategy. (Rather than having to download the above indicator zip).
1. Declare an enum type for your property at the class level. I think this needs to be declared public.
2. In the Properties section of your code simply use the enum type instead of an int or string, for example.
It is really that simple.
For the example requested by RiversideDude:
Code:namespace NinjaTrader.NinjaScript.Strategies { public class MyWinningStrategy : Strategy { [B]public enum MyStopType {Breakeven, Manual, Trail};[/B] // more declarations protected override void OnStateChage() {...} protected override void OnBarUpdate() {...} #region Properties [NinjaScriptProperty] [Display(Name="StopLossType", Description="Type to Stop Losss", Order=2, GroupName="Trade Parameters")] public [B]MyStopType [/B]StopLossType { get; set; } #endregion }
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by funk10101, Today, 12:02 AM
|
1 response
11 views
0 likes
|
Last Post Today, 06:38 AM | ||
Started by GLFX005, Today, 03:23 AM
|
1 response
6 views
0 likes
|
Last Post Today, 06:36 AM | ||
Started by nandhumca, Yesterday, 03:41 PM
|
1 response
13 views
0 likes
|
Last Post Today, 06:27 AM | ||
Started by The_Sec, Yesterday, 03:37 PM
|
1 response
11 views
0 likes
|
Last Post Today, 06:17 AM | ||
Started by vecnopus, Today, 06:15 AM
|
0 responses
1 view
0 likes
|
Last Post
by vecnopus
Today, 06:15 AM
|
Comment