Any suggestions?
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Set Stop Loss as an indicator value in Strategy Builder
Collapse
X
-
Set Stop Loss as an indicator value in Strategy Builder
I have user Strategy Builder to define a strategy to enter a buy order, set a profit target and set a stop loss using a set amount of ticks. How can I set the stop loss to the value of a current indicator? For example, I would like to set the stop loss to be the value of the 50-EMA at the time of the entry. It doesn't have to be a trailing stop, just the current value. I defined it as I thought it should be, but when running the strategy, the SL gets set at 1.
Any suggestions?Tags: None
-
Hello Jim H.
Thanks for your post.
In the Strategy Builder, the SetStopLoss and the other Set methods are created as fixed values meaning once created they cannot be changed. The EMA value is not known at the time that the set method is created and in the Strategy Builder, this is a limitation. To accomplish your goal of using a set method ties to an EMA, you would have to unlock the Strategy Builder created strategy and work directly in Ninjascript. In Ninjascript, in the section where you place the order, you would assign the setStopLoss() to the value of the EMA before the line that places the order to ensure the stop loss value is set first.
Alternative #1, in the Strategy Builder, you can use the other exit orders available under Order management folder (in a set). To accomplish your goal you would need to create a double variable (to hold the ema value) and in the set that places the order, assign the current value of the EMA to the double variable. In another set, you would check to see that you are in a (long for example) long position (see: https://ninjatrader.com/support/help...ionComparisons) and then you would add the "exit long position by a stop order".
Note: The exit orders cannot be used with the set methods so you would then also have to add an exit for a profit target (example: "Exit long position by a limit order").
Note: The exit orders are automatically canceled if not filled on the same bar they are submitted and this is why you would have them in another set that is active when there is a (in the example) long position.
Alternative #2, You can use an order like "exit long position" which is a market order that would be filled immediately. In this case, you would create a set where again you would check that you are in a market position and you would check to see if the price has crossed below the EMA and the action then would be to exit long position (market order). Market orders are not subject to the same internal rules that the other exit orders are so in this alternative, you could keep your Set methods (stop and profit). However, a possible conflict could be that the ema price and the SetStopLoss are relatively close, and if both the stop loss and your ema exit occur at the same time, you would close the position and then end up in an unexpected short position.
-
Thanks for your replay NinjaTrader_PaulH . In you reply you said this: "In the Strategy Builder, the SetStopLoss and the other Set methods are created as fixed values meaning once created they cannot be changed. The EMA value is not known at the time that the set method is created and in the Strategy Builder, this is a limitation."
The EMA for the previous bar HAS been calculated - could that number be used?
I'm trying to do this all in Strategy Builder, and as basic as possible...
Comment
-
Hello Jim H.
Thanks for your reply.
No, that number cannot be used. The Strategy Builder Set methods cannot be set with an indicator/bar/index value because the set method is fixed prior to loading the bar data.
The information provided in my post #2 lays out the options (alternatives 1 & 2) for accomplishing your goal in the strategy builder.
Comment
-
Thanks NinjaTrader_PaulH - I will try one of your suggested alternates. Can I set the stoploss to the low of the third previous bar? I have tried this:
but I don't think it likes that either because I get an error in the Log about Error on calling "onstatechange"....
Comment
-
Hello Jim H,
Thanks for your reply.
The set methods are generated before the bars are loaded so you cannot use any specific bar data like Low[3] as it (the bar data) has not been loaded by the strategy when the strategy generates the set methods. The proper use of the set methods in the strategy builder is as you have the profit target, set to a fixed value that gets applied to every entry.
Comment
-
NinjaTrader_PaulH Can the SetStopLoss be set to a variable that has been set/updated previously in a different step? Or even a running variable that had the value updated elsewhere?
Last edited by Jim H.; 02-11-2021, 12:27 PM.
Comment
-
Hello Jim H,
Thanks for your reply.
The Set methods, in the Strategy Builder, are generated before the bars are loaded so no. They can only be set by something like a user input value which would be pulled in also before the bars are loaded.
To use the set methods in a dynamic way, you would have to unlock the script and work directly in Ninjascript.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Today, 05:17 AM
|
0 responses
53 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
130 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
70 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
44 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