Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
SetStopLoss OnExecution
Collapse
X
-
SetStopLoss OnExecution
If I am flat in the market, can I call SetStopLoss from the OnExecution event to reset the value? The documentation only states if you wish to change this dynamically, call it from OnBarUpdate (I am assuming that dynamically means in the market). I have programmed a pretty intense limit ordering system, and I can't figure out why the simulation ordering process quits running when I goof up a order process.Tags: None
-
Believe that would work to to reset it on a fill event, but the Set()'s do not return IOrder to track the fill state changes, so you may want to move to the Exit() methods.
The OnOrderUpdate() and OnExecution() methods are reserved for experienced programmers. Instead of using Set() methods to submit stop-loss and profit target orders, you can submit and update them manually through the use of IOrder and IExecution objects in the OnOrderUpdate() and OnExecution() methods. The OnOrderUpdate()
-
Follow Up
So do you think this would work:
For example, I'm currently in the market short with a stop and profit set.
I decide to reverse my position.
So I issue a ExitShortLimit() in the OnBarUpdate
Then when it is filled (current state = flat), in the OnExecute event can I (in this order):
1) Issue a SetStopLoss
2) Issue a SetProfitTarget
3) Issue a EnterLongLimit
I'm expecting it to reverse my position and reset my stop and profit. If this doesn't work, how should I reverse my position without waiting for another OnBarUpdate?
Comment
-
No, as the SetProfitTarget and SetStopLoss are already set from the Initialize() call. Also since there's no IOrder you can only check if a StopLoss was executed by referring to the signal name, but not to a specific one as with the IOrders.
Additionally Sets and Exits can't be combined as you run into our Internal Order Handling Rules then (http://www.ninjatrader-support.com/H...verview36.html).
So best approach is using the Enter / Exit methods and check with the IOrder objects for individual fillstates to reverse then in OnExecution() -
The OnOrderUpdate() and OnExecution() methods are reserved for experienced programmers. Instead of using Set() methods to submit stop-loss and profit target orders, you can submit and update them manually through the use of IOrder and IExecution objects in the OnOrderUpdate() and OnExecution() methods. The OnOrderUpdate()
Comment
-
I am willing to step back and rewrite my code, but I am still struggling with the plan.
ON EVERYBAR, I want to reevaluate my position, stop and profit using limit orders. I want to dynamically have the ability to change a stop and a profit on every bar. I want to reevaluate if I need to reverse on every bar. What can I do.
Will this work? (Get in market)
1. EnterLongLimit(dPrice, "BuyContract") = In the market
2. ExitLongLimit(dProfitPrice, "ProfitContract", "BuyContract") = Take Profit
3. ExitLongStop(dStopPrice, "LossContract", "BuyContract") = Loss
If I want to reevaluate my profit and stop, can I:
1. CancelOrder("ProfitContract")
2. CancelOrder("LossContract")
3. ExitLongLimit(dProfitNEWPrice, "ProfitContract", "BuyContract") = New Take Profit
4. ExitLongStop(dStopNEWPrice, "LossContract", "BuyContract") = New Loss
If this is NOT going to work, what do I need to do?
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
648 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
369 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
108 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
572 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
574 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|
Comment