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
Change a SetStopLoss() Order
Collapse
X
-
Hello sjmuk1,
The Set methods are submitted based on the entry fill but you can change it later by calling SetStopLoss again with new values.
The two ways to use SetStopLoss orders would be statically by calling SetStopLoss in State.SetDefaults, that gives an always used stop. The other way would be to initialize the stop then submit the entry so that the stop is attached to the entry, that looks like this:
SetStopLoss(yourvalues);
EnterLong();
later you can call SetStopLoss again from other conditions in OnBarUpdate to update it.JesseNinjaTrader Customer Service
-
Hello sjmuk1,
Yes its the same exact concept you would just have two separate entry orders and two separate SetStopLoss syntax.
The Signal name from the entry order is used to tie a stop to that entry so you would have two entries with unique signal names and then each of your targets can reference a specific entry to close out part of a position.JesseNinjaTrader Customer Service
Comment
-
OK Thanks, How could you suggest i approach checking my open positions for moving them to breakeven at some point if I am using SetStopLoss(). I'll have filled entry order objects to check and some will be closed positions with cancelled or filled stops and some will be open positions with active working stops. I want to only check breakeven on the ones that are currently open positions. What do you suggest?
Comment
-
Hello sjmuk1,
There is a sample in the following link that shows how you can do a breakeven. The sample is not using SetStopLoss but is instead using ExitLongStopMarket, if you wanted to use SetStopLoss instead you could replace the ExitLongStopMarket order syntax with SetStopLoss. This sample otherwise lines up with what you described, it uses Order objects to know the state of the orders and also uses the order events to drive its logic.
https://ninjatrader.com/support/help...and_onexec.htm
The important parts of this sample would be its use of OnExecutionUpdate and OnOrderUpdate to manage its Order variables. Also OnBarUpdate where the entry is submitted and the break even for the target is managed. The Position and Order information are used from OnBarUpdate to delegate the breakeven and entry.
This sample only uses 1 order for simplicity, I would suggest that you initially do the same to make sure you have a single order being tracked correctly. That also lets you change to using SetStopLoss if you wanted. Once you do that you can expand it to support multiple entries or scaling if you wanted to.
JesseNinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by ClauTrade, Today, 12:39 PM
|
0 responses
3 views
0 likes
|
Last Post
![]()
by ClauTrade
Today, 12:39 PM
|
||
Started by ClauTrade, Today, 12:15 PM
|
0 responses
5 views
0 likes
|
Last Post
![]()
by ClauTrade
Today, 12:15 PM
|
||
Started by Snowdogg, Today, 11:39 AM
|
0 responses
3 views
0 likes
|
Last Post
![]()
by Snowdogg
Today, 11:39 AM
|
||
Started by SampaioCabezas, Yesterday, 01:58 PM
|
2 responses
21 views
0 likes
|
Last Post
![]() |
||
Started by ny10013, Today, 06:45 AM
|
2 responses
18 views
0 likes
|
Last Post
![]()
by ny10013
Today, 11:05 AM
|
Comment