Announcement
Collapse
No announcement yet.
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')
-
-
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.
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 NullPointStrategies, Yesterday, 05:17 AM
|
0 responses
55 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
132 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
73 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
45 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
49 views
0 likes
|
Last Post
|

Comment