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
Autobreak even for strategy builder
Collapse
X
-
Welcome to the forums henryd333!
This is possible to do with the Strategy Builder, however it must be done with your own logic using Exit methods in the Conditions and Actions page of the Strategy Builder. The Stops and Targets section of the Strategy Builder is intended for static stops and targets.
I have attached a couple examples that can demonstrate making breakeven logic.
Please note that Conditions and Actions is processed based on the Calculate Mode of the strategy, so the price may move greater than the distance needed to trigger the update if you are using Calculate.OnBarClose. You may use Calculate.OnPriceChange for intra bar order logic, but keep in mind that historical processing/backtesting will be forced to use Calculate.OnBarClose behaviors as there is no intrabar movement with historical data.
We look forward to assisting.JimNinjaTrader Customer Service
- Likes 1
-
Hello henryd333,
I do not have an example for this specifically, and it also will require unlocking the code.
You would then have to use IsFirstTickOfBar to identify when a bar has closed so you can differentiate logic that should occur on bar closes versus on price changes. When using OnEachTick/OnPriceChange we are working with the developing bar instead of the bar that has just closed, so on the first tick of a new bar we would use BarsAgo 1 references to reference the bar that had just closed.
IsFirstTickOfBar - https://ninjatrader.com/support/help...ttickofbar.htm
Example for creating OnBarClose like logic using OnEachTick/OnPriceChange - https://ninjatrader.com/support/help...either_cal.htm
If you are not familiar working with unlocked NinjaScript strategies, I suggest viewing the NinjaScript Editor 401 tutorial.
NinjaScript Editor 401 (publicly available recording) - https://www.youtube.com/watch?v=H7aDpWoWUQs
We look forward to assisting.JimNinjaTrader Customer Service
Comment
-
Thank you!
I could make the autobreakeven thanks to your example, but i need the exact price that the order is placed, I used close(0) to calculate the stop, but is way far from the entry point, is there any name that calls the entry price of an actual order?
Comment
-
Hello henryd333,
I use Position.AveragePrice to get the average entry price of the strategy's position in the examples. (Conditions > Strategy > Average position price)
If you would like to retrieve the average entry price of a specific order, this will require unlocking the code and using OnOrderUpdate to track Order objects. You could then get average entry price of the Order object from the Order.AverageFillPrice property. Otherwise you may try saving the stop price or limit price of your orders to variables, but this will not be the same thing as the fill price of the order.
The example below shows how Order object tracking can be done with OnOrderUpdate, as well as how you can submit orders for target/stop from OnExecutionUpdate.
SampleOnOrderUpdate - https://ninjatrader.com/support/help...nt8/?order.htm
Please let us know if you have any additional questions.
JimNinjaTrader Customer Service
Comment
-
Hello NT Jim,
I appreciate your post(s) as they're on topic for me. I'm trying to find a method to enable/utiilize an autobreakeven and more importantly an autotrail type of
stop into my strategy.. I use that type of custom stop in my manual trading and find it very useful..
If its not too much too ask, when you provide the link to view the 'strategy builder' conditions and actions - could you clarify which 'Set' these conditions should
be in ?
My strategy(ies) employ 'Set1' for long entry.. 'Set2' for short entry.. 'Set3' for long exit..and 'Set4' for short exit.. Will these conditions work with that type of 'Set'
arrangement.. If not how should I arrange the 'Sets' ?
I appreciate your help finding this information and especially your advice on where to put the conditions when trying to use them..
cheers,
Comment
-
Originally posted by Chuck_63 View PostHello NT Jim,
I appreciate your post(s) as they're on topic for me. I'm trying to find a method to enable/utiilize an autobreakeven and more importantly an autotrail type of
stop into my strategy.. I use that type of custom stop in my manual trading and find it very useful..
If its not too much too ask, when you provide the link to view the 'strategy builder' conditions and actions - could you clarify which 'Set' these conditions should
be in ?
My strategy(ies) employ 'Set1' for long entry.. 'Set2' for short entry.. 'Set3' for long exit..and 'Set4' for short exit.. Will these conditions work with that type of 'Set'
arrangement.. If not how should I arrange the 'Sets' ?
I appreciate your help finding this information and especially your advice on where to put the conditions when trying to use them..
cheers,
Thank you for your note.
This has also been discussed in other threads, including the following which has a post from another colleague that includes examples demonstrating both breakeven and auto trail built in the strategy builder:
To view the sets of conditions and actions, you may import the examples into your platform with the following steps:- Download the example(s) from the forum post
- In the platform, go to Control Center > Tools > Import > NinjaScript AddOn
- Select the downloaded .zip folder to import
- Once the import is successful, go to Control Center > New > Strategy Builder
- Select the newly imported strategy from the dropdown menu
Please let us know if we may be of further assistance.Emily C.NinjaTrader Customer Service
Comment
-
Hi Emily,
Great, yes - I've visited this thread lately and downloaded the examples. I'll take your advice to 'test along the way' because my last tries weren't
successful. If I may ask to be sure - am I correct to assume the examples are coded to work with long positions only as written ? If so, should the commands
work with the values given changed to negative numbers while keeping the same number values for short positions.. ?
Last edited by Chuck_63; 03-30-2023, 12:48 PM.
Comment
-
Hello Chuck,
Thank you for your reply.
Yes, the examples only deal with long positions as they are currently written. The BreakevenBuilderExample uses values for TriggerState, BreakevenTrigger, and InitialStopDistance. You will likely need to add additional conditions that use different TriggerState values for a short position, as well as potentially having a positive value for PositiveBreakevenTrigger and a negative value for NegativeBreakevenTrigger and then a negative InitialLongStopDistance and a positive InitialShortStopDistance to keep the values so that the offsets are on the correct side of the market depending on whether you go long/short. For more information about offsetting an item's value:
The TrailBuilderExample has Set 3 that checks if the position is Long and if the Close price is greater than the CurrentTriggerPrice, which is a positive value. For a set that checks if the condition is short, you are correct that you will likely need to use negative numbers to add a condition that checks if the position is short and if the Close price has gone below the trigger price in the opposite direction compared to how it is checked for the long position.
Please feel free to reach out with any additional questions or concerns.Emily C.NinjaTrader Customer Service
Comment
-
Originally posted by NinjaTrader_Jim View PostWelcome to the forums henryd333!
This is possible to do with the Strategy Builder, however it must be done with your own logic using Exit methods in the Conditions and Actions page of the Strategy Builder. The Stops and Targets section of the Strategy Builder is intended for static stops and targets.
I have attached a couple examples that can demonstrate making breakeven logic.
Please note that Conditions and Actions is processed based on the Calculate Mode of the strategy, so the price may move greater than the distance needed to trigger the update if you are using Calculate.OnBarClose. You may use Calculate.OnPriceChange for intra bar order logic, but keep in mind that historical processing/backtesting will be forced to use Calculate.OnBarClose behaviors as there is no intrabar movement with historical data.
We look forward to assisting.
So my strategy currently has 3 sets under "Conditions & Actions".
Set 1 is to Enter Short if some conditions match.
Set 2 is to Enter Long if some conditions match.
Set 3 is to Exit Short if some conditions match.
Set 4 is to Exit Long if some conditions match.
And since i added "SetProfitTarget" and "SetStopLoss" in "Stops and Targets" screen, i am assuming that after Set 1 or Set 2 executes, the profit target and stop loss are placed on my chart immediately, right?
And if so, why can't i move my stop to BE or "BE + few ticks" if the price moves above/below certain ticks but haven't met my Profit target yet?Last edited by psangram; 01-07-2024, 08:00 AM.
Comment
-
Originally posted by psangram View Post
Hi Jim, Why can't we apply the BE stop after applying static stop & target under "Stops and Targets" screen in strategic builder?
So my strategy currently has 3 sets under "Conditions & Actions".
Set 1 is to Enter Short if some conditions match.
Set 2 is to Enter Long if some conditions match.
Set 3 is to Exit Short if some conditions match.
Set 4 is to Exit Long if some conditions match.
And since i added "SetProfitTarget" and "SetStopLoss" in "Stops and Targets" screen, i am assuming that after Set 1 or Set 2 executes, the profit target and stop loss are placed on my chart immediately, right?
And if so, why can't i move my stop to BE or "BE + few ticks" if the price moves above/below certain ticks but haven't met my Profit target yet?
If we do have hold of those values, then all we can do is add another set-5 for short and set-6 for Long .
And in Set-5, check if current price is greater than or equal to "ShortBreakEvenTrigger" ticks from the average position size, move the Stop to average position size? (Also, my question here is how to move the existing stop to a different price? (can this be done in NT strategy)?
Comment
-
Originally posted by psangram View Post
When set 1 or set 2 executes, do we NOT have hold of the stop & PT set at that time?
If we do have hold of those values, then all we can do is add another set-5 for short and set-6 for Long .
And in Set-5, check if current price is greater than or equal to "ShortBreakEvenTrigger" ticks from the average position size, move the Stop to average position size? (Also, my question here is how to move the existing stop to a different price? (can this be done in NT strategy)?
Comment
-
Originally posted by psangram View Post
Hi Jim, Why can't we apply the BE stop after applying static stop & target under "Stops and Targets" screen in strategic builder?
So my strategy currently has 3 sets under "Conditions & Actions".
Set 1 is to Enter Short if some conditions match.
Set 2 is to Enter Long if some conditions match.
Set 3 is to Exit Short if some conditions match.
Set 4 is to Exit Long if some conditions match.
And since i added "SetProfitTarget" and "SetStopLoss" in "Stops and Targets" screen, i am assuming that after Set 1 or Set 2 executes, the profit target and stop loss are placed on my chart immediately, right?
And if so, why can't i move my stop to BE or "BE + few ticks" if the price moves above/below certain ticks but haven't met my Profit target yet?
https://ninjatrader.com/support/helpGuides/nt8/index.html?managed_approach.htm#InternalOrderHandl ingRulesThatReduceUnwantedPositions
Code:https://ninjatrader.com/support/helpGuides/nt8/index.html?managed_approach.htm#InternalOrderHandlingRulesThatReduceUnwantedPositions
Please let us know if we may be of further assistance.Emily C.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by linkcou, Today, 07:01 AM
|
0 responses
2 views
0 likes
|
Last Post
by linkcou
Today, 07:01 AM
|
||
Started by brunoviveiros, 02-17-2020, 05:31 AM
|
4 responses
63 views
0 likes
|
Last Post Today, 06:25 AM | ||
Started by volIQ, 03-27-2024, 04:28 PM
|
3 responses
21 views
0 likes
|
Last Post
by RJay
Today, 05:41 AM
|
||
Started by Nickgiaco, 02-26-2024, 10:23 AM
|
2 responses
72 views
0 likes
|
Last Post Today, 05:12 AM | ||
Started by Johndc, Today, 04:39 AM
|
0 responses
8 views
0 likes
|
Last Post
by Johndc
Today, 04:39 AM
|
Comment