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
how use trailing stop at strategy builder
Collapse
X
-
Hello Dist2020,
Thank you for your post.
A basic trail stop may be added in the Strategy Builder on the Stops and Targets screen. It should be noted that this is a very basic trailing stop and will trail by the same number of ticks each time - you cannot reduce the width of the trail stop after it's created.
The Set methods in the Stops and Targets section of the Strategy Builder only allow for simple stops and targets that cannot be changed dynamically. Programming by hand will offer more flexibility, but you can also create your own logic in Conditions and Actions that controls how you would like to exit.
We can not offer services to design strategy logic in the support department, but you may conceptualize the following as an example of using Exit orders to mimic Trail stop functionality:- If the strategy is flat, set a bool to controlling your auto trail behaviors to false. Then Enter.
- If the strategy is not flat and some condition happens that you would like to trigger your auto trail, set the bool to true.
- If the strategy is not flat and the bool is false, place your initial stop loss as an Exit Order.
- If the strategy is not flat and the bool is true, modify the Exit Order in association to the current market price.
Strategy Builder 301 - https://www.youtube.com/watch?v=HCyt90GAs9k
Please let us know if we may be of further assistance to you.Kate W.NinjaTrader Customer Service
-
Hello Dist2020,
Thank you for your replies.
I am unable to view your video as the format it is in, Flash, is no longer supported.
In the case that you want your stop movements to be triggered after the price increases by 8 ticks you will need to use exit orders to simulate stop movements in the builder. I've attached a simple example strategy that allows you to set the frequency with with your "trail stop" updates that should give you a good jumping off point to add your own logic.
Here is a basic guideline of how to import NinjaScript add-ons in NinjaTrader 8:
Note — To import NinjaScripts you will need the original .zip file.
To Import:- Download the NinjaScripts to your desktop, keep them in the compressed .zip file.
- From the Control Center window select the menu Tools > Import > NinjaScript Add-on...
- Select the downloaded .zip file
- NinjaTrader will then confirm if the import has been successful.
Once installed, you may add the Strategy to a chart by:- Right click your chart > Strategies... > Select the Strategy from the 'Available' list on the left > Add > OK
Please let me know if I can be of further assistance.
Attached FilesLast edited by NinjaTrader_Kate; 08-06-2020, 09:36 AM. Reason: Updated TrailBuilderExample as it previously used ints instead of doubles which caused issues on certain instruments.Kate W.NinjaTrader Customer Service
- Likes 1
Comment
-
Hi Kate, I have looked at the TrailBuilderExample, I believe I understand it, but I would like to set the "TrailStopDistance" to a multiplier of ATR rather than a fixed number. Can I get a walk through on how to do this either in the builder or a snippet of code for me to study.
Thanks
Comment
-
Hello clearlystocks,
Thank you for your reply.
Here's a different example for the strategy builder that shows how to set up a regular stop that uses the ATR times a multiplier and then rounds to the nearest integer for the stop distance - this could be modified and combined with the previous example to create a trail stop that uses the ATR.
Please let us know if we may be of further assistance to you.Kate W.NinjaTrader Customer Service
Comment
-
Hello,
your example trailing is very usefull for me, thats nice. But I have a problem if I use LONG & SHORTS in my strategy. Long Orders and TrailStopps works fine. In a Short Order the Script set the STP under the Price, so its an Error...
I dont know how to change the script... I see the forest for the trees....
Thank you,
Daniel
Comment
-
Originally posted by NinjaTrader_Kate View PostHello DannyB85,
Thank you for your reply.
That example has some bugs, so I've actually removed it.
I'm currently working on a new version and should have that available tomorrow.
Thanks in advance; I look forward to assisting you further.
Comment
-
Hello,
Thank you for your replies.
To submit orders using dynamic prices in the Strategy Builder it would be necessary to use Exit methods in the 'Do the following' > Order Management section.
Below is a link to an example created with the Strategy Builder.
The only math available in the Strategy Builder is with offsets.
While you could select set in the offset for a price (such as an exit price or when setting a double variable) and set this to the ATR, you would not be able to multiply this by your chosen value and this could not be added to the entry price.
Any kind of more complex math would require unlocking the script and coding by hand. This is possible to do in an unlocked script.
For example:
int myMultiplierValue = 2;
double myExitPrice = Position.AveragePrice + Instrument.MasterInstrument.RoundToTickSize( 2 * ATR(14)[0] );
Below is a link to examples of unlocked scripts that use Set methods as well as Exit methods.
I've also attached my unlocked revised version. What I'd recommend is setting up most of the logic in the builder, then unlocking it to make the small changes necessary for this to properly function.
Please let us know if we may be of further assistance to you.Attached FilesKate W.NinjaTrader Customer Service
Comment
-
Hello Kate,
thank you for your Updated Scripted. But i mean the TrailBuilderExample from your post Above. Can you help me with an V2.0 too?
That would be Nice. The Shorts doenst work, I dont know why.
After EnterShort and the filled Order, the Stop Order will be placed "under" the MarketPrice (ends with Error) and not above. Thank you.
Greetings,
Daniel
Comment
-
Hello DannyB85,
Thank you for your reply.
That example is meant to be a jumping off point to add your own code. We would expect that you would add logic to it if you need it to go short as well as long.
That particular example would need separate variables for the trigger and stop prices for short orders and for those you'd need to set them up similarly to how the current trigger and stop price works. Basically, for a short you would need to reverse the logic used to update the stop and trigger prices. I might also rename the CurrentTriggerPrice and CurrentStopPrice to CurrentLongTrigger and CurrentLongStop and then create a CurrentShortTrigger and CurrentShortStop. You would then want to make sure that those are getting updated by subtracting the TrailFrequency * TickSize or TrailStopDistance * TickSize from the current price rather than adding as with the long entry stops. You'd also need to create a separate ExitShortStopMarket to use for the trail.
Basically, you would need to add 4 more sets that do the identical things that the long ones do, but in reverse.
If you are unsure if you've got it set up correctly, please post screenshots of the builder screens in question.
Please let us know if we may be of further assistance to you.Kate W.NinjaTrader Customer Service
Comment
-
Hello Kate,
I have studied the TrailBuilderExample that you posted in this thread.. I have a question about how go about to adding code to include "Short Entres" to this strategy.. The coding part is a bit fuzzy for me as of yet.. What would I need to do..?
Thanks Michael
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by LincolnOrtiz, Today, 03:10 AM
|
0 responses
1 view
0 likes
|
Last Post
by LincolnOrtiz
Today, 03:10 AM
|
||
Started by Dr Kerry, Today, 02:03 AM
|
0 responses
3 views
0 likes
|
Last Post
by Dr Kerry
Today, 02:03 AM
|
||
Started by AndriXF7, 12-06-2023, 10:09 AM
|
5 responses
161 views
1 like
|
Last Post
by Lunorri
Today, 01:56 AM
|
||
Started by rosa2013, Today, 01:47 AM
|
0 responses
1 view
0 likes
|
Last Post
by rosa2013
Today, 01:47 AM
|
||
Started by owenany, Today, 01:25 AM
|
0 responses
1 view
0 likes
|
Last Post
by owenany
Today, 01:25 AM
|
Comment