Announcement
Collapse
No announcement yet.
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.
- 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.
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.
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
-
Hello Chuck,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.
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.
Comment
-
Hi Jim, Why can't we apply the BE stop after applying static stop & target under "Stops and Targets" screen in strategic builder?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
-
When set 1 or set 2 executes, do we NOT have hold of the stop & PT set at that time?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
-
Also, to let you know - i only take one position at a time, meaning either 1L or 1S and exit that at TP or SL or with a closing order. Then take next Long or short.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
-
In the Strategy Builder, you may not modify the prices of order submitted via the Stops and Targets screen. To phrase that differently and confirm one of your questions, no you do not "have hold" of the stop loss and profit target in your Conditions and Actions sets. Once those orders are submitted from Stops and Targets, they may not be modified from the Conditions and Actions screen. You must use Exit orders in the Conditions and Actions if you would like to create a breakeven scenario in the Strategy Builder. Exit actions may not be combined with Stops and Targets due to the internal order handling rules listed here - for example, if there is an order from SetStopLoss() or SetProfitTarget() and Exit() orders in the Actions, one of those orders will be ignored: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
You can modify stops and targets from the Set() methods if you configure them dynamically in OnBarUpdate() within an unlocked script in the NinjaScript Editor. This is not an option in the Strategy Builder because it uses static stops and targets that are set in State.Configure. For an example of an unlocked script that can modify to breakeven:Code:https://ninjatrader.com/support/helpGuides/nt8/index.html?managed_approach.htm#InternalOrderHandlingRulesThatReduceUnwantedPositions
Please let us know if we may be of further assistance.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Yesterday, 05:17 AM
|
0 responses
55 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
132 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
73 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
45 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