Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Issue with SL not moving to BE
Collapse
X
-
I didn't really add too much so I think it would be less confusing for you to just add the parts I did, which was
private Order targetOrder = null; next to your stopOrder declaration.
for your Long and Short Entries I added && Position.MarketPosition == MarketPosition.Flat, because it seemed like it kept checking that more than I thought it would. Might be unnecessary.
My OnExecutionUpdate portion is as follows:
protected override void OnExecutionUpdate(Execution execution, string executionID, double price, int quantity, MarketPosition marketPosition, string orderID, DateTime time)
{
if (execution.Order != null && execution.Order.Name == "Long")
{
stopOrder = ExitLongStopMarket(0, true, execution.Order.Filled, execution.Price - 50 * TickSize, "buyStop", "Long");
targetOrder = ExitLongLimit(0, true, execution.Order.Filled, execution.Price + 100 * TickSize, "buyTP", "Long");
}
if (execution.Order != null && execution.Order.Name == "Short")
{
stopOrder = ExitShortStopMarket(0, true, execution.Order.Filled, execution.Price + 50 * TickSize, "sellStop", "Short");
targetOrder = ExitShortLimit(0, true, execution.Order.Filled, execution.Price - 100 * TickSize, "sellTP", "Short");
}
}
give that a shot and let me know if that works for you.
Comment
-
Hello rockmanx00,
Variables holding orders should only be assigned from the order parameter provided from OnOrderUpdate().
From the Desktop SDK documentation:
"OnOrderUpdate() will run inside of order methods such as EnterLong() or SubmitOrderUnmanaged(), therefore attempting to assign an order object outside of OnOrderUpdate() may not return as soon as expected. If your strategy is dependent on tracking the order object from the very first update, you should try to match your order objects by the order.Name (signal name) from during the OnOrderUpdate() as the order is first updated."
Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.
The ProfitCasestopTrailExitOrdersExample I provided a link to in post # 3 provides sample code of how this should look. This also demonstrates implementing 1-tick intra-bar granularity so you can intra-bar fills in historical as well.
Is this historical or real-time?
Please add the State property to the print output.
Chelsea B.NinjaTrader Customer Service
Comment
-
-
Thanks for the feedback, you've helped a lot! I got it working mostly now. Now the only issue is, it keeps re-entering trades if it hits the BE stop loss.Originally posted by rockmanx00 View PostI didn't really add too much so I think it would be less confusing for you to just add the parts I did, which was
private Order targetOrder = null; next to your stopOrder declaration.
for your Long and Short Entries I added && Position.MarketPosition == MarketPosition.Flat, because it seemed like it kept checking that more than I thought it would. Might be unnecessary.
My OnExecutionUpdate portion is as follows:
protected override void OnExecutionUpdate(Execution execution, string executionID, double price, int quantity, MarketPosition marketPosition, string orderID, DateTime time)
{
if (execution.Order != null && execution.Order.Name == "Long")
{
stopOrder = ExitLongStopMarket(0, true, execution.Order.Filled, execution.Price - 50 * TickSize, "buyStop", "Long");
targetOrder = ExitLongLimit(0, true, execution.Order.Filled, execution.Price + 100 * TickSize, "buyTP", "Long");
}
if (execution.Order != null && execution.Order.Name == "Short")
{
stopOrder = ExitShortStopMarket(0, true, execution.Order.Filled, execution.Price + 50 * TickSize, "sellStop", "Short");
targetOrder = ExitShortLimit(0, true, execution.Order.Filled, execution.Price - 100 * TickSize, "sellTP", "Short");
}
}
give that a shot and let me know if that works for you.
Comment
-
No problem. I'm a fellow C#/ Ninjascript learner so this was a nice project that I learned a lot from. I think it'll help me understand my strategy that I'm working on as well. Glad you got it mostly working.
- Likes 1
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Yesterday, 05:17 AM
|
0 responses
63 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
139 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
75 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
50 views
0 likes
|
Last Post
|

Comment