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
Adopt Account Position, SetStopLoss, SetProfitTarget
Collapse
X
-
sagetrade, I think the attached strategy will do what you want.
It will assume the current position and immediately place stoploss and profit target orders.
It was designed to carry a futures contract into to next day without triggering overnight margin requirements. After assuming the current position, it will exit the position at a chosen time (end of session), and then re-enter the position at another time (start of the next session).
Thanks to AlanP for the code example to get me started. I hope this will do the same for you.
AssumeExitReenter.zip
-
Dear Alan,
thanks for your work. I used parts from your code to send a stopp once the strategy is started. The only problem that I have left is the timelag that occurs as the stopp is placed from within the onbarupdate method and I have it set to calculate onbarclose the first bar needs to finish before the SL is sent. I would like to keep my settings at onbarclose though.
Is there an easy way to have this code processed once in the beginning of the startup of a strategy?
Leave a comment:
-
Alan, Thank you very much for the code sample. It is just what I needed.
Leave a comment:
-
Hello Camdo,
SetStopLoss and SetProfitTarget are going to apply to entry orders made by the strategy.
I have built a strategy which when you apply it to a data series with an open position, will submit a stop loss and profit target using ExitShortLimit/ExitShortStopMarket for shorts and ExitLongtLimit/ExitLongStopMarket for longs. If either the stop or profit target order is filled, or if the position becomes flat through a manual trade to the account, the SL and PT orders will be canceled.
Please let us know if you have any questions.
Leave a comment:
-
Adopt Account Position, SetStopLoss, SetProfitTarget
I am writing a strategy that needs to assume an existing account position upon startup and then place a stop loss and profit target order around the strategy position.
The code essentials are:
Code:protected override void OnStateChange() { if (State == State.SetDefaults) { IsAdoptAccountPositionAware = true; StartBehavior = StartBehavior.AdoptAccountPosition; } else if (State == State.Configure) { SetProfitTarget(CalculationMode.Price, ProfitTargetPrice); SetStopLoss(CalculationMode.Ticks, StopLossTicks); } } protected override void OnBarUpdate() { //do something }
The instructions for SetStopLoss() and SetProfitTarget() say:
Profit target orders are submitted in real-time on incoming executions from entry orders
Is there a way for a strategy to adopt an account position and then apply a stop loss and profit target?Tags: None
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by mattbsea, Today, 05:44 PM
|
0 responses
4 views
0 likes
|
Last Post
by mattbsea
Today, 05:44 PM
|
||
Started by RideMe, 04-07-2024, 04:54 PM
|
6 responses
31 views
0 likes
|
Last Post
by RideMe
Today, 05:31 PM
|
||
Started by tkaboris, Today, 05:13 PM
|
0 responses
2 views
0 likes
|
Last Post
by tkaboris
Today, 05:13 PM
|
||
Started by GussJ, 03-04-2020, 03:11 PM
|
16 responses
3,282 views
0 likes
|
Last Post
by Leafcutter
Today, 04:14 PM
|
||
Started by WHICKED, Today, 12:45 PM
|
2 responses
20 views
0 likes
|
Last Post
by WHICKED
Today, 03:36 PM
|
Leave a comment: