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
Indicator Based Stop-loss Strategy
Collapse
X
-
Indicator Based Stop-loss Strategy
I'd like to build a stop loss strategy around 2 indicators: ATR and St.Err. but am not sure where to start. Initially I'd like to place a stop loss at an ATR below my entry and then once price crosses an ATR past each standard error band have the stop loss move to trail the band so that on a good price move it ultimately ends up trailing the outer band. Easier said than done? Thanks.Tags: None
-
Hello jak479,
Thanks for your post and welcome to the NinjaTrader forums!
Are you coding directly in Ninjascript or are you working with the Strategy Builder?
I'm not sure I understand what you are trying to do, can you provide a chart screenshot marked up to provide a visual example?Paul H.NinjaTrader Customer Service
-
Thanks for the welcome. If it's doable in strategy builder that's my first choice. Here is a chart.
Ok so in this chart you can see where I entered a long trade and my stop loss.
Step 1 of the strategy would have the system place the stop loss at 1 ATR below entry.
On the chart, the stop loss is 50 cents lower, corresponding to 1 ATR which is being tracked at the top of the window.
Step 2 would trigger when the price bar closes 1 ATR above the lower blue band using whatever the dynamic ATR number is for that moment. Then the stop order would move up to track the band.
Step 3 would trigger when the price bar closes 1 ATR above the gold band and then proceed to track it.
Step 4 would similarly trigger and move the stop to the top blue band, but in this case I would only want it to track as long as the slope is positive.
Hope that makes sense.
Comment
-
Hello jak479,
Thanks for your reply and clarifications.
You should be able to do this in the Strategy Builder and it will require using bool type variables to control the "steps" and double type variables to hold the current value of the ATR when you place the entry order. You might think of the steps as being "sets" and using different bool variable for each set so that you can logically control the sequencing as you described.
While we cannot create this for you, or provide debugging services, here is a general description of what you would need to do. I'll add some educational references at the end.
For example, in one set you have your entry conditions and there you would save the current value of the ATR into a double type variable and set a bool variable true. In another set you would check that you are in a market position (see link below), check that the bool is true and then place the Exit stop order at the (strategy>Position average price) plus (or minus) the saved ATR value. You would also set another bool true that would get you into the next set (Step 2). Likewise for steps 3 and step 4.
For slope, you can find that Under the Misc folder.
Note 1: The exit order will automatically be canceled if it is not filled on the bar that it is placed. This means that you have to continually submit the exit order and the bools along with the market position check will help you to do that.
Note 2: You didn't mention a profit target and perhaps you do not need one but to clarify when you are using stop exit you would have to use an exit limit order for the profit target. You cannot use the Stops and profit targets window as this would be a conflict.
References:
Free live webinar every other Thursday at 4:00 PM EST, through this link to all webinars: https://ninjatrader.com/PlatformTraining
Previous recording of the Strategy Builder 301 webinar: https://youtu.be/HCyt90GAs9k?list=PL...auWXkWe0Nf&t=2
Help guide for the strategy builder: https://ninjatrader.com/support/help...gy_builder.htm
Paul H.NinjaTrader Customer Service
Comment
-
Hello jak479,
Thanks for your reply.
Yes, however, to see a marker at every instance you would have to provide a unique tag name for the object. If the same tag name is used the previously drawn object is automatically removed to make way for the new object. This is the default behavior in the Strategy Builder( using the same tag names), so you would only see the latest occurrence.
The other requirement is the Y location, (Price location), to display the object. Typically you would want to relate this to a price on the chart such as above or below the bar so that it is visible. By default, this value would be 0 so you may be drawing them but at a price of 0 unless you have put in a price reference
I've attached a short video on how to be able to see all of the markers and well as how to adjust them to place on the chart: https://paul-ninjatrader.tinytake.co...MF8xMTMwNTc0MA
Paul H.NinjaTrader Customer Service
Comment
-
Hello jak479,
Thanks for your reply.
Yes, using draw markers can be very helpful when debugging. It is common to use them to indicator when a "set" is true. By using different colors (or different objects) and placing them at different y location offsets you can see bar by bar what set it true and when.
Glad you found the video helpful!
Paul H.NinjaTrader Customer Service
Comment
-
In this trade, there are about 10 ticks of value that got left on the table. I am having trouble configuring the exit to correct this. What I would like to do is have an exit order placed when the gold St. Err bar starts to reverse its direction. I can't quite figure out how to place it in condition builder. Appreciate your help.
Comment
-
Hello jak479,
Thanks for your reply.
Is the screenshot of a live trade or a trade made on historical data?
What is the Calculate setting of the strategy? (Calculate.OnBarClose, Calculate.OnPriceChange, or Calculate.OnEachTick)
"What I would like to do is have an exit order placed when the gold St. Err bar starts to reverse its direction." In your screenshot I don't see a gold bar. Are you referring to the 4:00 bar or the longer 4:01 bar?
Can you provide a screenshot of your exit condition?
Paul H.NinjaTrader Customer Service
Comment
-
The screenshot reflects historical data. The strategy calculates on each tick. Sorry for the confusion. I meant to state the gold regression line not the 4:01 exit bar. So ideally I would like to make it so an exit order gets submitted when the channel turns south which is at approximately 3:40.
Comment
-
Hello jak479,
Thanks for your reply.
You could compare the current bar value of the lower band to the previous bar value of the lower band and see if it is less indicating perhaps a reversal. This may be too reactive as only two bars are considered.
You could use the Misc>Slope and use the std error bands (pick one of the 3 plots) as the input series. A negative value of slope would indicate falling. The slope allow you o specify how many bars to use for the slope calculation. So you can use Misc>Slope> indicators>std error (pick a plot), less, Misc>numeric value> 0
Paul H.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by andrewtrades, Today, 04:57 PM
|
1 response
5 views
0 likes
|
Last Post Today, 05:02 PM | ||
Started by chbruno, Today, 04:10 PM
|
0 responses
3 views
0 likes
|
Last Post
by chbruno
Today, 04:10 PM
|
||
Started by josh18955, 03-25-2023, 11:16 AM
|
6 responses
436 views
0 likes
|
Last Post
by Delerium
Today, 03:42 PM
|
||
Started by FAQtrader, Today, 03:35 PM
|
0 responses
7 views
0 likes
|
Last Post
by FAQtrader
Today, 03:35 PM
|
||
Started by rocketman7, Today, 09:41 AM
|
5 responses
19 views
0 likes
|
Last Post Today, 03:33 PM |
Comment