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
Stop loss that is below lowest and profit target that is 1.5x the stop
Collapse
X
-
Stop loss that is below lowest and profit target that is 1.5x the stop
I am trying to make a system that will create a stop loss that is say the lowest value within 10 bars from the entry and then it will calculate the difference between the entry price and stop loss and multiply that by 1.5 and place the profit target at that levelTags: None
-
Hello jmass13,
Thanks for your post.
You can use the MIN indicator with the Low PriceSeries as input to get the Lowest Low from 10 bars ago. You can save this value to a private variable for later use in the strategy.
MIN - https://ninjatrader.com/support/help...inimum_min.htm
Working with PriceSeries - https://ninjatrader.com/support/help...ice_series.htm
You can then check OnOrderUpdate for when your entry order's OrderState reaches OrderState.Filled so you can check the AverageFillPrice property of the order.
Then in OnExecutionUpdate, you can submit the stop loss with ExitLongStopMarket using the Lowest Low saved in your private variable. You can also use this variable to calculate the difference from the AverageFillPrice of your entry order, multiply it by 1.5, then use that result to submit your profit target with ExitLongLimit.
OnOrderUpdate - https://ninjatrader.com/support/help...rderupdate.htm
Order.AverageFillPrice is a property of Order objects. Order object documentation can be found below.
Order objects - https://ninjatrader.com/support/help.../nt8/order.htm
An example that uses Order objects, OnOrderUpdate, and OnExecutionUpdate can be found below.
SampleOnOrderUpdate - https://ninjatrader.com/support/help...and_onexec.htm
Let us know if you have any additional questions.JimNinjaTrader Customer Service
-
Hello jmass13,
You could check:
if (order.Name == "MyEntrySignalName" && order.OrderState == OrderState.Filled) to confirm the order is filled. Different OrderStates can be found in the OnOrderUpdate documentation.
If the above approach is too complicated, you could consider using the current market price to distance the profit target instead of the average fill price of the entry order and this would work very similarly for market orders. In that case you could simply use OnBarUpdate without using OnOrderUpdate/OnExecutionUpdate, and do the following:
1. Calculate the prices for the stop and target before submitting your entry order
2. Call SetStopLoss and SetProfitTarget when Position.MarketPosition == MarketPosition.Flat before you submit your entry order. (Set methods prep NinjaTrader to submit target/stop upon the execution of an entry order and should be called before that entry order is submitted.)
You can also consider using Position.AveragePrice in OnBarUpdate when you are Long to distance the profit target, but this would mean we will have to wait for the next bar to be processed to deploy the profit target.Last edited by NinjaTrader_Jim; 08-25-2021, 07:20 AM.JimNinjaTrader Customer Service
Comment
-
I have been trying to come up with alternative methods for creating stops and targets other than using moving averages. Could some one tell or show me how I could calculate a prior bars entire length (wicks included) as the measurement of distance to attach to the SetStopLoss method to create the stop distance below a long entry. For example If I were to enter a long position and one bar ago there was a real long bar then the stop for the long entry should be pretty far below the entry and vise verse if the prior bar was very short. On a time based chart the stop distance would be constantly changing and on a range chart it should always be the same distance below a long entry because range bars will all be the same lengths.
I appreciate any help on this Thanks!
Futures Phantom
Comment
-
Hello FuturesPhantom,
If you want to measure the distance in ticks from the previous bars High/Low, it would be High[1] - Low[1]. This would be in points so to convert it to ticks, you can divide it by TickSize.
(High[1] - Low[1]) / TickSize
You can additional ticks to this result to have a greater sized stop if you wish.JimNinjaTrader Customer Service
- Likes 1
Comment
-
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by warreng86, 11-10-2020, 02:04 PM
|
7 responses
1,360 views
0 likes
|
Last Post Today, 09:41 PM | ||
Started by Perr0Grande, Today, 08:16 PM
|
0 responses
5 views
0 likes
|
Last Post
by Perr0Grande
Today, 08:16 PM
|
||
Started by elderan, Today, 08:03 PM
|
0 responses
9 views
0 likes
|
Last Post
by elderan
Today, 08:03 PM
|
||
Started by algospoke, Today, 06:40 PM
|
0 responses
10 views
0 likes
|
Last Post
by algospoke
Today, 06:40 PM
|
||
Started by maybeimnotrader, Today, 05:46 PM
|
0 responses
14 views
0 likes
|
Last Post Today, 05:46 PM |
Comment