Can you help?
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Disable
Collapse
X
-
Hello girda,
You can use Disable() to ensure your strategy is disabled when your trailing stop is hit. Please note that using Disable() will require your unlock your code and enter the code manually. There would also no way to re-enable the strategy from the code.
for example:
Code:[COLOR=#000000][FONT=Tahoma][LEFT][FONT=Courier New][SIZE=2] [/SIZE] [FONT=Courier New][SIZE=2][COLOR=#0000FF]protected[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]override[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]void[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2]OnBarUpdate()[/SIZE][/FONT][/LEFT][/FONT][LEFT][/LEFT][/COLOR][LEFT][/LEFT] [COLOR=#000000][FONT=Tahoma][LEFT][FONT=Courier New][SIZE=2] { [/SIZE][/FONT][/LEFT][/FONT][LEFT][/LEFT][/COLOR][LEFT][/LEFT] [COLOR=#000000][FONT=Tahoma][LEFT][FONT=Courier New][SIZE=2] SetTrailStop(CalculationMode.Ticks,[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800080]12[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);[/SIZE][/FONT][/LEFT][/FONT][LEFT][/LEFT][/COLOR][LEFT][/LEFT] [COLOR=#000000][FONT=Tahoma][LEFT][FONT=Courier New][SIZE=2] [/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2](Position.MarketPosition == MarketPosition.Long)[/SIZE][/FONT][/LEFT][/FONT][LEFT][/LEFT][/COLOR][LEFT][/LEFT] [COLOR=#000000][FONT=Tahoma][LEFT][FONT=Courier New][SIZE=2] {[/SIZE][/FONT][/LEFT][/FONT][LEFT][/LEFT][/COLOR][LEFT][/LEFT] [COLOR=#000000][FONT=Tahoma][LEFT][FONT=Courier New][SIZE=2] trailing =[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]true[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]; [/SIZE][/FONT][/LEFT][/FONT][LEFT][/LEFT][/COLOR][LEFT][/LEFT] [COLOR=#000000][FONT=Tahoma][LEFT][FONT=Courier New][SIZE=2] }[/SIZE][/FONT][/LEFT][/FONT][LEFT][/LEFT][/COLOR][LEFT][/LEFT] [COLOR=#000000][FONT=Tahoma][LEFT][FONT=Courier New][SIZE=2] [/SIZE][/FONT][/LEFT][/FONT][LEFT][/LEFT][/COLOR][LEFT][/LEFT] [COLOR=#000000][FONT=Tahoma][LEFT][FONT=Courier New][SIZE=2] [/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2](Position.MarketPosition == MarketPosition.Flat && trailing ==[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]true[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])[/SIZE][/FONT][/LEFT][/FONT][LEFT][/LEFT][/COLOR][LEFT][/LEFT] [COLOR=#000000][FONT=Tahoma][LEFT][FONT=Courier New][SIZE=2] {[/SIZE][/FONT][/LEFT][/FONT][LEFT][/LEFT][/COLOR][LEFT][/LEFT] [COLOR=#000000][FONT=Tahoma][LEFT][FONT=Courier New][SIZE=2] Disable();[/SIZE][/FONT][/LEFT][/FONT][LEFT][/LEFT][/COLOR][LEFT][/LEFT] [COLOR=#000000][FONT=Tahoma][LEFT][FONT=Courier New][SIZE=2] }[/SIZE][/FONT][/LEFT][/FONT][LEFT][/LEFT][/COLOR][LEFT][/LEFT] [COLOR=#000000][FONT=Tahoma][LEFT][FONT=Courier New][SIZE=2] }[/SIZE][/FONT][/LEFT][/FONT][LEFT][/LEFT][/COLOR][LEFT][/LEFT]
Shawn B.NinjaTrader Customer Service
-
Hello girda,
"Trailing" is a bool variable. However, you could also could use OnExecution() to disable the strategy when there is a fill of an order.
Here is the OnExecution() Help Guide to assist you further. I have included an example of this below.
Code:[LEFT][FONT=Courier New][SIZE=2][COLOR=#0000FF]protected[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]override[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]void[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2]Initialize()[/SIZE][/FONT] [FONT=Courier New][SIZE=2] { [/SIZE][/FONT] [FONT=Courier New][SIZE=2] SetTrailStop([/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800000]"Trail stop"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],CalculationMode.Price, Position.AvgPrice,[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]false[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2]);[/SIZE][/FONT] [FONT=Courier New][SIZE=2] }[/SIZE][/FONT] [FONT=Courier New][SIZE=2] [/SIZE][/FONT] [FONT=Courier New][SIZE=2] [/SIZE][/FONT] [FONT=Courier New][SIZE=2] [/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]protected[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]override[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]void[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2]OnBarUpdate()[/SIZE][/FONT] [FONT=Courier New][SIZE=2] { [/SIZE][/FONT] [FONT=Courier New][SIZE=2] [/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#008000]// Enter the conditions you would like to use here.[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2] [/SIZE][/FONT] [FONT=Courier New][SIZE=2] }[/SIZE][/FONT] [FONT=Courier New][SIZE=2] [/SIZE][/FONT] [FONT=Courier New][SIZE=2] [/SIZE][/FONT] [FONT=Courier New][SIZE=2] [/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]protected[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]override[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]void[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2]OnExecution(IExecution e)[/SIZE][/FONT] [FONT=Courier New][SIZE=2] {[/SIZE][/FONT] [FONT=Courier New][SIZE=2] [/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2](e.Name ==[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800000]"Trail stop"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])[/SIZE][/FONT] [FONT=Courier New][SIZE=2] {[/SIZE][/FONT] [FONT=Courier New][SIZE=2] Disable();[/SIZE][/FONT] [FONT=Courier New][SIZE=2] }}[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000FF][/COLOR][/SIZE][/FONT]
Shawn B.NinjaTrader Customer Service
Comment
-
Hello,
If by hit you are meaning the stop order is filled then creating events in OnExecution() would do this for you. OnExecution() is called on an incoming execution. An execution is another name for a fill of an order. What ShawnB has provided in his example does this.
If this is not what you are looking for please clarify further on what you are wanting it to do and what you mean by "the stop is hit."Cody B.NinjaTrader Customer Service
Comment
-
Hello,
Just to ensure we are on the same page here when you are saying the strategy is disabling on the stops entry are you meaning the stop order is submitted and waiting to fill?
If so please attach your strategy so I may fully look at the logic of the strategy, if you are not comfortable posting this on the forum you can email this to us at platformsupport[AT]ninjatrader[DOT]com. You can attach your Strategy to your response by going to File > Utilities > Export NinjaScript > Export selected source files > select your Strategy> select the right arrow > Export. The file will be located under (My) Documents\NinjaTrader 7\bin\Custom\ExportNinjaScript.Cody B.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by johntraderuser2, Today, 02:34 AM
|
0 responses
6 views
0 likes
|
Last Post Today, 02:34 AM | ||
Started by IanS00, 03-27-2024, 11:24 AM
|
2 responses
12 views
0 likes
|
Last Post Today, 02:00 AM | ||
Started by Mariawilcoxi, Today, 01:32 AM
|
0 responses
5 views
0 likes
|
Last Post
by Mariawilcoxi
Today, 01:32 AM
|
||
Started by gleichnerany, Today, 01:17 AM
|
0 responses
5 views
0 likes
|
Last Post
by gleichnerany
Today, 01:17 AM
|
||
Started by WHICKED, 03-27-2024, 12:33 PM
|
4 responses
47 views
0 likes
|
Last Post Today, 12:28 AM |
Comment